|
|
|
@ -141,18 +141,21 @@ module Submissions
|
|
|
|
AccountConfig::WITH_SIGNATURE_ID,
|
|
|
|
AccountConfig::WITH_SIGNATURE_ID,
|
|
|
|
AccountConfig::WITH_FILE_LINKS_KEY,
|
|
|
|
AccountConfig::WITH_FILE_LINKS_KEY,
|
|
|
|
AccountConfig::WITH_TIMESTAMP_SECONDS_KEY,
|
|
|
|
AccountConfig::WITH_TIMESTAMP_SECONDS_KEY,
|
|
|
|
|
|
|
|
AccountConfig::ROTATE_INCREMENTAL_PDF_KEY,
|
|
|
|
AccountConfig::WITH_SUBMITTER_TIMEZONE_KEY,
|
|
|
|
AccountConfig::WITH_SUBMITTER_TIMEZONE_KEY,
|
|
|
|
AccountConfig::WITH_SIGNATURE_ID_REASON_KEY])
|
|
|
|
AccountConfig::WITH_SIGNATURE_ID_REASON_KEY])
|
|
|
|
|
|
|
|
|
|
|
|
with_signature_id = configs.find { |c| c.key == AccountConfig::WITH_SIGNATURE_ID }&.value == true
|
|
|
|
with_signature_id = configs.find { |c| c.key == AccountConfig::WITH_SIGNATURE_ID }&.value == true
|
|
|
|
is_flatten = configs.find { |c| c.key == AccountConfig::FLATTEN_RESULT_PDF_KEY }&.value != false
|
|
|
|
is_flatten = configs.find { |c| c.key == AccountConfig::FLATTEN_RESULT_PDF_KEY }&.value != false
|
|
|
|
|
|
|
|
is_rotate_incremental = configs.find { |c| c.key == AccountConfig::ROTATE_INCREMENTAL_PDF_KEY }&.value == true
|
|
|
|
with_timestamp_seconds = configs.find { |c| c.key == AccountConfig::WITH_TIMESTAMP_SECONDS_KEY }&.value == true
|
|
|
|
with_timestamp_seconds = configs.find { |c| c.key == AccountConfig::WITH_TIMESTAMP_SECONDS_KEY }&.value == true
|
|
|
|
with_submitter_timezone = configs.find { |c| c.key == AccountConfig::WITH_SUBMITTER_TIMEZONE_KEY }&.value == true
|
|
|
|
with_submitter_timezone = configs.find { |c| c.key == AccountConfig::WITH_SUBMITTER_TIMEZONE_KEY }&.value == true
|
|
|
|
with_file_links = configs.find { |c| c.key == AccountConfig::WITH_FILE_LINKS_KEY }&.value == true
|
|
|
|
with_file_links = configs.find { |c| c.key == AccountConfig::WITH_FILE_LINKS_KEY }&.value == true
|
|
|
|
with_signature_id_reason =
|
|
|
|
with_signature_id_reason =
|
|
|
|
configs.find { |c| c.key == AccountConfig::WITH_SIGNATURE_ID_REASON_KEY }&.value != false
|
|
|
|
configs.find { |c| c.key == AccountConfig::WITH_SIGNATURE_ID_REASON_KEY }&.value != false
|
|
|
|
|
|
|
|
|
|
|
|
pdfs_index = build_pdfs_index(submitter.submission, submitter:, flatten: is_flatten)
|
|
|
|
pdfs_index = build_pdfs_index(submitter.submission, submitter:, flatten: is_flatten,
|
|
|
|
|
|
|
|
incremental: is_rotate_incremental)
|
|
|
|
|
|
|
|
|
|
|
|
if with_signature_id || submitter.account.testing?
|
|
|
|
if with_signature_id || submitter.account.testing?
|
|
|
|
pdfs_index.each_value do |pdf|
|
|
|
|
pdfs_index.each_value do |pdf|
|
|
|
|
@ -802,7 +805,7 @@ module Submissions
|
|
|
|
Digest::UUID.uuid_v5(Digest::UUID::OID_NAMESPACE, attachments.map(&:uuid).sort.join(':'))
|
|
|
|
Digest::UUID.uuid_v5(Digest::UUID::OID_NAMESPACE, attachments.map(&:uuid).sort.join(':'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def build_pdfs_index(submission, submitter: nil, flatten: true)
|
|
|
|
def build_pdfs_index(submission, submitter: nil, flatten: true, incremental: false)
|
|
|
|
latest_submitter = find_last_submitter(submission, submitter:)
|
|
|
|
latest_submitter = find_last_submitter(submission, submitter:)
|
|
|
|
|
|
|
|
|
|
|
|
documents = Submissions::EnsureResultGenerated.call(latest_submitter) if latest_submitter
|
|
|
|
documents = Submissions::EnsureResultGenerated.call(latest_submitter) if latest_submitter
|
|
|
|
@ -826,7 +829,7 @@ module Submissions
|
|
|
|
HexaPDF::Document.new(io: StringIO.new(attachment.download))
|
|
|
|
HexaPDF::Document.new(io: StringIO.new(attachment.download))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
pdf = maybe_rotate_pdf(pdf)
|
|
|
|
pdf = maybe_rotate_pdf(pdf, incremental:)
|
|
|
|
|
|
|
|
|
|
|
|
maybe_flatten_pdf(pdf) if flatten
|
|
|
|
maybe_flatten_pdf(pdf) if flatten
|
|
|
|
|
|
|
|
|
|
|
|
@ -845,7 +848,7 @@ module Submissions
|
|
|
|
Rollbar.error(e) if defined?(Rollbar)
|
|
|
|
Rollbar.error(e) if defined?(Rollbar)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def maybe_rotate_pdf(pdf)
|
|
|
|
def maybe_rotate_pdf(pdf, incremental: false)
|
|
|
|
return pdf if pdf.pages.size > MAX_PAGE_ROTATE
|
|
|
|
return pdf if pdf.pages.size > MAX_PAGE_ROTATE
|
|
|
|
|
|
|
|
|
|
|
|
is_pages_rotated = pdf.pages.root[:Rotate].present? && pdf.pages.root[:Rotate] != 0
|
|
|
|
is_pages_rotated = pdf.pages.root[:Rotate].present? && pdf.pages.root[:Rotate] != 0
|
|
|
|
@ -860,7 +863,7 @@ module Submissions
|
|
|
|
|
|
|
|
|
|
|
|
io = StringIO.new
|
|
|
|
io = StringIO.new
|
|
|
|
|
|
|
|
|
|
|
|
pdf.write(io, incremental: false, validate: false)
|
|
|
|
pdf.write(io, incremental:, validate: false)
|
|
|
|
|
|
|
|
|
|
|
|
HexaPDF::Document.new(io:)
|
|
|
|
HexaPDF::Document.new(io:)
|
|
|
|
rescue StandardError => e
|
|
|
|
rescue StandardError => e
|
|
|
|
|