Skip to content

Commit

Permalink
Add send consent document to applicant page
Browse files Browse the repository at this point in the history
This adds a page which allows the assessor to send the uploaded consent
documents to the applicant.
  • Loading branch information
thomasleese committed Feb 22, 2024
1 parent 70530e1 commit 85b633a
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class QualificationRequestsController < BaseController
edit_unsigned_consent_document
update_unsigned_consent_document
generate_unsigned_consent_document
edit_send_signed_consent_documents
update_send_signed_consent_documents
]
before_action :set_member_variables,
only: %i[
Expand Down Expand Up @@ -77,6 +79,24 @@ def generate_unsigned_consent_document
)
end

def edit_send_signed_consent_documents
end

def update_send_signed_consent_documents
ActiveRecord::Base.transaction do
qualification_requests.consent_method_signed.each(&:consent_requested!)
end

TeacherMailer.with(application_form:).consent_requested.deliver_later

redirect_to [
:assessor_interface,
application_form,
assessment,
:qualification_requests,
]
end

def edit
received =
if requestable.received?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ def generate_unsigned_consent_document?
user.assess_permission
end

def update_send_signed_consent_documents?
user.assess_permission
end

alias_method :edit_send_signed_consent_documents?,
:update_send_signed_consent_documents?

def update?
user.assess_permission
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,32 @@ def send_consent_document_in_all_qualifications?
end

def send_consent_document_task_item
consent_requests = qualification_requests.consent_method_signed

all_documents_completed =
consent_requests
.map(&:unsigned_consent_document)
.all? { |document| document.completed? && document.downloadable? }
all_consent_requested = consent_requests.all?(&:consent_requested?)

{
name: "Send consent document to applicant",
link: "#",
name:
"Send consent #{"document".pluralize(consent_requests.count)} to applicant",
link:
if all_documents_completed && !all_consent_requested
[
:send_signed_consent_documents,
:assessor_interface,
application_form,
assessment,
:qualification_requests,
]
end,
status:
if qualification_requests.map(&:unsigned_consent_document).all?(
&:completed?
)
if qualification_requests.all?(&:consent_requested?)
"completed"
else
"not_started"
end
if all_documents_completed && all_consent_requested
"completed"
elsif all_documents_completed
"not_started"
else
"cannot_start"
end,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% consent_requests = @qualification_requests.consent_method_signed %>

<% title = "Send consent #{"document".pluralize(consent_requests.count)} to applicant" %>

<% content_for :page_title, title %>
<% content_for :back_link_url, back_history_path(default: assessor_interface_application_form_assessment_qualification_requests_path) %>

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

<p class="govuk-body">You need to request a signature for the uploaded consent documents for:</p>

<ul class="govuk-list govuk-list--bullet">
<% consent_requests.each do |qualification_request| %>
<li><%= qualification_title(qualification_request.qualification) %></li>
<% end %>
</ul>

<p class="govuk-body">Select ‘Continue’ to automatically send an email and the uploaded consent document to the applicant.</p>

<div class="govuk-button-group">
<%= govuk_button_to "Continue", [:send_signed_consent_documents, :assessor_interface, @application_form, @assessment, :qualification_requests] %>
<%= render "shared/assessor_interface/cancel_link" %>
</div>
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@
to: "qualification_requests#update_unsigned_consent_document"
get "generate-unsigned-consent-document",
to: "qualification_requests#generate_unsigned_consent_document"

get "send-signed-consent-documents",
to: "qualification_requests#edit_send_signed_consent_documents"
post "send-signed-consent-documents",
to:
"qualification_requests#update_send_signed_consent_documents"
end

member do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@
it_behaves_like "a policy method requiring the assess permission"
end

describe "#update_send_signed_consent_documents?" do
subject(:update_send_signed_consent_documents?) do
policy.update_send_signed_consent_documents?
end
it_behaves_like "a policy method requiring the assess permission"
end

describe "#edit_send_signed_consent_documents?" do
subject(:edit_send_signed_consent_documents?) do
policy.edit_send_signed_consent_documents?
end
it_behaves_like "a policy method requiring the assess permission"
end

describe "#show?" do
subject(:show?) { policy.show? }
it_behaves_like "a policy method without permission"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module PageObjects
module AssessorInterface
class SendSignedConsentDocuments < SitePrism::Page
set_url "/assessor/applications/{reference}/assessments/{assessment_id}" \
"/qualification-requests/send-signed-consent-documents"

element :continue_button, ".govuk-button:not(.govuk-button--secondary)"
end
end
end
5 changes: 5 additions & 0 deletions spec/support/page_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ def assessor_review_verifications_page
PageObjects::AssessorInterface::ReviewVerifications.new
end

def assessor_send_signed_consent_documents_page
@assessor_send_signed_consent_documents_page ||=
PageObjects::AssessorInterface::SendSignedConsentDocuments.new
end

def assessor_timeline_page
@assessor_timeline_page ||= PageObjects::AssessorInterface::Timeline.new
end
Expand Down
38 changes: 36 additions & 2 deletions spec/system/assessor_interface/verifying_qualifications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@
when_i_upload_the_consent_document
then_i_see_the(:assessor_qualification_requests_page, reference:)
and_the_upload_consent_document_task_item_is_completed
and_the_send_consent_document_to_applicant_task_is_not_started

and_i_go_back_to_overview
when_i_click_the_send_consent_document_to_applicant_task
then_i_see_the(:assessor_send_signed_consent_documents_page)

when_i_send_the_signed_consent_documents
then_i_see_the(:assessor_qualification_requests_page, reference:)
and_the_send_consent_document_to_applicant_task_is_completed

when_i_go_back_to_overview
then_i_see_the(:assessor_application_page, reference:)
end

Expand Down Expand Up @@ -135,7 +143,27 @@ def and_the_upload_consent_document_task_item_is_completed
expect(upload_consent_document_task_item.status_tag.text).to eq("COMPLETED")
end

def and_i_go_back_to_overview
def and_the_send_consent_document_to_applicant_task_is_not_started
expect(send_consent_document_to_applicant_task_item.status_tag.text).to eq(
"NOT STARTED",
)
end

def when_i_click_the_send_consent_document_to_applicant_task
send_consent_document_to_applicant_task_item.click
end

def when_i_send_the_signed_consent_documents
assessor_send_signed_consent_documents_page.continue_button.click
end

def and_the_send_consent_document_to_applicant_task_is_completed
expect(send_consent_document_to_applicant_task_item.status_tag.text).to eq(
"COMPLETED",
)
end

def when_i_go_back_to_overview
assessor_qualification_requests_page.continue_button.click
end

Expand Down Expand Up @@ -163,6 +191,12 @@ def upload_consent_document_task_item
)
end

def send_consent_document_to_applicant_task_item
assessor_qualification_requests_page.task_lists.third.find_item(
"Send consent document to applicant",
)
end

def application_form
@application_form ||=
create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
},
{
name: "Send consent document to applicant",
link: "#",
link: nil,
status: "cannot_start",
},
{
Expand Down

0 comments on commit 85b633a

Please sign in to comment.