Skip to content

Commit 072dd22

Browse files
committed
Prevent deletion of vaccination records from NHS immunisations API
This PR prevents all users from deleting vaccination records where `source = nhs_immunisations_api`. Users are already unable to edit such records, because only records with an associated session can be edited. Jira-Issue: MAV-1772
1 parent 8c37a66 commit 072dd22

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

app/policies/vaccination_record_policy.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def update?
1919
end
2020

2121
def destroy?
22-
user.is_superuser?
22+
# binding.irb
23+
user.is_superuser? && record.source != "nhs_immunisations_api"
2324
end
2425

2526
class Scope < ApplicationPolicy::Scope

spec/policies/vaccination_record_policy_spec.rb

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
describe VaccinationRecordPolicy do
44
subject(:policy) { described_class.new(user, vaccination_record) }
55

6+
let(:programme) { create(:programme) }
7+
let(:team) { create(:team, programmes: [programme]) }
8+
69
describe "update?" do
710
subject(:update?) { policy.update? }
811

9-
let(:programme) { create(:programme) }
10-
let(:team) { create(:team, programmes: [programme]) }
11-
1212
let(:vaccination_record) { create(:vaccination_record, programme:) }
1313

1414
context "with an admin" do
@@ -45,29 +45,58 @@
4545
describe "destroy?" do
4646
subject(:destroy?) { policy.destroy? }
4747

48-
let(:vaccination_record) { create(:vaccination_record) }
48+
context "when vaccination record is from the nhs immunisations api" do
49+
let(:vaccination_record) do
50+
create(:vaccination_record, programme:, source: "nhs_immunisations_api")
51+
end
4952

50-
context "with an admin" do
51-
let(:user) { build(:admin) }
53+
context "with an admin with superuser access" do
54+
let(:user) { build(:admin, :superuser) }
5255

53-
it { should be(false) }
56+
it { should be(false) }
57+
end
5458

55-
context "and superuser access" do
56-
let(:user) { build(:admin, :superuser) }
59+
context "with a nurse with superuser access" do
60+
let(:user) { build(:nurse, :superuser) }
5761

58-
it { should be(true) }
62+
it { should be(false) }
5963
end
6064
end
6165

62-
context "with a nurse" do
63-
let(:user) { build(:nurse) }
66+
context "when vaccination record is managed in mavis" do
67+
let(:session) { create(:session, team:, programmes: [programme]) }
68+
let(:vaccination_record) do
69+
create(
70+
:vaccination_record,
71+
team:,
72+
programme:,
73+
source: "mavis",
74+
session:
75+
)
76+
end
6477

65-
it { should be(false) }
78+
context "with an admin" do
79+
let(:user) { build(:admin) }
6680

67-
context "and superuser access" do
68-
let(:user) { build(:nurse, :superuser) }
81+
it { should be(false) }
6982

70-
it { should be(true) }
83+
context "and superuser access" do
84+
let(:user) { build(:admin, :superuser) }
85+
86+
it { should be(true) }
87+
end
88+
end
89+
90+
context "with a nurse" do
91+
let(:user) { build(:nurse) }
92+
93+
it { should be(false) }
94+
95+
context "and superuser access" do
96+
let(:user) { build(:nurse, :superuser) }
97+
98+
it { should be(true) }
99+
end
71100
end
72101
end
73102
end

0 commit comments

Comments
 (0)