Skip to content

Commit

Permalink
Add edit consent method
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasleese committed Feb 19, 2024
1 parent 5c0572d commit 4dca5f7
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -68,15 +75,59 @@ def update
if @form.save
redirect_to [
:assessor_interface,
qualification_request.application_form,
qualification_request.assessment,
application_form,
assessment,
:qualification_requests,
]
else
render :edit, status: :unprocessable_entity
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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %>

<h1 class="govuk-heading-l">Select consent method</h1>

<%= 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 %>
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
<% end %>

<div class="govuk-button-group">
<%= 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] %>
</div>
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4dca5f7

Please sign in to comment.