diff --git a/app/controllers/templates_preferences_controller.rb b/app/controllers/templates_preferences_controller.rb index 7eecc555..ca21a52e 100644 --- a/app/controllers/templates_preferences_controller.rb +++ b/app/controllers/templates_preferences_controller.rb @@ -22,6 +22,7 @@ class TemplatesPreferencesController < ApplicationController preferences: %i[bcc_completed request_email_subject request_email_body documents_copy_email_subject documents_copy_email_body 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_enabled completed_notification_email_attach_audit] ).tap do |attrs| diff --git a/app/mailers/submitter_mailer.rb b/app/mailers/submitter_mailer.rb index 3802425a..8f83dc5f 100644 --- a/app/mailers/submitter_mailer.rb +++ b/app/mailers/submitter_mailer.rb @@ -48,8 +48,11 @@ class SubmitterMailer < ApplicationMailer @email_config = AccountConfigs.find_for_account(@current_account, AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY) add_completed_email_attachments!( - submitter, with_audit_log: (@email_config.nil? || @email_config.value['attach_audit_log'] != false) && - @submitter.template.preferences['completed_notification_email_attach_audit'] != 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 ) @subject = @submitter.template.preferences['completed_notification_email_subject'].presence @@ -117,8 +120,8 @@ class SubmitterMailer < ApplicationMailer %(#{submitter.submission.template.name} has been completed by #{submitters}) end - def add_completed_email_attachments!(submitter, with_audit_log: true) - documents = Submitters.select_attachments_for_download(submitter) + def add_completed_email_attachments!(submitter, with_audit_log: true, with_documents: true) + documents = with_documents ? Submitters.select_attachments_for_download(submitter) : [] total_size = 0 audit_trail_data = nil @@ -133,13 +136,15 @@ class SubmitterMailer < ApplicationMailer attachments[submitter.submission.audit_trail.filename.to_s.tr('"', "'")] = audit_trail_data if audit_trail_data - file_fields = submitter.submission.template_fields.select { |e| e['type'].in?(%w[file payment]) } + if with_documents + file_fields = submitter.submission.template_fields.select { |e| e['type'].in?(%w[file payment]) } - if file_fields.pluck('submitter_uuid').uniq.size == 1 - storage_attachments = - submitter.attachments.where(uuid: submitter.values.values_at(*file_fields.pluck('uuid')).flatten) + if file_fields.pluck('submitter_uuid').uniq.size == 1 + storage_attachments = + submitter.attachments.where(uuid: submitter.values.values_at(*file_fields.pluck('uuid')).flatten) - add_attachments_with_size_limit(storage_attachments, total_size) + add_attachments_with_size_limit(storage_attachments, total_size) + end end documents diff --git a/app/views/personalization_settings/_submitter_completed_email_form.html.erb b/app/views/personalization_settings/_submitter_completed_email_form.html.erb index f6805366..674c1009 100644 --- a/app/views/personalization_settings/_submitter_completed_email_form.html.erb +++ b/app/views/personalization_settings/_submitter_completed_email_form.html.erb @@ -8,7 +8,7 @@
<%= 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.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| %>
<%= ff.label :subject, class: 'label' %> @@ -29,7 +29,13 @@ <%= ff.text_area :body, required: true, class: 'base-input w-full py-2', dir: 'auto' %>
-
+
+ + Attach documents + + <%= ff.check_box :attach_documents, { checked: ff.object.attach_documents != false, class: 'toggle' }, 'true', 'false' %> +
+
Attach audit log PDF diff --git a/app/views/templates_preferences/show.html.erb b/app/views/templates_preferences/show.html.erb index 90d62d9b..2b897653 100644 --- a/app/views/templates_preferences/show.html.erb +++ b/app/views/templates_preferences/show.html.erb @@ -130,7 +130,7 @@ <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' } do |f| %> <% 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| %>
<%= ff.label :completed_notification_email_subject, 'Email subject', class: 'label' %> <%= ff.text_field :completed_notification_email_subject, required: true, class: 'base-input', dir: 'auto' %> @@ -148,15 +148,21 @@
- Attach Audit Log PDF to the email + Send emails automatically on completion - <%= 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' %> +
+
+ + Attach documents to the email + + <%= 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' %>
- Send emails automatically on completion + Attach Audit Log PDF to the email - <%= 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' %>
<% end %>