add flatten pdf toggle
This commit is contained in:
@@ -11,7 +11,8 @@ class AccountConfigsController < ApplicationController
|
|||||||
AccountConfig::ESIGNING_PREFERENCE_KEY,
|
AccountConfig::ESIGNING_PREFERENCE_KEY,
|
||||||
AccountConfig::FORM_WITH_CONFETTI_KEY,
|
AccountConfig::FORM_WITH_CONFETTI_KEY,
|
||||||
AccountConfig::DOWNLOAD_LINKS_AUTH_KEY,
|
AccountConfig::DOWNLOAD_LINKS_AUTH_KEY,
|
||||||
AccountConfig::FORCE_SSO_AUTH_KEY
|
AccountConfig::FORCE_SSO_AUTH_KEY,
|
||||||
|
AccountConfig::FLATTEN_RESULT_PDF_KEY
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
InvalidKey = Class.new(StandardError)
|
InvalidKey = Class.new(StandardError)
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class AccountConfig < ApplicationRecord
|
|||||||
WEBHOOK_PREFERENCES_KEY = 'webhook_preferences'
|
WEBHOOK_PREFERENCES_KEY = 'webhook_preferences'
|
||||||
DOWNLOAD_LINKS_AUTH_KEY = 'download_links_auth'
|
DOWNLOAD_LINKS_AUTH_KEY = 'download_links_auth'
|
||||||
FORCE_SSO_AUTH_KEY = 'force_sso_auth'
|
FORCE_SSO_AUTH_KEY = 'force_sso_auth'
|
||||||
|
FLATTEN_RESULT_PDF_KEY = 'flatten_result_pdf'
|
||||||
|
|
||||||
DEFAULT_VALUES = {
|
DEFAULT_VALUES = {
|
||||||
SUBMITTER_INVITATION_EMAIL_KEY => {
|
SUBMITTER_INVITATION_EMAIL_KEY => {
|
||||||
|
|||||||
@@ -140,6 +140,18 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% account_config = AccountConfig.find_or_initialize_by(account: current_account, key: AccountConfig::FLATTEN_RESULT_PDF_KEY) %>
|
||||||
|
<% if can?(:manage, account_config) %>
|
||||||
|
<%= form_for account_config, url: account_configs_path, method: :post do |f| %>
|
||||||
|
<%= f.hidden_field :key %>
|
||||||
|
<div class="flex items-center justify-between py-2.5">
|
||||||
|
<span>
|
||||||
|
Remove PDF form fillable fields from the signed PDF (flatten form)
|
||||||
|
</span>
|
||||||
|
<%= f.check_box :value, { class: 'toggle', checked: account_config.value != false, onchange: 'this.form.requestSubmit()' } %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -44,12 +44,16 @@ module Submissions
|
|||||||
|
|
||||||
template = submitter.submission.template
|
template = submitter.submission.template
|
||||||
|
|
||||||
|
is_flatten =
|
||||||
|
submitter.account.account_configs
|
||||||
|
.find_or_initialize_by(key: AccountConfig::FLATTEN_RESULT_PDF_KEY).value != false
|
||||||
|
|
||||||
account = submitter.account
|
account = submitter.account
|
||||||
pkcs = Accounts.load_signing_pkcs(account)
|
pkcs = Accounts.load_signing_pkcs(account)
|
||||||
tsa_url = Accounts.load_timeserver_url(account)
|
tsa_url = Accounts.load_timeserver_url(account)
|
||||||
attachments_data_cache = {}
|
attachments_data_cache = {}
|
||||||
|
|
||||||
pdfs_index = build_pdfs_index(submitter)
|
pdfs_index = build_pdfs_index(submitter, flatten: is_flatten)
|
||||||
|
|
||||||
submitter.submission.template_fields.each do |field|
|
submitter.submission.template_fields.each do |field|
|
||||||
next if field['submitter_uuid'] != submitter.uuid
|
next if field['submitter_uuid'] != submitter.uuid
|
||||||
@@ -86,10 +90,12 @@ module Submissions
|
|||||||
|
|
||||||
next if Array.wrap(value).compact_blank.blank?
|
next if Array.wrap(value).compact_blank.blank?
|
||||||
|
|
||||||
begin
|
if is_flatten
|
||||||
page.flatten_annotations
|
begin
|
||||||
rescue StandardError => e
|
page.flatten_annotations
|
||||||
Rollbar.error(e) if defined?(Rollbar)
|
rescue StandardError => e
|
||||||
|
Rollbar.error(e) if defined?(Rollbar)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
canvas = page.canvas(type: :overlay)
|
canvas = page.canvas(type: :overlay)
|
||||||
@@ -335,7 +341,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(submitter)
|
def build_pdfs_index(submitter, flatten: true)
|
||||||
latest_submitter = find_last_submitter(submitter)
|
latest_submitter = find_last_submitter(submitter)
|
||||||
|
|
||||||
Submissions::EnsureResultGenerated.call(latest_submitter) if latest_submitter
|
Submissions::EnsureResultGenerated.call(latest_submitter) if latest_submitter
|
||||||
@@ -353,10 +359,12 @@ module Submissions
|
|||||||
|
|
||||||
pdf = maybe_rotate_pdf(pdf)
|
pdf = maybe_rotate_pdf(pdf)
|
||||||
|
|
||||||
begin
|
if flatten
|
||||||
pdf.acro_form&.flatten
|
begin
|
||||||
rescue StandardError => e
|
pdf.acro_form&.flatten
|
||||||
Rollbar.error(e) if defined?(Rollbar)
|
rescue StandardError => e
|
||||||
|
Rollbar.error(e) if defined?(Rollbar)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
pdf.config['font.on_missing_glyph'] = method(:on_missing_glyph).to_proc
|
pdf.config['font.on_missing_glyph'] = method(:on_missing_glyph).to_proc
|
||||||
|
|||||||
Reference in New Issue
Block a user