Skip to content

Commit

Permalink
Add record applicant response page
Browse files Browse the repository at this point in the history
This adds the page that allows the admin to view the response as
provided by the applicant and proceed either by accepting the response
or sending it to review.
  • Loading branch information
thomasleese committed Feb 27, 2024
1 parent 922bdd4 commit 8a4875e
Show file tree
Hide file tree
Showing 14 changed files with 293 additions and 16 deletions.
91 changes: 88 additions & 3 deletions app/controllers/assessor_interface/consent_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ class ConsentRequestsController < BaseController

before_action :set_collection_variables,
only: %i[new edit_request update_request]
before_action :set_member_variables, only: %i[edit_upload update_upload]
before_action :set_member_variables,
only: %i[
edit_upload
update_upload
edit_verify
update_verify
edit_verify_failed
update_verify_failed
]

skip_before_action :track_history, only: :new

def new
authorize %i[assessor_interface consent_request]

qualification =
application_form.qualifications.find(params[:qualification_id])

Expand All @@ -36,6 +42,7 @@ def update_request
end

application_form.reload

ApplicationFormStatusUpdater.call(
application_form:,
user: current_staff,
Expand Down Expand Up @@ -79,6 +86,70 @@ def update_upload
end
end

def edit_verify
@form =
RequestableVerifyPassedForm.new(
requestable:,
user: current_staff,
passed: requestable.verify_passed,
)
end

def update_verify
@form =
RequestableVerifyPassedForm.new(
verify_passed_form_params.merge(requestable:, user: current_staff),
)

if @form.save
if @form.passed
redirect_to [
:assessor_interface,
application_form,
assessment,
:qualification_requests,
]
else
redirect_to [
:verify_failed,
:assessor_interface,
application_form,
assessment,
consent_request,
]
end
else
render :edit_verify, status: :unprocessable_entity
end
end

def edit_verify_failed
@form =
RequestableVerifyFailedForm.new(
requestable:,
user: current_staff,
note: requestable.verify_note,
)
end

def update_verify_failed
@form =
RequestableVerifyFailedForm.new(
verify_failed_form_params.merge(requestable:, user: current_staff),
)

if @form.save
redirect_to [
:assessor_interface,
application_form,
assessment,
:qualification_requests,
]
else
render :edit_verify_failed, status: :unprocessable_entity
end
end

private

def application_form
Expand All @@ -103,6 +174,8 @@ def consent_request
@consent_request ||= consent_requests.find(params[:id])
end

alias_method :requestable, :consent_request

def qualification_request
@qualification_request ||=
assessment.qualification_requests.find_by!(
Expand All @@ -129,5 +202,17 @@ def upload_unsigned_consent_document_form_params
:assessor_interface_upload_unsigned_consent_document_form,
).permit(:original_attachment)
end

def verify_passed_form_params
params.require(:assessor_interface_requestable_verify_passed_form).permit(
:passed,
)
end

def verify_failed_form_params
params.require(:assessor_interface_requestable_verify_failed_form).permit(
:note,
)
end
end
end
16 changes: 14 additions & 2 deletions app/policies/assessor_interface/consent_request_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,27 @@ def create?
user.verify_permission
end

def update_request?
user.verify_permission
end

alias_method :edit_request?, :update_request?

def update_upload?
user.verify_permission
end

alias_method :edit_upload?, :update_upload?

def update_request?
def update_verify?
user.verify_permission
end

alias_method :edit_request?, :update_request?
alias_method :edit_verify?, :update_verify?

def update_verify_failed?
user.verify_permission
end

alias_method :edit_verify_failed?, :update_verify_failed?
end
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,21 @@ def signed_consent_method_task_items(qualification_request)
end,
{
name: "Record applicant response",
link: "#",
link:
if consent_request&.requested?
[
:verify,
:assessor_interface,
application_form,
assessment,
consent_request,
]
end,
status:
consent_request&.status(not_requested: "cannot_start") ||
"cannot_start",
},
]
].compact
end

def ecctis_task_items(qualification_request)
Expand Down
41 changes: 41 additions & 0 deletions app/views/assessor_interface/consent_requests/edit_verify.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<% qualification = @consent_request.qualification %>
<% upload = @consent_request.signed_consent_document.uploads.first %>
<% can_update_verify_consent_request = @assessment.verify? && policy([:assessor_interface, @consent_request]).update_verify? %>

<% title = "Record applicant response" %>

