Skip to content

Commit a355a39

Browse files
committed
Make superuser permissions based on activities
This updates how a user is allowed to perform certain superuser tasks by checking their activity codes rather than the `mavissuperusers` workgroup. This is being done to allow for a more granular permissions system where different users have permission to perform different tasks. Jira-Issue: MAV-1681
1 parent 19e7216 commit a355a39

File tree

4 files changed

+16
-19
lines changed

4 files changed

+16
-19
lines changed

app/models/cis2_info.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ class CIS2Info
66
NURSE_ROLE = "S8000:G8000:R8001"
77
MEDICAL_SECRETARY_ROLE = "S8000:G8001:R8006"
88

9-
SUPERUSER_WORKGROUP = "mavissuperusers"
10-
9+
ACCESS_SENSITIVE_FLAGGED_RECORDS_ACTIVITY_CODE = "B1611"
1110
INDEPENDENT_PRESCRIBING_ACTIVITY_CODE = "B0420"
11+
LOCAL_SYSTEM_ADMINISTRATION_ACTIVITY_CODE = "B0062"
1212
PERSONAL_MEDICATION_ADMINISTRATION_ACTIVITY_CODE = "B0428"
1313

1414
attribute :organisation_name
@@ -57,7 +57,8 @@ def is_prescriber?
5757
end
5858

5959
def is_superuser?
60-
workgroups.include?(SUPERUSER_WORKGROUP)
60+
activity_codes.include?(ACCESS_SENSITIVE_FLAGGED_RECORDS_ACTIVITY_CODE) &&
61+
activity_codes.include?(LOCAL_SYSTEM_ADMINISTRATION_ACTIVITY_CODE)
6162
end
6263

6364
private

spec/factories/users.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
team { Team.includes(:organisation).first || create(:team) }
4545

4646
role_code { CIS2Info::NURSE_ROLE }
47-
role_workgroups { [] }
4847
activity_codes { [] }
4948

5049
cis2_info_hash do
@@ -54,7 +53,7 @@
5453
"role_code" => role_code,
5554
"activity_codes" => activity_codes,
5655
"team_workgroup" => team.workgroup,
57-
"workgroups" => role_workgroups + [team.workgroup]
56+
"workgroups" => [team.workgroup]
5857
}
5958
end
6059
end
@@ -89,7 +88,12 @@
8988

9089
trait :superuser do
9190
sequence(:email) { |n| "superuser-#{n}@example.com" }
92-
role_workgroups { [CIS2Info::SUPERUSER_WORKGROUP] }
91+
activity_codes do
92+
[
93+
CIS2Info::ACCESS_SENSITIVE_FLAGGED_RECORDS_ACTIVITY_CODE,
94+
CIS2Info::LOCAL_SYSTEM_ADMINISTRATION_ACTIVITY_CODE
95+
]
96+
end
9397
fallback_role { :superuser }
9498
show_in_suppliers { false }
9599
end

spec/models/user_spec.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,6 @@
254254

255255
it { should be(true) }
256256
end
257-
258-
context "without workgroups" do
259-
let(:user) { build(:medical_secretary, role_workgroups: []) }
260-
261-
it { should be(false) }
262-
end
263257
end
264258

265259
context "when the user is a nurse" do
@@ -272,12 +266,6 @@
272266

273267
it { should be(true) }
274268
end
275-
276-
context "without workgroups" do
277-
let(:user) { build(:nurse, role_workgroups: []) }
278-
279-
it { should be(false) }
280-
end
281269
end
282270
end
283271

spec/support/cis2_auth_helper.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,12 @@ def sign_in(user, organisation: nil, role: :nurse, superuser: false)
135135
prescriber: [CIS2Info::INDEPENDENT_PRESCRIBING_ACTIVITY_CODE]
136136
}.fetch(role)
137137

138+
if superuser
139+
activity_codes << CIS2Info::ACCESS_SENSITIVE_FLAGGED_RECORDS_ACTIVITY_CODE
140+
activity_codes << CIS2Info::LOCAL_SYSTEM_ADMINISTRATION_ACTIVITY_CODE
141+
end
142+
138143
workgroups = user.teams.where(organisation:).pluck(:workgroup)
139-
workgroups << CIS2Info::SUPERUSER_WORKGROUP if superuser
140144

141145
cis2_sign_in(user, ods_code:, role_code:, activity_codes:, workgroups:)
142146
end

0 commit comments

Comments
 (0)