-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1985 from DFE-Digital/teacher-qualification-request
Add teacher consent workflow
- Loading branch information
Showing
35 changed files
with
900 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
app/controllers/teacher_interface/qualification_requests_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/forms/teacher_interface/qualification_request_download_form.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.