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 29, 2024
1 parent e816ddb commit 0f7c85e
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 30 deletions.
42 changes: 40 additions & 2 deletions app/controllers/assessor_interface/consent_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ module AssessorInterface
class ConsentRequestsController < BaseController
include HistoryTrackable

before_action :set_variables, except: :new
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]

skip_before_action :track_history, only: :new

Expand All @@ -23,6 +26,34 @@ def new
]
end

def edit_request
end

def update_request
if consent_requests.present?
ActiveRecord::Base.transaction do
consent_requests.each do |requestable|
RequestRequestable.call(requestable:, user: current_staff)
end

application_form.reload
ApplicationFormStatusUpdater.call(
application_form:,
user: current_staff,
)
end

TeacherMailer.with(application_form:).consent_requested.deliver_later
end

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

def edit_upload
@form = UploadUnsignedConsentDocumentForm.new(consent_request:)
end
Expand Down Expand Up @@ -92,7 +123,14 @@ def consent_request
@consent_request ||= consent_requests.find(params[:id])
end

def set_variables
def set_collection_variables
authorize %i[assessor_interface consent_request]
@consent_requests = consent_requests
@application_form = application_form
@assessment = assessment
end

def set_member_variables
@consent_request = authorize [:assessor_interface, consent_request]
@application_form = application_form
@assessment = assessment
Expand Down
6 changes: 6 additions & 0 deletions app/policies/assessor_interface/consent_request_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ def update_upload?

alias_method :edit_upload?, :update_upload?

def update_request?
user.verify_permission
end

alias_method :edit_request?, :update_request?

def update_review?
user.assess_permission
end
Expand Down
4 changes: 1 addition & 3 deletions app/services/verify_assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ def create_professional_standing_request

def create_qualification_requests
qualifications.map do |qualification|
QualificationRequest
.create!(assessment:, qualification:)
.tap { |requestable| RequestRequestable.call(requestable:, user:) }
QualificationRequest.create!(assessment:, qualification:)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,29 @@ def send_consent_document_in_all_qualifications?
end

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

all_consents_requested = consent_requests.all?(&:requested?)

{
name: "Send consent document to applicant",
link: "#",
name:
"Send consent #{"document".pluralize(consent_requests.count)} to applicant",
link:
if all_documents_completed && !all_consents_requested
[
:request,
:assessor_interface,
application_form,
assessment,
:consent_requests,
]
end,
status:
if consent_requests.map(&:unsigned_consent_document).all?(
&:completed?
)
consent_requests.all?(&:requested?) ? "completed" : "not_started"
if all_documents_completed
all_consents_requested ? "completed" : "not_started"
else
"cannot_start"
end,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<% 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 |consent_request| %>
<li><%= qualification_title(consent_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", [:request, :assessor_interface, @application_form, @assessment, :consent_requests] %>
<%= render "shared/assessor_interface/cancel_link" %>
</div>
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
end

resources :consent_requests, path: "/consent-requests", only: %i[new] do
collection do
get "request", to: "consent_requests#edit_request"
post "request", to: "consent_requests#update_request"
end

member do
get "upload", to: "consent_requests#edit_upload"
post "upload", to: "consent_requests#update_upload"
Expand Down
10 changes: 10 additions & 0 deletions spec/policies/assessor_interface/consent_request_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@
it_behaves_like "a policy method requiring the verify permission"
end

describe "#update_request?" do
subject(:update?) { policy.update_request? }
it_behaves_like "a policy method requiring the verify permission"
end

describe "#edit_request?" do
subject(:edit?) { policy.edit_request? }
it_behaves_like "a policy method requiring the verify permission"
end

describe "#update_review?" do
subject(:update_review?) { policy.update_review? }
it_behaves_like "a policy method requiring the assess permission"
Expand Down
18 changes: 3 additions & 15 deletions spec/services/verify_assessment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,9 @@
end
end

describe "creating qualification request" do
subject(:qualification_request) do
QualificationRequest.find_by(assessment:, qualification:)
end

it { is_expected.to be_nil }

context "after calling the service" do
before { call }

it { is_expected.to_not be_nil }

it "sets the attributes correctly" do
expect(qualification_request.requested?).to be true
end
describe "qualification request" do
it "creates a qualification request" do
expect { call }.to change(QualificationRequest, :count).by(1)
end
end

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}" \
"/consent-requests/request"

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 @@ -160,7 +160,7 @@
{
name: "Upload consent document",
link: [
:edit,
:upload,
:assessor_interface,
application_form,
assessment,
Expand All @@ -170,7 +170,7 @@
},
{
name: "Send consent document to applicant",
link: "#",
link: nil,
status: "cannot_start",
},
{
Expand Down

0 comments on commit 0f7c85e

Please sign in to comment.