From 4dca5f7fd11eee794260f5c08f72dc6f3aba915f Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Mon, 19 Feb 2024 10:01:09 +0100 Subject: [PATCH] Add edit consent method --- .../qualification_requests_controller.rb | 63 ++++++++++++++++++- .../edit_consent_method.html.erb | 17 +++++ .../index_consent_methods.html.erb | 1 + config/routes.rb | 5 ++ 4 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 app/views/assessor_interface/qualification_requests/edit_consent_method.html.erb diff --git a/app/controllers/assessor_interface/qualification_requests_controller.rb b/app/controllers/assessor_interface/qualification_requests_controller.rb index 74ca1a4d17..8385b4bb88 100644 --- a/app/controllers/assessor_interface/qualification_requests_controller.rb +++ b/app/controllers/assessor_interface/qualification_requests_controller.rb @@ -5,7 +5,14 @@ class QualificationRequestsController < BaseController before_action :set_collection_variables, only: %i[index index_consent_methods consent_letter] before_action :set_member_variables, - only: %i[edit update edit_review update_review] + only: %i[ + edit + update + edit_consent_method + update_consent_method + edit_review + update_review + ] define_history_origin :index @@ -68,8 +75,8 @@ def update if @form.save redirect_to [ :assessor_interface, - qualification_request.application_form, - qualification_request.assessment, + application_form, + assessment, :qualification_requests, ] else @@ -77,6 +84,50 @@ def update end end + def edit_consent_method + @form = + ConsentMethodForm.new( + qualification_request:, + consent_method: qualification_request.consent_method, + ) + end + + def update_consent_method + @form = + ConsentMethodForm.new( + consent_method_form_params.merge(qualification_request:), + ) + + if @form.save + if (check_path = history_stack.last_path_if_check) + redirect_to check_path + elsif ( + next_qualification_request = + qualification_requests[ + qualification_requests.index(qualification_request) + 1 + ] + ) + redirect_to [ + :consent_method, + :assessor_interface, + application_form, + assessment, + next_qualification_request, + ] + else + redirect_to [ + :check_consent_method, + :assessor_interface, + application_form, + assessment, + :qualification_requests, + ] + end + else + render :edit_consent_method, status: :unprocessable_entity + end + end + def edit_review @form = RequestableReviewForm.new(requestable:) end @@ -147,6 +198,12 @@ def form_params ) end + def consent_method_form_params + params.require(:assessor_interface_consent_method_form).permit( + :consent_method, + ) + end + def requestable_review_form_params params.require(:assessor_interface_requestable_review_form).permit( :passed, diff --git a/app/views/assessor_interface/qualification_requests/edit_consent_method.html.erb b/app/views/assessor_interface/qualification_requests/edit_consent_method.html.erb new file mode 100644 index 0000000000..c8d4fd5822 --- /dev/null +++ b/app/views/assessor_interface/qualification_requests/edit_consent_method.html.erb @@ -0,0 +1,17 @@ +<% legend = "Consent required for #{qualification_title(@qualification_request.qualification)}" %> + +<% content_for :page_title, title_with_error_prefix(legend, error: @form.errors.any?) %> +<% content_for :back_link_url, back_history_path(default: assessor_interface_application_form_assessment_qualification_requests_path) %> + +<%= form_with model: @form, url: [:consent_method, :assessor_interface, @application_form, @assessment, @qualification_request] do |f| %> + <%= f.govuk_error_summary %> + +

Select consent method

+ + <%= f.govuk_collection_radio_buttons :consent_method, + %i[signed_institution signed_ecctis unsigned], + :itself, + legend: { text: legend }%> + + <%= render "shared/assessor_interface/continue_cancel_button", f: %> +<% end %> diff --git a/app/views/assessor_interface/qualification_requests/index_consent_methods.html.erb b/app/views/assessor_interface/qualification_requests/index_consent_methods.html.erb index fc1ee05122..60811949a3 100644 --- a/app/views/assessor_interface/qualification_requests/index_consent_methods.html.erb +++ b/app/views/assessor_interface/qualification_requests/index_consent_methods.html.erb @@ -26,5 +26,6 @@ <% end %>
+ <%= govuk_button_link_to "Continue", [:consent_method, :assessor_interface, @application_form, @assessment, @qualification_requests.first] %> <%= govuk_link_to "Cancel", [:assessor_interface, @application_form, @assessment, :qualification_requests] %>
diff --git a/config/routes.rb b/config/routes.rb index da6826ac0e..8c3a96169c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -137,6 +137,11 @@ end member do + get "consent-method", + to: "qualification_requests#edit_consent_method" + post "consent-method", + to: "qualification_requests#update_consent_method" + get "review", to: "qualification_requests#edit_review" post "review", to: "qualification_requests#update_review" end