add flatten pdf toggle

pull/267/head
Pete Matsyburka 2 years ago
parent 02a7b6ea55
commit 2d76198290

@ -11,7 +11,8 @@ class AccountConfigsController < ApplicationController
AccountConfig::ESIGNING_PREFERENCE_KEY,
AccountConfig::FORM_WITH_CONFETTI_KEY,
AccountConfig::DOWNLOAD_LINKS_AUTH_KEY,
AccountConfig::FORCE_SSO_AUTH_KEY
AccountConfig::FORCE_SSO_AUTH_KEY,
AccountConfig::FLATTEN_RESULT_PDF_KEY
].freeze
InvalidKey = Class.new(StandardError)

@ -36,6 +36,7 @@ class AccountConfig < ApplicationRecord
WEBHOOK_PREFERENCES_KEY = 'webhook_preferences'
DOWNLOAD_LINKS_AUTH_KEY = 'download_links_auth'
FORCE_SSO_AUTH_KEY = 'force_sso_auth'
FLATTEN_RESULT_PDF_KEY = 'flatten_result_pdf'
DEFAULT_VALUES = {
SUBMITTER_INVITATION_EMAIL_KEY => {

@ -140,6 +140,18 @@
</div>
<% 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>
<% end %>
</div>

@ -44,12 +44,16 @@ module Submissions
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
pkcs = Accounts.load_signing_pkcs(account)
tsa_url = Accounts.load_timeserver_url(account)
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|
next if field['submitter_uuid'] != submitter.uuid
@ -86,10 +90,12 @@ module Submissions
next if Array.wrap(value).compact_blank.blank?
begin
page.flatten_annotations
rescue StandardError => e
Rollbar.error(e) if defined?(Rollbar)
if is_flatten
begin
page.flatten_annotations
rescue StandardError => e
Rollbar.error(e) if defined?(Rollbar)
end
end
canvas = page.canvas(type: :overlay)
@ -335,7 +341,7 @@ module Submissions
Digest::UUID.uuid_v5(Digest::UUID::OID_NAMESPACE, attachments.map(&:uuid).sort.join(':'))
end
def build_pdfs_index(submitter)
def build_pdfs_index(submitter, flatten: true)
latest_submitter = find_last_submitter(submitter)
Submissions::EnsureResultGenerated.call(latest_submitter) if latest_submitter
@ -353,10 +359,12 @@ module Submissions
pdf = maybe_rotate_pdf(pdf)
begin
pdf.acro_form&.flatten
rescue StandardError => e
Rollbar.error(e) if defined?(Rollbar)
if flatten
begin
pdf.acro_form&.flatten
rescue StandardError => e
Rollbar.error(e) if defined?(Rollbar)
end
end
pdf.config['font.on_missing_glyph'] = method(:on_missing_glyph).to_proc

Loading…
Cancel
Save