Skip to content

Commit

Permalink
Add download consent document page
Browse files Browse the repository at this point in the history
This adds a page that allows applicants to download their consent
document before uploading the signed one.
  • Loading branch information
thomasleese committed Feb 12, 2024
1 parent 426c07c commit a1dbc0d
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 54 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.sass.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ $govuk-assets-path: "/";
$moj-images-path: "/";

@import "govuk-frontend/govuk/all";
@import "@ministryofjustice/frontend/moj/components/ticket-panel/ticket-panel";
@import "@ministryofjustice/frontend/moj/components/timeline/timeline";
@import "dfe-autocomplete/src/dfe-autocomplete";
@import "location-autocomplete.min";
Expand Down
47 changes: 1 addition & 46 deletions app/components/check_your_answers_summary/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,42 +117,7 @@ def format_date(date, field)
end

def format_document(document, field)
scope =
(
if field[:translation]
document.translated_uploads
else
document.original_uploads
end
)

if document.optional? && !document.available
"<em>The applicant has indicated that they haven't done an induction period " \
"and don't have this document.</em>".html_safe
else
uploads =
scope
.order(:created_at)
.select { |upload| upload.attachment.present? }

[
format_array(uploads, field),
if malware_scan_active && scope.scan_result_suspect.exists?
"<em>#{scope.count} #{"file upload".pluralize(scope.count)} has been scanned as malware and deleted.</em>"
elsif request.path.starts_with?("/assessor") &&
convert_to_pdf_active && !uploads.all?(&:is_pdf?)
helpers.govuk_link_to(
"Download as PDF (opens in a new tab)",
url_helpers.assessor_interface_application_form_document_pdf_path(
document,
field[:translation] ? "translated" : "original",
),
target: :_blank,
rel: :noopener,
)
end,
].compact_blank.join("<br /><br />").html_safe
end
helpers.document_link_to(document, translated: field[:translation])
end

def format_array(list, field)
Expand All @@ -162,15 +127,5 @@ def format_array(list, field)
def url_helpers
@url_helpers ||= Rails.application.routes.url_helpers
end

def malware_scan_active
@malware_scan_active ||=
FeatureFlags::FeatureFlag.active?(:fetch_malware_scan_result)
end

def convert_to_pdf_active
@convert_to_pdf_active =
FeatureFlags::FeatureFlag.active?(:convert_documents_to_pdf)
end
end
end
9 changes: 7 additions & 2 deletions app/controllers/teacher_interface/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def document
.assessment
&.further_information_requests
&.flat_map(&:items) || []
),
) + (application_form.assessment&.qualification_requests || []),
).find(params[:document_id] || params[:id])
end

Expand All @@ -37,11 +37,16 @@ def redirect_unless_application_form_is_draft
end
end

def redirect_unless_draft_or_further_information
def redirect_unless_draft_or_additional_information
if document.for_further_information_request?
unless document.documentable.further_information_request.requested?
redirect_to %i[teacher_interface application_form]
end
elsif document.for_qualification_request?
if document.documentable.consent_requested_at.nil? ||
document.documentable.consent_received_at.present?
redirect_to %i[teacher_interface application_form]
end
else
redirect_unless_application_form_is_draft
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/teacher_interface/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class DocumentsController < BaseController
include HandleApplicationFormSection
include HistoryTrackable

before_action :redirect_unless_draft_or_further_information
before_action :redirect_unless_draft_or_additional_information
before_action :load_application_form
before_action :load_document

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,58 @@

module TeacherInterface
class QualificationRequestsController < BaseController
include HandleApplicationFormSection
include HistoryTrackable

before_action :load_qualification_request, except: :index

define_history_origin :index
define_history_reset :index

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

def edit_download
@form =
QualificationRequestDownloadForm.new(
qualification_request:,
downloaded:
qualification_request.unsigned_consent_document_downloaded,
)
end

def update_download
@form =
QualificationRequestDownloadForm.new(
qualification_request:,
downloaded:
params.dig(
:teacher_interface_qualification_request_download_form,
:downloaded,
),
)

handle_application_form_section(
form: @form,
if_success_then_redirect:
teacher_interface_application_form_qualification_requests_path,
if_failure_then_render: :edit_download,
)
end

private

attr_reader :qualification_request

def load_qualification_request
@qualification_request =
QualificationRequest
.joins(assessment: :application_form)
.includes(:qualification, :application_form)
.find_by!(id: params[:id], assessment: { application_form: })

@qualification = qualification_request.qualification
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/teacher_interface/uploads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class UploadsController < BaseController
skip_before_action :authenticate_teacher!
before_action -> { authenticate_or_redirect(:teacher) }

before_action :redirect_unless_draft_or_further_information
before_action :redirect_unless_draft_or_additional_information
before_action :load_application_form
before_action :load_document
before_action :load_upload, only: %i[delete destroy show]
Expand Down
19 changes: 19 additions & 0 deletions app/forms/teacher_interface/qualification_request_download_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module TeacherInterface
class QualificationRequestDownloadForm < BaseForm
attr_accessor :qualification_request
attribute :downloaded, :boolean

validates :qualification_request, presence: true
validates :downloaded, presence: true

