allow to disable completed email attachments

pull/349/head
Pete Matsyburka 1 year ago
parent ee9ee6ee32
commit cb38549480

@ -22,6 +22,7 @@ class TemplatesPreferencesController < ApplicationController
preferences: %i[bcc_completed request_email_subject request_email_body preferences: %i[bcc_completed request_email_subject request_email_body
documents_copy_email_subject documents_copy_email_body documents_copy_email_subject documents_copy_email_body
documents_copy_email_enabled documents_copy_email_attach_audit documents_copy_email_enabled documents_copy_email_attach_audit
completed_notification_email_attach_documents
completed_notification_email_subject completed_notification_email_body completed_notification_email_subject completed_notification_email_body
completed_notification_email_enabled completed_notification_email_attach_audit] completed_notification_email_enabled completed_notification_email_attach_audit]
).tap do |attrs| ).tap do |attrs|

@ -48,7 +48,10 @@ class SubmitterMailer < ApplicationMailer
@email_config = AccountConfigs.find_for_account(@current_account, AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY) @email_config = AccountConfigs.find_for_account(@current_account, AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY)
add_completed_email_attachments!( add_completed_email_attachments!(
submitter, with_audit_log: (@email_config.nil? || @email_config.value['attach_audit_log'] != false) && submitter,
with_documents: @email_config&.value&.dig('attach_documents') != false &&
@submitter.template.preferences['completed_notification_email_attach_documents'] != false,
with_audit_log: @email_config&.value&.dig('attach_audit_log') != false &&
@submitter.template.preferences['completed_notification_email_attach_audit'] != false @submitter.template.preferences['completed_notification_email_attach_audit'] != false
) )
@ -117,8 +120,8 @@ class SubmitterMailer < ApplicationMailer
%(#{submitter.submission.template.name} has been completed by #{submitters}) %(#{submitter.submission.template.name} has been completed by #{submitters})
end end
def add_completed_email_attachments!(submitter, with_audit_log: true) def add_completed_email_attachments!(submitter, with_audit_log: true, with_documents: true)
documents = Submitters.select_attachments_for_download(submitter) documents = with_documents ? Submitters.select_attachments_for_download(submitter) : []
total_size = 0 total_size = 0
audit_trail_data = nil audit_trail_data = nil
@ -133,6 +136,7 @@ class SubmitterMailer < ApplicationMailer
attachments[submitter.submission.audit_trail.filename.to_s.tr('"', "'")] = audit_trail_data if audit_trail_data attachments[submitter.submission.audit_trail.filename.to_s.tr('"', "'")] = audit_trail_data if audit_trail_data
if with_documents
file_fields = submitter.submission.template_fields.select { |e| e['type'].in?(%w[file payment]) } file_fields = submitter.submission.template_fields.select { |e| e['type'].in?(%w[file payment]) }
if file_fields.pluck('submitter_uuid').uniq.size == 1 if file_fields.pluck('submitter_uuid').uniq.size == 1
@ -141,6 +145,7 @@ class SubmitterMailer < ApplicationMailer
add_attachments_with_size_limit(storage_attachments, total_size) add_attachments_with_size_limit(storage_attachments, total_size)
end end
end
documents documents
end end

@ -8,7 +8,7 @@
<div class="collapse-content"> <div class="collapse-content">
<%= form_for AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY), url: settings_personalization_path, method: :post, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %> <%= form_for AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY), url: settings_personalization_path, method: :post, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %>
<%= f.hidden_field :key %> <%= f.hidden_field :key %>
<%= f.fields_for :value, Struct.new(:subject, :body, :attach_audit_log).new(*f.object.value.values_at('subject', 'body', 'attach_audit_log')) do |ff| %> <%= f.fields_for :value, Struct.new(:subject, :body, :attach_audit_log, :attach_documents).new(*f.object.value.values_at('subject', 'body', 'attach_audit_log', 'attach_documents')) do |ff| %>
<div class="form-control"> <div class="form-control">
<div class="flex items-center"> <div class="flex items-center">
<%= ff.label :subject, class: 'label' %> <%= ff.label :subject, class: 'label' %>
@ -29,7 +29,13 @@
<%= ff.text_area :body, required: true, class: 'base-input w-full py-2', dir: 'auto' %> <%= ff.text_area :body, required: true, class: 'base-input w-full py-2', dir: 'auto' %>
</autoresize-textarea> </autoresize-textarea>
</div> </div>
<div class="flex items-center justify-between py-2.5 mx-1"> <div class="flex items-center justify-between pt-2.5 mx-1">
<span>
Attach documents
</span>
<%= ff.check_box :attach_documents, { checked: ff.object.attach_documents != false, class: 'toggle' }, 'true', 'false' %>
</div>
<div class="flex items-center justify-between pb-2.5 mx-1">
<span> <span>
Attach audit log PDF Attach audit log PDF
</span> </span>

