Skip to content

Commit e3d9e1c

Browse files
committed
Merge pull request #4370 from nhsuk/edit-session-protocols
Add ability for users to enable/disable delgation
2 parents b1f1a48 + d35cfd5 commit e3d9e1c

18 files changed

+346
-75
lines changed

app/controllers/session_dates_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def update
3434
if any_destroyed?
3535
session_dates_path(@session)
3636
else
37-
edit_session_path(@session)
37+
session_edit_path(@session)
3838
end
3939
)
4040
end

app/controllers/sessions/edit_controller.rb

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,47 @@
33
class Sessions::EditController < ApplicationController
44
before_action :set_session
55

6-
def edit_programmes
6+
before_action :authorize_session_edit,
7+
except: %i[
8+
update_programmes
9+
update_send_consent_requests_at
10+
update_send_invitations_at
11+
update_weeks_before_consent_reminders
12+
update_register_attendance
13+
update_delegation
14+
]
15+
before_action :authorize_session_update,
16+
only: %i[
17+
update_programmes
18+
update_send_consent_requests_at
19+
update_send_invitations_at
20+
update_weeks_before_consent_reminders
21+
update_register_attendance
22+
update_delegation
23+
]
24+
25+
def show
26+
end
27+
28+
def programmes
729
@form =
830
SessionProgrammesForm.new(
931
session: @session,
1032
programme_ids: @session.programme_ids
1133
)
12-
13-
render :programmes
1434
end
1535

1636
def update_programmes
1737
@form = SessionProgrammesForm.new(session: @session, **programmes_params)
1838

1939
if @form.save
20-
redirect_to edit_session_path(@session)
40+
redirect_to session_edit_path(@session)
2141
else
2242
render :programmes, status: :unprocessable_content
2343
end
2444
end
2545

26-
def edit_send_consent_requests_at
27-
render :send_consent_requests_at
46+
def send_consent_requests_at
2847
end
2948

3049
def update_send_consent_requests_at
@@ -35,12 +54,11 @@ def update_send_consent_requests_at
3554
elsif !@session.update(send_consent_requests_at_params)
3655
render :send_consent_requests_at, status: :unprocessable_content
3756
else
38-
redirect_to edit_session_path(@session)
57+
redirect_to session_edit_path(@session)
3958
end
4059
end
4160

42-
def edit_send_invitations_at
43-
render :send_invitations_at
61+
def send_invitations_at
4462
end
4563

4664
def update_send_invitations_at
@@ -51,26 +69,55 @@ def update_send_invitations_at
5169
elsif !@session.update(send_invitations_at_params)
5270
render :send_invitations_at, status: :unprocessable_content
5371
else
54-
redirect_to edit_session_path(@session)
72+
redirect_to session_edit_path(@session)
5573
end
5674
end
5775

58-
def edit_weeks_before_consent_reminders
59-
render :weeks_before_consent_reminders
76+
def weeks_before_consent_reminders
6077
end
6178

6279
def update_weeks_before_consent_reminders
6380
if @session.update(weeks_before_consent_reminders_params)
64-
redirect_to edit_session_path(@session)
81+
redirect_to session_edit_path(@session)
6582
else
6683
render :weeks_before_consent_reminders, status: :unprocessable_content
6784
end
6885
end
6986

87+
def register_attendance
88+
end
89+
90+
def update_register_attendance
91+
if @session.update(register_attendance_params)
92+
redirect_to session_edit_path(@session)
93+
else
94+
render :register_attendance, status: :unprocessable_content
95+
end
96+
end
97+
98+
def delegation
99+
end
100+
101+
def update_delegation
102+
if @session.update(delegation_params)
103+
redirect_to session_edit_path(@session)
104+
else
105+
render :delegation, status: :unprocessable_content
106+
end
107+
end
108+
70109
private
71110

72111
def set_session
73-
@session = policy_scope(Session).find_by!(slug: params[:slug])
112+
@session = policy_scope(Session).find_by!(slug: params[:session_slug])
113+
end
114+
115+
def authorize_session_edit
116+
authorize @session, :edit?
117+
end
118+
119+
def authorize_session_update
120+
authorize @session, :update?
74121
end
75122

76123
def programmes_params
@@ -106,4 +153,12 @@ def send_invitations_at_params
106153
def weeks_before_consent_reminders_params
107154
params.expect(session: :weeks_before_consent_reminders)
108155
end
156+
157+
def register_attendance_params
158+
params.expect(session: :requires_registration)
159+
end
160+
161+
def delegation_params
162+
params.expect(session: %i[psd_enabled national_protocol_enabled])
163+
end
109164
end

app/controllers/sessions_controller.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ def show
5151
end
5252
end
5353

54-
def edit
55-
end
56-
5754
def import
5855
draft_import = DraftImport.new(request_session: session, current_user:)
5956

app/policies/session_policy.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# frozen_string_literal: true
22

33
class SessionPolicy < ApplicationPolicy
4+
def update?
5+
user.is_nurse? || user.is_admin?
6+
end
7+
48
def import? = show?
59

610
def make_in_progress? = edit?

app/views/session_dates/show.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<% content_for :before_main do %>
2-
<%= render AppBacklinkComponent.new(edit_session_path(@session), name: "edit session") %>
2+
<%= render AppBacklinkComponent.new(session_edit_path(@session), name: "edit session") %>
33
<% end %>
44

55
<%= h1 "When will sessions be held?" %>
@@ -42,6 +42,6 @@
4242

