-
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 #1890 from DFE-Digital/upload-convert-to-pdf
Convert files to PDF on upload
- Loading branch information
Showing
35 changed files
with
395 additions
and
242 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
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
40 changes: 40 additions & 0 deletions
40
app/controllers/assessor_interface/documents_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,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module AssessorInterface | ||
class DocumentsController < BaseController | ||
include ActiveStorage::Streaming | ||
include StreamedResponseAuthenticatable | ||
include RescueActiveStorageErrors | ||
include UploadHelper | ||
|
||
skip_before_action :authenticate_staff! | ||
before_action { authenticate_or_redirect(:staff) } | ||
|
||
def show_pdf | ||
authorize %i[assessor_interface application_form] | ||
|
||
unless all_uploads_downloadable? | ||
render "shared/malware_scan" | ||
return | ||
end | ||
|
||
translation = params[:scope] == "translated" | ||
|
||
if (pdf_data = ConvertToPDF.call(document:, translation:)) | ||
send_data(pdf_data, type: "application/pdf", disposition: :inline) | ||
else | ||
error_internal_server_error | ||
end | ||
end | ||
|
||
private | ||
|
||
def document | ||
@document ||= Document.find(params[:id]) | ||
end | ||
|
||
def all_uploads_downloadable? | ||
document.uploads.all? { |upload| upload_downloadable?(upload) } | ||
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
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 |
---|---|---|
|
@@ -2,6 +2,4 @@ | |
|
||
class StaticController < ApplicationController | ||
include EligibilityCurrentNamespace | ||
|
||
layout "two_thirds" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module UploadHelper | ||
def upload_link_to(upload) | ||
if downloadable?(upload) | ||
href = | ||
govuk_link_to( | ||
"#{upload.name} (opens in a new tab)", | ||
[interface, :application_form, upload.document, upload], | ||
upload_path(upload), | ||
target: :_blank, | ||
rel: :noopener, | ||
) | ||
else | ||
output = | ||
govuk_link_to( | ||
upload.name, | ||
[interface, :application_form, upload.document, upload], | ||
) | ||
if show_scan_result_error?(upload) | ||
output += | ||
tag.p( | ||
"There’s a problem with this file", | ||
class: "govuk-error-message", | ||
) | ||
end | ||
output | ||
end | ||
end | ||
|
||
def interface | ||
if request.path.start_with?("/assessor/") | ||
:assessor_interface | ||
else | ||
:teacher_interface | ||
end | ||
end | ||
scan_result_problem = | ||
malware_scanning_enabled? && | ||
(upload.scan_result_error? || upload.scan_result_suspect?) | ||
|
||
def downloadable?(upload) | ||
unless FeatureFlags::FeatureFlag.active?(:fetch_malware_scan_result) | ||
return true | ||
end | ||
return href unless scan_result_problem | ||
|
||
upload.scan_result_clean? | ||
href + | ||
tag.p("There’s a problem with this file", class: "govuk-error-message") | ||
end | ||
|
||
def show_scan_result_error?(upload) | ||
unless FeatureFlags::FeatureFlag.active?(:fetch_malware_scan_result) | ||
return false | ||
end | ||
def upload_path(upload) | ||
interface = | ||
if request.path.start_with?("/assessor/") | ||
:assessor_interface | ||
else | ||
:teacher_interface | ||
end | ||
[interface, :application_form, upload.document, upload] | ||
end | ||
|
||
def upload_downloadable?(upload) | ||
!malware_scanning_enabled? || upload.scan_result_clean? | ||
end | ||
|
||
upload.scan_result_error? || upload.scan_result_suspect? | ||
def malware_scanning_enabled? | ||
FeatureFlags::FeatureFlag.active?(:fetch_malware_scan_result) | ||
end | ||
end |
Oops, something went wrong.