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 29, 2024
1 parent 0f7c85e commit 87a0c9f
Show file tree
Hide file tree
Showing 14 changed files with 309 additions and 18 deletions.
94 changes: 89 additions & 5 deletions app/controllers/assessor_interface/consent_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ 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 edit_review update_review]
only: %i[
edit_upload
update_upload
edit_verify
update_verify
edit_verify_failed
update_verify_failed
edit_review
update_review
]

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 @@ -37,6 +44,7 @@ def update_request
end

application_form.reload

ApplicationFormStatusUpdater.call(
application_form:,
user: current_staff,
Expand Down Expand Up @@ -80,6 +88,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

def edit_review
@form = RequestableReviewForm.new(requestable:)
end
Expand Down Expand Up @@ -123,6 +195,8 @@ def consent_request
@consent_request ||= consent_requests.find(params[:id])
end

alias_method :requestable, :consent_request

def set_collection_variables
authorize %i[assessor_interface consent_request]
@consent_requests = consent_requests
Expand All @@ -142,13 +216,23 @@ def upload_unsigned_consent_document_form_params
).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

def review_form_params
params.require(:assessor_interface_requestable_review_form).permit(
:passed,
:note,
)
end

alias_method :requestable, :consent_request
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,17 +5,29 @@ 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?

def update_review?
user.assess_permission
Expand Down
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
56 changes: 56 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,56 @@
<% 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">
<% if upload.is_pdf? %>
<%= govuk_button_link_to "Download", [:assessor_interface, :application_form, upload.document, upload] %>
<% else %>
<%= govuk_button_link_to "Download original", [:assessor_interface, :application_form, upload.document, upload] %>
<%= govuk_button_link_to "Download as PDF", assessor_interface_application_form_document_pdf_path(upload.document, "original"), inverse: true %>
<% end %>
</div>
</div>
<% elsif @consent_request.expired? %>
<%= govuk_warning_text(text: "This consent is overdue.") %>

<h2 class="govuk-heading-m">Please follow these steps</h2>

<ul class="govuk-list govuk-list--number">
<li>Go to Zendesk to email the applicant to remind them.</li>
<li>If no response, escalate to an EO.</li>
</ul>
<% end %>

<% if can_update_verify_consent_request && (@consent_request.received? || @consent_request.expired?) %>
<% if @consent_request.received? %>
<%= f.govuk_collection_radio_buttons :passed, %i[true false], :itself,
legend: { text: "Is the consent document for this qualification valid?" } %>
<% else %>
<%= f.govuk_collection_radio_buttons :passed, [OpenStruct.new(value: false, label: "Yes, send for review")], :value, :label,
legend: { text: "Do you want to send this reference for review?" } %>
<% end %>

<%= 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"
get "review", to: "consent_requests#edit_review"
post "review", to: "consent_requests#update_review"
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 @@ -250,6 +250,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 87a0c9f

Please sign in to comment.