4343
<div class="app-button-group">
4444
<%= f.govuk_submit "Continue" %>
45-
<%= govuk_link_to "Back", edit_session_path(@session) %>
45+
<%= govuk_link_to "Back", session_edit_path(@session) %>
4646
</div>
4747
<% end %>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<% content_for :before_main do %>
2+
<%= render AppBacklinkComponent.new(session_edit_path(@session), name: "edit session") %>
3+
<% end %>
4+
5+
<%= form_with model: @session, url: delegation_session_edit_path(@session), method: :put do |f| %>
6+
<% content_for(:before_content) { f.govuk_error_summary } %>
7+
8+
<span class="nhsuk-caption-l"><%= @session.location.name %></span>
9+
<%= h1 "Delegation" %>
10+
11+
<%= f.govuk_radio_buttons_fieldset :psd_enabled,
12+
legend: { text: "Can healthcare assistants administer the flu nasal spray vaccine using a patient specific direction (PSD)?" },
13+
link_errors: true do %>
14+
<%= f.govuk_radio_button :psd_enabled,
15+
"false",
16+
label: { text: "No" },
17+
hint: { text: "Healthcare assistants can only administer a nasal spray when supplied by a nurse" } %>
18+
<%= f.govuk_radio_button :psd_enabled,
19+
"true",
20+
label: { text: "Yes" },
21+
hint: { text: "Healthcare assistants can administer the nasal spray vaccine to children who are covered by a PSD" } %>
22+
<% end %>
23+
24+
<%= f.govuk_radio_buttons_fieldset :national_protocol_enabled,
25+
legend: { text: "Can healthcare assistants administer the injected flu vaccine using the national protocol?" },
26+
link_errors: true do %>
27+
<%= f.govuk_radio_button :national_protocol_enabled,
28+
"false",
29+
label: { text: "No" },
30+
hint: { text: "Only nurses can administer the injected flu vaccine" } %>
31+
<%= f.govuk_radio_button :national_protocol_enabled,
32+
"true",
33+
label: { text: "Yes" },
34+
hint: { text: "Healthcare assistants can administer an injected flu vaccine when supplied by a nurse" } %>
35+
<% end %>
36+
37+
<%= f.govuk_submit "Continue" %>
38+
<% end %>

app/views/sessions/edit/programmes.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<% content_for :before_main do %>
2-
<%= render AppBacklinkComponent.new(edit_session_path(@session), name: "edit session") %>
2+
<%= render AppBacklinkComponent.new(session_edit_path(@session), name: "edit session") %>
33
<% end %>
44

55
<% legend = "Which programmes is this session part of?" %>
66
<% content_for :page_title, legend %>
77

8-
<%= form_with model: @form, url: edit_programmes_session_path(@session), method: :put do |f| %>
8+
<%= form_with model: @form, url: programmes_session_edit_path(@session), method: :put do |f| %>
99
<% content_for(:before_content) { f.govuk_error_summary } %>
1010

1111
<%= f.govuk_collection_check_boxes :programme_ids, policy_scope(Programme), :id, :name,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<% content_for :before_main do %>
2+
<%= render AppBacklinkComponent.new(session_edit_path(@session), name: "edit session") %>
3+
<% end %>
4+
5+
<% legend = "Do you want to register children’s attendance before recording vaccinations?" %>
6+
<% content_for :page_title, legend %>
7+
8+
<%= form_with model: @session, url: register_attendance_session_edit_path(@session), method: :put do |f| %>
9+
<% content_for(:before_content) { f.govuk_error_summary } %>
10+
11+
<%= f.govuk_radio_buttons_fieldset :requires_registration,
12+
legend: { text: legend, size: "l", tag: "h1" },
13+
caption: { text: @session.location.name, size: "l" },
14+
link_errors: true do %>
15+
<%= f.govuk_radio_button :requires_registration, "true", label: { text: "Yes" } %>
16+
<%= f.govuk_radio_button :requires_registration, "false", label: { text: "No" } %>
17+
<% end %>
18+
19+
<%= f.govuk_submit "Continue" %>
20+
<% end %>

app/views/sessions/edit/send_consent_requests_at.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<% content_for :before_main do %>
2-
<%= render AppBacklinkComponent.new(edit_session_path(@session), name: "edit session") %>
2+
<%= render AppBacklinkComponent.new(session_edit_path(@session), name: "edit session") %>
33
<% end %>
44

55
<% legend = "When should parents get a request to give consent?" %>
66
<% content_for :page_title, legend %>
77

8-
<%= form_with model: @session, url: edit_send_consent_requests_at_session_path(@session), method: :put do |f| %>
8+
<%= form_with model: @session, url: send_consent_requests_at_session_edit_path(@session), method: :put do |f| %>
99
<% content_for(:before_content) { f.govuk_error_summary } %>
1010

1111
<%= f.govuk_date_field :send_consent_requests_at,

app/views/sessions/edit/send_invitations_at.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<% content_for :before_main do %>
2-
<%= render AppBacklinkComponent.new(edit_session_path(@session), name: "edit session") %>
2+
<%= render AppBacklinkComponent.new(session_edit_path(@session), name: "edit session") %>
33
<% end %>
44

55
<% legend = "When should parents get an invitation?" %>
66
<% content_for :page_title, legend %>
77

8-
<%= form_with model: @session, url: edit_send_invitations_at_session_path(@session), method: :put do |f| %>
8+
<%= form_with model: @session, url: send_invitations_at_session_edit_path(@session), method: :put do |f| %>
99
<% content_for(:before_content) { f.govuk_error_summary } %>
1010

1111
<%= f.govuk_date_field :send_invitations_at,

0 commit comments

Comments
 (0)