<% content_for :page_title, title_with_error_prefix(title, 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: [:verify, :assessor_interface, @application_form, @assessment, @consent_request] do |f| %>
<%= f.govuk_error_summary %>

<h1 class="govuk-heading-xl"><%= title %></h1>

<h2 class="govuk-heading-m"><%= qualification_title(qualification) %></h2>

<% if @consent_request.received? %>
<div class="govuk-inset-text" style="background-color: #f3f2f1">
<h2 class="govuk-heading-m">Returned file</h2>

<p class="govuk-body">
<%= upload.name %>
</p>

<div class="govuk-button-group">
<%= govuk_button_link_to "Download original", [:assessor_interface, :application_form, upload.document, upload] %>

<% unless upload.is_pdf? %>
<%= govuk_button_link_to "Download as PDF", assessor_interface_application_form_document_pdf_path(upload.document, "original"), inverse: true %>
<% end %>
</div>
</div>
<% end %>

<% if can_update_verify_consent_request && (@consent_request.received? || @consent_request.expired?) %>
<%= f.govuk_collection_radio_buttons :passed, %i[true false], :itself,
legend: { text: "Is the consent document for this qualification valid?" } %>

<%= render "shared/assessor_interface/continue_cancel_button", f: %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<% title = "Send for review" %>

<% content_for :page_title, title_with_error_prefix(title, error: @form.errors.any?) %>
<% content_for :back_link_url, back_history_path(default: verify_assessor_interface_application_form_assessment_consent_request_path) %>

<%= form_with model: @form, url: [:verify_failed, :assessor_interface, @application_form, @assessment, @consent_request] do |f| %>
<%= f.govuk_error_summary %>

<h1 class="govuk-heading-xl"><%= title %></h1>

<p class="govuk-body">You have opted to send this qualification’s consent request for review.</p>

<%= f.govuk_text_area :note %>

<%= render "shared/assessor_interface/continue_cancel_button", f: %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<p class="govuk-body">You have opted to send this reference for review.</p>

<%= f.govuk_text_area :note, label: { text: "Internal note: briefly explain to the assessor why you are sending this reference for review." } %>
<%= f.govuk_text_area :note %>

<%= render "shared/assessor_interface/continue_cancel_button", f: %>
<% end %>
2 changes: 2 additions & 0 deletions config/locales/helpers.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ en:
passed_options:
true: Yes, mark as accepted
false: No, mark as rejected
assessor_interface_requestable_verify_failed_form:
note: "Internal note: briefly explain to the assessor why you are sending this for review."
assessor_interface_requestable_verify_passed_form:
passed_options:
true: Yes, mark as completed
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
member do
get "upload", to: "consent_requests#edit_upload"
post "upload", to: "consent_requests#update_upload"
get "verify", to: "consent_requests#edit_verify"
post "verify", to: "consent_requests#update_verify"
get "verify-failed", to: "consent_requests#edit_verify_failed"
post "verify-failed", to: "consent_requests#update_verify_failed"
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module PageObjects
module AssessorInterface
class VerifyConsentRequest < VerifyRequestablePage
set_url "/assessor/applications/{reference}/assessments/{assessment_id}" \
"/consent-requests/{id}/verify"

element :download_original_button,
".govuk-button:not(.govuk-button--inverse)"
element :download_as_pdf_button, ".govuk-button.govuk-button--inverse"
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module PageObjects
module AssessorInterface
class VerifyFailedConsentRequest < VerifyFailedRequestablePage
set_url "/assessor/applications/{reference}/assessments/{assessment_id}" \
"/consent-requests/{id}/verify-failed"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class VerifyRequestablePage < SitePrism::Page
section :false_radio_item,
PageObjects::GovukRadioItem,
".govuk-radios__item:nth-of-type(2)"
element :submit_button, ".govuk-button"
element :submit_button, "button.govuk-button"
end

def submit_yes
Expand Down
10 changes: 10 additions & 0 deletions spec/support/page_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,16 @@ def assessor_verify_age_range_subjects_page
PageObjects::AssessorInterface::VerifyAgeRangeSubjectsPage.new
end

def assessor_verify_consent_request_page
@assessor_verify_consent_request_page ||=
PageObjects::AssessorInterface::VerifyConsentRequest.new
end

def assessor_verify_failed_consent_request_page
@assessor_verify_failed_consent_request_page ||=
PageObjects::AssessorInterface::VerifyFailedConsentRequest.new
end

def assessor_verify_failed_professional_standing_request_page
@assessor_verify_failed_professional_standing_request_page ||=
PageObjects::AssessorInterface::VerifyFailedProfessionalStandingRequest.new
Expand Down
Loading

0 comments on commit 8a4875e

Please sign in to comment.