Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/controllers/concerns/authentication_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def selected_cis2_workgroup_is_valid?

def selected_cis2_role_is_valid?
cis2_info.is_admin? || cis2_info.is_nurse? ||
cis2_info.is_healthcare_assistant? || cis2_info.is_superuser?
cis2_info.is_healthcare_assistant? || cis2_info.is_superuser? ||
cis2_info.is_prescriber?
end

def storable_location?
Expand Down
5 changes: 5 additions & 0 deletions app/models/cis2_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class CIS2Info

SUPERUSER_WORKGROUP = "mavissuperusers"

INDEPENDENT_PRESCRIBING_ACTIVITY_CODE = "B0420"
PERSONAL_MEDICATION_ADMINISTRATION_ACTIVITY_CODE = "B0428"

attribute :organisation_name
Expand Down Expand Up @@ -50,6 +51,10 @@ def is_healthcare_assistant?
activity_codes.include?(PERSONAL_MEDICATION_ADMINISTRATION_ACTIVITY_CODE)
end

def is_prescriber?
activity_codes.include?(INDEPENDENT_PRESCRIBING_ACTIVITY_CODE)
end

def is_superuser?
workgroups.include?(SUPERUSER_WORKGROUP)
end
Expand Down
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def role_description
role =
if is_healthcare_assistant?
"Healthcare Assistant"
elsif is_prescriber?
"Prescriber"
elsif is_nurse?
"Nurse"
else
Expand All @@ -151,6 +153,10 @@ def is_healthcare_assistant?
end
end

def is_prescriber?
cis2_enabled? ? cis2_info.is_prescriber? : fallback_role_prescriber?
end

def is_superuser?
cis2_enabled? ? cis2_info.is_superuser? : fallback_role_superuser?
end
Expand Down
8 changes: 8 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@
fallback_role { :healthcare_assistant }
end

trait :prescriber do
sequence(:email) { |n| "prescriber-#{n}@example.com" }
role_code { nil }
activity_codes { [CIS2Info::INDEPENDENT_PRESCRIBING_ACTIVITY_CODE] }
fallback_role { :prescriber }
end

trait :signed_in do
current_sign_in_at { Time.current }
current_sign_in_ip { "127.0.0.1" }
Expand All @@ -108,5 +115,6 @@

factory :admin, parent: :user, traits: %i[admin]
factory :healthcare_assistant, parent: :user, traits: %i[healthcare_assistant]
factory :prescriber, parent: :user, traits: %i[prescriber]
factory :superuser, parent: :user, traits: %i[superuser]
end
44 changes: 44 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,50 @@
end
end

describe "#is_prescriber?" do
subject { user.is_prescriber? }

context "cis2 is enabled", cis2: :enabled do
context "when the user is a nurse" do
let(:user) { build(:nurse) }

it { should be(false) }
end

context "when the user is admin staff" do
let(:user) { build(:admin) }

it { should be(false) }
end

context "when the user is a prescriber" do
let(:user) { build(:prescriber) }

it { should be(true) }
end
end

context "cis2 is disabled", cis2: :disabled do
context "when the user is a nurse" do
let(:user) { build(:nurse) }

it { should be(false) }
end

context "when the user is admin staff" do
let(:user) { build(:admin) }

it { should be(false) }
end

context "when the user is a prescriber" do
let(:user) { build(:prescriber) }

it { should be(true) }
end
end
end

describe "#is_superuser?" do
subject { user.is_superuser? }

Expand Down