Skip to content

Commit

Permalink
Merge pull request #1985 from DFE-Digital/teacher-qualification-request
Browse files Browse the repository at this point in the history
Add teacher consent workflow
  • Loading branch information
thomasleese authored Feb 14, 2024
2 parents 0933cc5 + 54cc40e commit faaad35
Show file tree
Hide file tree
Showing 35 changed files with 900 additions and 111 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
@@ -0,0 +1,77 @@
# frozen_string_literal: true

module TeacherInterface
class QualificationRequestsController < BaseController
include HandleApplicationFormSection
include HistoryTrackable

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

define_history_origin :index
define_history_reset :index

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
.consent_respondable
.update_all(consent_received_at: Time.zone.now)

TeacherMailer.with(application_form:).consent_submitted.deliver_later

redirect_to %i[teacher_interface 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: 17 additions & 2 deletions app/controllers/teachers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def check_email
end

def signed_out
@section = params[:section]
end

protected
Expand All @@ -61,8 +62,22 @@ def after_sign_in_path_for(resource)
stored_location_for(resource) || teacher_interface_root_path
end

def after_sign_out_path_for(_resource)
teacher_signed_out_path
def after_sign_out_path_for(resource)
if (application_form = resource.application_form)
view_object =
TeacherInterface::ApplicationFormViewObject.new(application_form:)

section =
if view_object.request_qualification_consent?
"qualification_consent"
else
"application"
end

teacher_signed_out_path(section:)
else
teacher_signed_out_path
end
end

private
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: 1 addition & 1 deletion app/lib/document_continue_redirection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ def further_information_request_url
end

def qualification_request_url
[:teacher_interface, :application_form, documentable]
%i[teacher_interface application_form qualification_requests]
end
end
6 changes: 4 additions & 2 deletions app/models/qualification_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ class QualificationRequest < ApplicationRecord
.merge(ApplicationForm.assessable)
end

scope :order_by_role, -> { order("qualifications.start_date": :desc) }
scope :order_by_user, -> { order("qualifications.created_at": :asc) }
scope :order_by_role,
-> { joins(:qualification).order("qualifications.start_date": :desc) }
scope :order_by_user,
-> { joins(:qualification).order("qualifications.created_at": :asc) }

def expires_after
6.weeks
Expand Down
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
Expand Up @@ -146,6 +146,23 @@ def request_professional_standing_certificate?
) || false
end

def request_qualification_consent?
return false if assessment.nil?

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 All @@ -165,7 +182,10 @@ def show_work_history_under_induction_banner?
:requires_preliminary_check,
to: :application_form

delegate :professional_standing_request, to: :assessment, allow_nil: true
delegate :professional_standing_request,
:qualification_requests,
to: :assessment,
allow_nil: true

def task_list_section(key, item_keys)
{
Expand Down
Loading

0 comments on commit faaad35

Please sign in to comment.