add download combined pdf button
This commit is contained in:
@@ -12,7 +12,6 @@ module Submissions
|
||||
'Helvetica'
|
||||
end
|
||||
|
||||
SIGN_REASON = 'Signed with DocuSeal.co'
|
||||
VERIFIED_TEXT = 'Verified'
|
||||
UNVERIFIED_TEXT = 'Unverified'
|
||||
|
||||
@@ -31,9 +30,35 @@ module Submissions
|
||||
|
||||
# rubocop:disable Metrics
|
||||
def call(submission)
|
||||
document = build_audit_trail(submission)
|
||||
|
||||
account = submission.account
|
||||
|
||||
pkcs = Accounts.load_signing_pkcs(account)
|
||||
tsa_url = Accounts.load_timeserver_url(account)
|
||||
|
||||
io = StringIO.new
|
||||
|
||||
document.trailer.info[:Creator] = "#{Docuseal.product_name} (#{Docuseal::PRODUCT_URL})"
|
||||
|
||||
sign_params = {
|
||||
reason: sign_reason,
|
||||
**Submissions::GenerateResultAttachments.build_signing_params(pkcs, tsa_url)
|
||||
}
|
||||
|
||||
document.sign(io, **sign_params)
|
||||
|
||||
ActiveStorage::Attachment.create!(
|
||||
blob: ActiveStorage::Blob.create_and_upload!(
|
||||
io: StringIO.new(io.string), filename: "Audit Log - #{submission.template.name}.pdf"
|
||||
),
|
||||
name: 'audit_trail',
|
||||
record: submission
|
||||
)
|
||||
end
|
||||
|
||||
def build_audit_trail(submission)
|
||||
account = submission.account
|
||||
verify_url = Rails.application.routes.url_helpers.settings_esign_url(**Docuseal.default_url_options)
|
||||
page_size =
|
||||
if TimeUtils.timezone_abbr(account.timezone, Time.current.beginning_of_year).in?(US_TIMEZONES)
|
||||
@@ -299,24 +324,11 @@ module Submissions
|
||||
|
||||
composer.table(events_data, cell_style: { padding: [0, 0, 12, 0], border: { width: 0 } }) if events_data.present?
|
||||
|
||||
io = StringIO.new
|
||||
composer.document
|
||||
end
|
||||
|
||||
composer.document.trailer.info[:Creator] = "#{Docuseal.product_name} (#{Docuseal::PRODUCT_URL})"
|
||||
|
||||
sign_params = {
|
||||
reason: SIGN_REASON,
|
||||
**Submissions::GenerateResultAttachments.build_signing_params(pkcs, tsa_url)
|
||||
}
|
||||
|
||||
composer.document.sign(io, **sign_params)
|
||||
|
||||
ActiveStorage::Attachment.create!(
|
||||
blob: ActiveStorage::Blob.create_and_upload!(
|
||||
io: StringIO.new(io.string), filename: "Audit Log - #{submission.template.name}.pdf"
|
||||
),
|
||||
name: 'audit_trail',
|
||||
record: submission
|
||||
)
|
||||
def sign_reason
|
||||
'Signed with DocuSeal.co'
|
||||
end
|
||||
|
||||
def add_logo(column, _submission = nil)
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Submissions
|
||||
module GenerateCombinedAttachment
|
||||
module_function
|
||||
|
||||
def call(submitter)
|
||||
pdf = build_combined_pdf(submitter)
|
||||
|
||||
submission = submitter.submission
|
||||
account = submission.account
|
||||
|
||||
pkcs = Accounts.load_signing_pkcs(account)
|
||||
tsa_url = Accounts.load_timeserver_url(account)
|
||||
|
||||
io = StringIO.new
|
||||
|
||||
pdf.trailer.info[:Creator] = "#{Docuseal.product_name} (#{Docuseal::PRODUCT_URL})"
|
||||
|
||||
sign_params = {
|
||||
reason: sign_reason,
|
||||
**Submissions::GenerateResultAttachments.build_signing_params(pkcs, tsa_url)
|
||||
}
|
||||
|
||||
pdf.sign(io, **sign_params)
|
||||
|
||||
ActiveStorage::Attachment.create!(
|
||||
blob: ActiveStorage::Blob.create_and_upload!(
|
||||
io: StringIO.new(io.string), filename: "#{submission.template.name}.pdf"
|
||||
),
|
||||
name: 'combined_document',
|
||||
record: submission
|
||||
)
|
||||
end
|
||||
|
||||
def build_combined_pdf(submitter)
|
||||
pdfs_index = Submissions::GenerateResultAttachments.generate_pdfs(submitter)
|
||||
|
||||
audit_trail = Submissions::GenerateAuditTrail.build_audit_trail(submitter.submission)
|
||||
|
||||
audit_trail.dispatch_message(:complete_objects)
|
||||
|
||||
result = HexaPDF::Document.new
|
||||
|
||||
submitter.submission.template_schema.each do |item|
|
||||
pdf = pdfs_index[item['attachment_uuid']]
|
||||
|
||||
pdf.dispatch_message(:complete_objects)
|
||||
|
||||
pdf.pages.each { |page| result.pages << result.import(page) }
|
||||
end
|
||||
|
||||
audit_trail.pages.each { |page| result.pages << result.import(page) }
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
def sign_reason
|
||||
'Signed with DocuSeal.co'
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -39,17 +39,58 @@ module Submissions
|
||||
|
||||
# rubocop:disable Metrics
|
||||
def call(submitter)
|
||||
cell_layouter = HexaPDF::Layout::TextLayouter.new(text_valign: :center, text_align: :center)
|
||||
pdfs_index = generate_pdfs(submitter)
|
||||
|
||||
template = submitter.submission.template
|
||||
account = submitter.account
|
||||
|
||||
pkcs = Accounts.load_signing_pkcs(account)
|
||||
tsa_url = Accounts.load_timeserver_url(account)
|
||||
|
||||
image_pdfs = []
|
||||
original_documents = template.documents.preload(:blob)
|
||||
|
||||
result_attachments =
|
||||
submitter.submission.template_schema.map do |item|
|
||||
pdf = pdfs_index[item['attachment_uuid']]
|
||||
|
||||
attachment = build_pdf_attachment(pdf:, submitter:, pkcs:, tsa_url:,
|
||||
uuid: item['attachment_uuid'],
|
||||
name: item['name'])
|
||||
|
||||
image_pdfs << pdf if original_documents.find { |a| a.uuid == item['attachment_uuid'] }.image?
|
||||
|
||||
attachment
|
||||
end
|
||||
|
||||
return result_attachments.map { |e| e.tap(&:save!) } if image_pdfs.size < 2
|
||||
|
||||
images_pdf =
|
||||
image_pdfs.each_with_object(HexaPDF::Document.new) do |pdf, doc|
|
||||
pdf.pages.each { |page| doc.pages << doc.import(page) }
|
||||
end
|
||||
|
||||
images_pdf_attachment =
|
||||
build_pdf_attachment(
|
||||
pdf: images_pdf,
|
||||
submitter:,
|
||||
tsa_url:,
|
||||
pkcs:,
|
||||
uuid: images_pdf_uuid(original_documents.select(&:image?)),
|
||||
name: template.name
|
||||
)
|
||||
|
||||
(result_attachments + [images_pdf_attachment]).map { |e| e.tap(&:save!) }
|
||||
end
|
||||
|
||||
def generate_pdfs(submitter)
|
||||
cell_layouter = HexaPDF::Layout::TextLayouter.new(text_valign: :center, text_align: :center)
|
||||
|
||||
is_flatten =
|
||||
submitter.account.account_configs
|
||||
.find_or_initialize_by(key: AccountConfig::FLATTEN_RESULT_PDF_KEY).value != false
|
||||
|
||||
account = submitter.account
|
||||
pkcs = Accounts.load_signing_pkcs(account)
|
||||
tsa_url = Accounts.load_timeserver_url(account)
|
||||
attachments_data_cache = {}
|
||||
|
||||
pdfs_index = build_pdfs_index(submitter, flatten: is_flatten)
|
||||
@@ -259,40 +300,7 @@ module Submissions
|
||||
end
|
||||
end
|
||||
|
||||
image_pdfs = []
|
||||
original_documents = template.documents.preload(:blob)
|
||||
|
||||
result_attachments =
|
||||
submitter.submission.template_schema.map do |item|
|
||||
pdf = pdfs_index[item['attachment_uuid']]
|
||||
|
||||
attachment = build_pdf_attachment(pdf:, submitter:, pkcs:, tsa_url:,
|
||||
uuid: item['attachment_uuid'],
|
||||
name: item['name'])
|
||||
|
||||
image_pdfs << pdf if original_documents.find { |a| a.uuid == item['attachment_uuid'] }.image?
|
||||
|
||||
attachment
|
||||
end
|
||||
|
||||
return result_attachments.map { |e| e.tap(&:save!) } if image_pdfs.size < 2
|
||||
|
||||
images_pdf =
|
||||
image_pdfs.each_with_object(HexaPDF::Document.new) do |pdf, doc|
|
||||
pdf.pages.each { |page| doc.pages << doc.import(page) }
|
||||
end
|
||||
|
||||
images_pdf_attachment =
|
||||
build_pdf_attachment(
|
||||
pdf: images_pdf,
|
||||
submitter:,
|
||||
tsa_url:,
|
||||
pkcs:,
|
||||
uuid: images_pdf_uuid(original_documents.select(&:image?)),
|
||||
name: template.name
|
||||
)
|
||||
|
||||
(result_attachments + [images_pdf_attachment]).map { |e| e.tap(&:save!) }
|
||||
pdfs_index
|
||||
end
|
||||
|
||||
def build_pdf_attachment(pdf:, submitter:, pkcs:, tsa_url:, uuid:, name:)
|
||||
|
||||
Reference in New Issue
Block a user