Skip to content

Commit c6abeb5

Browse files
authored
Merge pull request #4257 from nhsuk/allow-signing-in-without-a-workgroup
Allow signing in without a team workgroup
2 parents e32c32c + 29aff2d commit c6abeb5

13 files changed

+43
-51
lines changed

app/controllers/concerns/authentication_concern.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ def authenticate_user!
1717
redirect_to start_path
1818
end
1919
elsif cis2_enabled?
20-
if !selected_cis2_role_is_valid?
20+
if !selected_cis2_workgroup_is_valid?
21+
redirect_to users_workgroup_not_found_path
22+
elsif !selected_cis2_role_is_valid?
2123
redirect_to users_role_not_found_path
2224
elsif !selected_cis2_org_is_registered?
2325
redirect_to users_organisation_not_found_path
24-
elsif !selected_cis2_workgroup_is_valid?
25-
redirect_to users_workgroup_not_found_path
2626
end
2727
end
2828
end
@@ -36,7 +36,7 @@ def selected_cis2_org_is_registered?
3636
end
3737

3838
def selected_cis2_workgroup_is_valid?
39-
cis2_info.has_valid_workgroup?
39+
cis2_info.has_workgroup?
4040
end
4141

4242
def selected_cis2_role_is_valid?

app/controllers/users/omniauth_callbacks_controller.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
1515
def cis2
1616
set_cis2_session_info
1717

18-
if !selected_cis2_role_is_valid?
18+
if !selected_cis2_workgroup_is_valid?
19+
redirect_to users_workgroup_not_found_path
20+
elsif !selected_cis2_role_is_valid?
1921
redirect_to users_role_not_found_path
2022
elsif !selected_cis2_org_is_registered?
2123
redirect_to users_organisation_not_found_path
22-
elsif !selected_cis2_workgroup_is_valid?
23-
redirect_to users_workgroup_not_found_path
2424
else
2525
@user = User.find_or_create_from_cis2_oidc(user_cis2_info, valid_teams)
2626

@@ -109,7 +109,8 @@ def set_cis2_session_info
109109
role_name: selected_cis2_nrbac_role["role_name"],
110110
role_code: selected_cis2_nrbac_role["role_code"],
111111
workgroups: selected_cis2_nrbac_role["workgroups"],
112-
has_other_roles: raw_cis2_info["nhsid_nrbac_roles"].length > 1
112+
has_other_roles: raw_cis2_info["nhsid_nrbac_roles"].length > 1,
113+
team_workgroup: nil
113114
)
114115
end
115116

app/forms/select_team_form.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def save
2121
cis2_info.update!(
2222
organisation_code: team.organisation.ods_code,
2323
role_code: CIS2Info::NURSE_ROLE,
24-
workgroups: [team.workgroup]
24+
workgroups: [CIS2Info::WORKGROUP] + [team.workgroup]
2525
)
2626
end
2727

@@ -31,7 +31,7 @@ def save
3131
def teams
3232
@teams ||=
3333
if Settings.cis2.enabled
34-
cis2_info.organisation.teams.where(workgroup: cis2_info.workgroups)
34+
cis2_info.organisation.teams
3535
else
3636
current_user.teams.includes(:organisation)
3737
end

app/models/cis2_info.rb

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

9+
WORKGROUP = "schoolagedimmunisations"
910
SUPERUSER_WORKGROUP = "mavissuperusers"
1011

1112
attribute :organisation_name
@@ -27,14 +28,12 @@ def organisation
2728

2829
def team
2930
@team ||=
30-
if (workgroup = team_workgroup).present? &&
31-
workgroups&.include?(workgroup)
31+
if (workgroup = team_workgroup).present?
3232
Team.find_by(organisation:, workgroup:)
3333
end
3434
end
3535

36-
def has_valid_workgroup? =
37-
organisation&.teams&.exists?(workgroup: workgroups) || false
36+
def has_workgroup? = workgroups&.include?(WORKGROUP) || false
3837

3938
def is_admin? = role_code == ADMIN_ROLE
4039

