Skip to content

Commit

Permalink
Allow submitting consent documents
Browse files Browse the repository at this point in the history
This adds the functionality to submit consent documentsonce they've been
signed.
  • Loading branch information
thomasleese committed Feb 13, 2024
1 parent 27526ee commit 3c54bfa
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class QualificationRequestsController < BaseController
include HandleApplicationFormSection
include HistoryTrackable

before_action :load_qualification_request, except: :index
before_action :load_qualification_request,
only: %i[edit_download update_download]

define_history_origin :index
define_history_reset :index
Expand All @@ -14,6 +15,22 @@ def index
@view_object = QualificationRequestsViewObject.new(application_form:)
end

def check
@view_object = QualificationRequestsViewObject.new(application_form:)
end

def submit
@qualification_requests ||=
application_form
.assessment
.qualification_requests
.joins(assessment: :application_form)
.consent_respondable
.update_all(consent_received_at: Time.zone.now)

redirect_to %i[teacher_interface application_form]
end

def edit_download
@form =
QualificationRequestDownloadForm.new(
Expand Down
11 changes: 11 additions & 0 deletions app/view_objects/teacher_interface/application_form_view_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ def request_qualification_consent?
qualification_requests.consent_respondable.exists?
end

def qualification_consent_submitted?
return false if assessment.nil?

required_qualification_requests =
qualification_requests.where(signed_consent_document_required: true)

return false if required_qualification_requests.empty?

required_qualification_requests.all?(&:consent_received?)
end

def show_work_history_under_submission_banner?
application_form.qualification_changed_work_history_duration &&
!work_history_duration.enough_for_submission?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ def task_list_sections
end
end

def can_submit?
qualification_requests.all? do |qualification_request|
qualification_request.unsigned_consent_document_downloaded &&
qualification_request.signed_consent_document.completed?
end
end

def check_your_answers_fields
qualification_requests.each_with_object(
{},
) do |qualification_request, memo|
memo[qualification_request.id] = {
title: qualification_title(qualification_request.qualification),
value: qualification_request.signed_consent_document,
href: [
:teacher_interface,
:application_form,
qualification_request.signed_consent_document,
],
}
end
end

private

attr_reader :application_form
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
<%= govuk_panel(title_text: view_object.further_information_request&.received? ? "Further information successfully submitted" : "Application complete") do %>
<% further_information_submitted = view_object.further_information_request&.received? %>
<% qualification_consent_submitted = view_object.qualification_consent_submitted? %>

<% title_text = if qualification_consent_submitted
"Consent documents successfully submitted"
elsif further_information_submitted
"Further information successfully submitted"
else
"Application complete"
end %>

<%= govuk_panel(title_text:) do %>
Your application reference number
<br />
<strong><%= view_object.application_form.reference %></strong>
<% end %>

<% if view_object.further_information_request&.received? %>
<% if qualification_consent_submitted %>
<p class="govuk-body">We’ve sent you an email to confirm.</p>
<p class="govuk-body">Once an assessor has checked the documents to make sure you’ve provided the required information, they’ll continue reviewing your application.</p>
<p class="govuk-body">You can now close this page.</p>
<% elsif further_information_submitted %>
<h3 class="govuk-heading-m">You’ve successfully submitted your further information</h3>
<p class="govuk-body">We’ve sent you an email to confirm that we’ve received it.</p>
<p class="govuk-body">The assessor will continue to review your QTS application once they’ve checked that the further information you’ve provided can be accepted.</p>
Expand Down
18 changes: 18 additions & 0 deletions app/views/teacher_interface/qualification_requests/check.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<% content_for :page_title, "Check your uploaded consent documents" %>
<% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_qualification_requests_path) %>

<h1 class="govuk-heading-l">Check your uploaded consent documents</h1>

<%= render(CheckYourAnswersSummary::Component.new(
id: "check-your-answers",
model: @assessment,
title: t(".check_your_answers"),
fields: @view_object.check_your_answers_fields
)) %>

<% if @view_object.can_submit? %>
<h2 class="govuk-heading-m">Submit your consent documents</h2>
<p class="govuk-body">By selecting the ‘Submit’ button you confirm that, to the best of your knowledge, the details you’ve provided are correct.</p>
<p class="govuk-body">You will not be able to change your response, add new documents, or delete anything once you submit.</p>
<%= govuk_button_to "Submit", submit_teacher_interface_application_form_qualification_requests_path %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@

<%= render(TaskList::Component.new(@view_object.task_list_sections)) %>

<%= govuk_button_link_to t("teacher_interface.application_forms.show.draft.save"), destroy_teacher_session_path, secondary: true %>
<div class="govuk-button-group">
<% if @view_object.can_submit? %>
<%= govuk_button_link_to "Continue", check_teacher_interface_application_form_qualification_requests_path %>
<% end %>

<%= govuk_button_link_to t("teacher_interface.application_forms.show.draft.save"), destroy_teacher_session_path, secondary: true %>
</div>
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@
get "download", to: "qualification_requests#edit_download"
post "download", to: "qualification_requests#update_download"
end

collection do
get "check"
post "submit"
end
end
end

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

module PageObjects
module TeacherInterface
class CheckQualificationRequests < SitePrism::Page
set_url "/teacher/application/qualification-requests/check"

element :heading, "h1"
section :summary_card, GovukSummaryCard, ".govuk-summary-card"
element :submit_button, ".govuk-button"
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 @@ -375,6 +375,11 @@ def teacher_check_qualification_page
PageObjects::TeacherInterface::CheckQualification.new
end

def teacher_check_qualification_requests_page
@teacher_check_qualification_requests_page =
PageObjects::TeacherInterface::CheckQualificationRequests.new
end

def teacher_check_qualifications_page
@teacher_check_qualifications_page ||=
PageObjects::TeacherInterface::CheckQualifications.new
Expand Down
29 changes: 29 additions & 0 deletions spec/system/teacher_interface/qualification_consent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@

when_i_dont_need_to_upload_another_file
then_i_see_the(:teacher_qualification_requests_page)

when_i_click_check_your_answers
then_i_see_the(:teacher_check_qualification_requests_page)
and_i_see_the_documents

when_i_click_submit
then_i_see_the(:teacher_application_page)
and_i_see_the_consent_submitted_status
end

def given_there_is_an_application_form
Expand Down Expand Up @@ -121,6 +129,27 @@ def when_i_dont_need_to_upload_another_file
teacher_check_document_page.form.continue_button.click
end

def when_i_click_check_your_answers
teacher_qualification_requests_page.check_your_answers_button.click
end

def and_i_see_the_documents
expect(teacher_check_qualification_requests_page.summary_card).to be_visible
end

def when_i_click_submit
teacher_check_qualification_requests_page.submit_button.click
end

def and_i_see_the_consent_submitted_status
expect(teacher_submitted_application_page.panel.title.text).to eq(
"Consent documents successfully submitted",
)
expect(teacher_submitted_application_page.panel.body.text).to eq(
"Your application reference number\n#{@application_form.reference}",
)
end

def teacher
@teacher ||= create(:teacher)
end
Expand Down

0 comments on commit 3c54bfa

Please sign in to comment.