def update_model
if downloaded
qualification_request.update!(
unsigned_consent_document_downloaded: true,
)
end
end
end
end
50 changes: 50 additions & 0 deletions app/helpers/document_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

module DocumentHelper
include UploadHelper

def document_link_to(document, translated: false)
scope =
(
if translated
document.translated_uploads
else
document.original_uploads
end
)

if document.optional? && !document.available
"<em>The applicant has indicated that they haven't done an induction period " \
"and don't have this document.</em>".html_safe
else
uploads =
scope.order(:created_at).select { |upload| upload.attachment.present? }

malware_scan_active =
FeatureFlags::FeatureFlag.active?(:fetch_malware_scan_result)
convert_to_pdf_active =
FeatureFlags::FeatureFlag.active?(:convert_documents_to_pdf)

[
uploads
.map { |upload| upload_link_to(upload) }
.join("<br />")
.html_safe,
if malware_scan_active && scope.scan_result_suspect.exists?
"<em>#{scope.count} #{"file upload".pluralize(scope.count)} has been scanned as malware and deleted.</em>"
elsif request.path.starts_with?("/assessor") && convert_to_pdf_active &&
!uploads.all?(&:is_pdf?)
helpers.govuk_link_to(
"Download as PDF (opens in a new tab)",
url_helpers.assessor_interface_application_form_document_pdf_path(
document,
translated ? "translated" : "original",
),
target: :_blank,
rel: :noopener,
)
end,
].compact_blank.join("<br /><br />").html_safe
end
end
end
2 changes: 0 additions & 2 deletions app/models/reference_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ class ReferenceRequest < ApplicationRecord
validates :satisfied_response, inclusion: [true, false]
end

delegate :application_form, to: :assessment

def responses_given?
[
contact_response,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% content_for :page_title, "Download consent document" %>
<% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_qualification_requests_path) %>

<%= form_with model: @form, url: [:download, :teacher_interface, :application_form, @qualification_request] do |f| %>
<%= f.govuk_error_summary %>

<h1 class="govuk-heading-l">Download consent document</h1>

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

<article class="moj-ticket-panel">
<section class="moj-ticket-panel__content moj-ticket-panel__content--blue">
<h2 class="govuk-heading-m govuk-!-margin-bottom-2">Download the consent document</h2>
<p class="govuk-body"><%= document_link_to(@qualification_request.unsigned_consent_document) %></p>
</section>
</article>

<%= f.govuk_check_boxes_fieldset :downloaded, multiple: false, small: true, legend: nil do %>
<%= f.govuk_check_box :downloaded, true, false, link_errors: true, label: { text: "I have downloaded the consent document." } %>
<% end %>

<%= render "shared/save_submit_buttons", f: %>
<% end %>
4 changes: 4 additions & 0 deletions config/locales/teacher_interface.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ en:
invalid: Enter the certificate date in the format 27 3 1980
future: Certificate date must be in the past
comparison: Certificate date must be after completion date
teacher_interface/qualification_request_download_form:
attributes:
downloaded:
blank: Confirm that you have downloaded the consent document.
teacher_interface/reference_request_children_response_form:
attributes:
children_response:
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@
path: "/qualification-requests",
only: %i[index] do
member do
get "download"
get "upload"
get "download", to: "qualification_requests#edit_download"
post "download", to: "qualification_requests#update_download"
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/factories/qualification_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@

trait :consent_required do
signed_consent_document_required { true }

after(:create) do |qualification_request, _evaluator|
create(
:upload,
document: qualification_request.unsigned_consent_document,
)
end
end

trait :consent_requested do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe TeacherInterface::QualificationRequestDownloadForm,
type: :model do
let(:qualification_request) { create(:qualification_request) }

subject(:form) { described_class.new(qualification_request:, downloaded:) }

describe "validations" do
let(:downloaded) { "" }

it { is_expected.to validate_presence_of(:qualification_request) }
it { is_expected.to validate_presence_of(:downloaded) }
end

describe "#save" do
subject(:save) { form.save(validate: false) }

context "with a positive response" do
let(:downloaded) { "true" }

it "sets unsigned_consent_document_downloaded" do
expect { save }.to change(
qualification_request,
:unsigned_consent_document_downloaded,
).to(true)
end
end

context "with a negative response" do
let(:downloaded) { "false" }

it "doesn't set unsigned_consent_document_downloaded" do
expect { save }.to_not change(
qualification_request,
:unsigned_consent_document_downloaded,
)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module PageObjects
module TeacherInterface
class QualificationRequestDownload < SitePrism::Page
set_url "/teacher/application/qualification-requests/{id}/download"

element :downloaded_checkbox, ".govuk-checkboxes__input", visible: false

element :continue_button, ".govuk-button:not(.govuk-button--secondary)"
element :save_and_sign_out_button, ".govuk-button.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 @@ -569,6 +569,11 @@ def teacher_qualification_requests_page
PageObjects::TeacherInterface::QualificationRequests.new
end

def teacher_qualification_request_download_page
@teacher_qualification_request_download_page =
PageObjects::TeacherInterface::QualificationRequestDownload.new
end

def teacher_reference_received_page
@teacher_reference_received_page ||=
PageObjects::TeacherInterface::ReferenceReceived.new
Expand Down
Loading

0 comments on commit a1dbc0d

Please sign in to comment.