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 %> + +