app/views/users/errors/workgroup_not_found.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<h2 class="nhsuk-heading-m">Contact your registration authority</h2>
44

55
<p>
6-
You need to belong to a workgroup to use Mavis. If you think you should be in the workgroup, ask your registration authority to add you.
6+
You need to belong to <em><%= CIS2Info::WORKGROUP %></em>to use Mavis. If you think you should be in this workgroup, ask your registration authority to add you.
77
</p>
88

99
<% if @cis2_info.has_other_roles %>

spec/factories/users.rb

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

4545
role_code { CIS2Info::NURSE_ROLE }
46-
role_workgroups { [] }
46+
role_workgroups { [CIS2Info::WORKGROUP] }
4747

4848
cis2_info_hash do
4949
{
@@ -83,7 +83,7 @@
8383
end
8484

8585
trait :superuser do
86-
role_workgroups { [CIS2Info::SUPERUSER_WORKGROUP] }
86+
role_workgroups { [CIS2Info::WORKGROUP, CIS2Info::SUPERUSER_WORKGROUP] }
8787
fallback_role { :superuser }
8888
end
8989

spec/features/user_cis2_authentication_from_redirect_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def given_a_test_team_is_setup_in_mavis_and_cis2
2121
family_name: "Test",
2222
org_code: @team.organisation.ods_code,
2323
org_name: @team.name,
24-
workgroups: [@team.workgroup]
24+
workgroups: [CIS2Info::WORKGROUP, @team.workgroup]
2525
)
2626
end
2727

spec/features/user_cis2_authentication_from_start_page_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def given_a_test_team_is_setup_in_mavis_and_cis2
2828
family_name: "Test",
2929
org_code: @team.organisation.ods_code,
3030
org_name: @team.name,
31-
workgroups: [@team.workgroup]
31+
workgroups: [CIS2Info::WORKGROUP, @team.workgroup]
3232
)
3333
end
3434

spec/features/user_cis2_authentication_with_empty_role_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
when_i_go_to_the_sessions_page
77
then_i_am_on_the_start_page
88
when_i_click_the_cis2_login_button
9-
then_i_see_the_wrong_role_error
9+
then_i_see_the_wrong_workgroup_error
1010
end
1111

1212
def given_i_am_setup_in_mavis_and_cis2_but_with_an_empty_role
13-
@team = create(:team, ods_code: "AB12")
13+
@team = create :team, ods_code: "AB12"
1414

1515
mock_cis2_auth(selected_roleid: "")
1616
end
@@ -20,20 +20,20 @@ def when_i_click_the_cis2_login_button
2020
end
2121

2222
def then_i_am_on_the_start_page
23-
expect(page).to have_current_path(start_path)
23+
expect(page).to have_current_path start_path
2424
end
2525

2626
def when_i_go_to_the_sessions_page
2727
visit sessions_path
2828
end
2929

3030
def then_i_see_the_sessions_page
31-
expect(page).to have_current_path(sessions_path)
31+
expect(page).to have_current_path sessions_path
3232
end
3333

34-
def then_i_see_the_wrong_role_error
35-
expect(page).to have_heading(
36-
"You do not have permission to use this service"
37-
)
34+
def then_i_see_the_wrong_workgroup_error
35+
expect(
36+
page
37+
).to have_heading "You’re not in the right workgroup to use this service"
3838
end
3939
end

spec/features/user_cis2_authentication_with_wrong_organisation_spec.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,11 @@ def setup_cis2_auth_mock
3131
end
3232

3333
def given_i_am_setup_in_cis2_but_not_mavis
34-
mock_cis2_auth(
35-
org_code: "A9A5A",
36-
org_name: "SAIS Team",
37-
workgroups: %w[a9a5a]
38-
)
34+
mock_cis2_auth(org_code: "A9A5A", org_name: "SAIS Team")
3935
end
4036

4137
def given_my_team_has_been_setup_in_mavis
42-
@team = create(:team, ods_code: "A9A5A", workgroup: "a9a5a")
38+
@team = create(:team, ods_code: "A9A5A")
4339
end
4440

4541
def when_i_go_to_the_start_page

0 commit comments

Comments
 (0)