@ -130,7 +130,7 @@
<%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' } do |f| %> <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' } do |f| %>
<toggle-on-submit data-element-id="email_saved_alert3"></toggle-on-submit> <toggle-on-submit data-element-id="email_saved_alert3"></toggle-on-submit>
<% configs = AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY).value %> <% configs = AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY).value %>
<%= f.fields_for :preferences, Struct.new(:completed_notification_email_subject, :completed_notification_email_body, :completed_notification_email_enabled, :completed_notification_email_attach_audit).new(@template.preferences['completed_notification_email_subject'].presence || configs['subject'], @template.preferences['completed_notification_email_body'].presence || configs['body'], @template.preferences['completed_notification_email_enabled'], configs['attach_audit_log'] != false && @template.preferences['completed_notification_email_attach_audit'] != false) do |ff| %> <%= f.fields_for :preferences, Struct.new(:completed_notification_email_subject, :completed_notification_email_body, :completed_notification_email_enabled, :completed_notification_email_attach_audit, :completed_notification_email_attach_documents).new(@template.preferences['completed_notification_email_subject'].presence || configs['subject'], @template.preferences['completed_notification_email_body'].presence || configs['body'], @template.preferences['completed_notification_email_enabled'], configs['attach_audit_log'] != false && @template.preferences['completed_notification_email_attach_audit'] != false, configs['attach_documents'] != false && @template.preferences['completed_notification_email_attach_documents'] != false) do |ff| %>
<div class="form-control"> <div class="form-control">
<%= ff.label :completed_notification_email_subject, 'Email subject', class: 'label' %> <%= ff.label :completed_notification_email_subject, 'Email subject', class: 'label' %>
<%= ff.text_field :completed_notification_email_subject, required: true, class: 'base-input', dir: 'auto' %> <%= ff.text_field :completed_notification_email_subject, required: true, class: 'base-input', dir: 'auto' %>
@ -148,15 +148,21 @@
</div> </div>
<div class="flex items-center justify-between pt-2.5 px-1 mb-2"> <div class="flex items-center justify-between pt-2.5 px-1 mb-2">
<span> <span>
Attach Audit Log PDF to the email Send emails automatically on completion
</span> </span>
<%= ff.check_box :completed_notification_email_attach_audit, { checked: ff.object.completed_notification_email_attach_audit != false, class: 'toggle', onchange: 'this.form.requestSubmit()', disabled: configs['attach_audit_log'] == false }, 'true', 'false' %> <%= ff.check_box :completed_notification_email_enabled, { checked: ff.object.completed_notification_email_enabled != false, class: 'toggle', onchange: 'this.form.requestSubmit()' }, 'true', 'false' %>
</div>
<div class="flex items-center justify-between pt-2.5 px-1 mb-2">
<span>
Attach documents to the email
</span>
<%= ff.check_box :completed_notification_email_attach_documents, { checked: ff.object.completed_notification_email_attach_documents != false, class: 'toggle', onchange: 'this.form.requestSubmit()', disabled: configs['attach_documents'] == false }, 'true', 'false' %>
</div> </div>
<div class="flex items-center justify-between py-2.5 px-1 mb-2"> <div class="flex items-center justify-between py-2.5 px-1 mb-2">
<span> <span>
Send emails automatically on completion Attach Audit Log PDF to the email
</span> </span>
<%= ff.check_box :completed_notification_email_enabled, { checked: ff.object.completed_notification_email_enabled != false, class: 'toggle', onchange: 'this.form.requestSubmit()' }, 'true', 'false' %> <%= ff.check_box :completed_notification_email_attach_audit, { checked: ff.object.completed_notification_email_attach_audit != false, class: 'toggle', onchange: 'this.form.requestSubmit()', disabled: configs['attach_audit_log'] == false }, 'true', 'false' %>
</div> </div>
<% end %> <% end %>
<div class="form-control pt-2"> <div class="form-control pt-2">

Loading…
Cancel
Save