diff --git a/app/jobs/process_submitter_completion_job.rb b/app/jobs/process_submitter_completion_job.rb index 231a98d2..9c3a4b26 100644 --- a/app/jobs/process_submitter_completion_job.rb +++ b/app/jobs/process_submitter_completion_job.rb @@ -94,11 +94,27 @@ class ProcessSubmitterCompletionJob end end - to = build_to_addresses(submitter) + maybe_enqueue_copy_emails(submitter) + end + + def maybe_enqueue_copy_emails(submitter) + return if submitter.template.preferences['documents_copy_email_enabled'] == false + + configs = AccountConfigs.find_or_initialize_for_key(submitter.account, + AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY) + + return if configs.value['enabled'] == false - return if to.blank? || submitter.template.preferences['documents_copy_email_enabled'] == false + to = submitter.submission.submitters.reject { |e| e.preferences['send_email'] == false } + .sort_by(&:completed_at).select(&:email?).map(&:friendly_name) - SubmitterMailer.documents_copy_email(submitter, to:).deliver_later! + return if to.blank? + + if configs.value['bcc_recipients'] == true + to.each { |to| SubmitterMailer.documents_copy_email(submitter, to:).deliver_later! } + else + SubmitterMailer.documents_copy_email(submitter, to: to.join(', ')).deliver_later! + end end def build_bcc_addresses(submission) @@ -110,11 +126,6 @@ class ProcessSubmitterCompletionJob bcc.to_s.scan(User::EMAIL_REGEXP) end - def build_to_addresses(submitter) - submitter.submission.submitters.reject { |e| e.preferences['send_email'] == false } - .sort_by(&:completed_at).select(&:email?).map(&:friendly_name).join(', ') - end - def enqueue_next_submitter_request_notification(submitter) next_submitter_item = submitter.submission.template_submitters.find do |e| diff --git a/app/views/personalization_settings/_documents_copy_email_form.html.erb b/app/views/personalization_settings/_documents_copy_email_form.html.erb index fcb3b18a..c5af6c49 100644 --- a/app/views/personalization_settings/_documents_copy_email_form.html.erb +++ b/app/views/personalization_settings/_documents_copy_email_form.html.erb @@ -8,7 +8,7 @@
<%= form_for AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_DOCUMENTS_COPY_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, :reply_to, :attach_audit_log, :attach_documents).new(*f.object.value.values_at('subject', 'body', 'reply_to', 'attach_audit_log', 'attach_documents')) do |ff| %> + <%= f.fields_for :value, Struct.new(:subject, :body, :reply_to, :attach_audit_log, :attach_documents, :bcc_recipients, :enabled).new(*f.object.value.values_at('subject', 'body', 'reply_to', 'attach_audit_log', 'attach_documents', 'bcc_recipients', 'enabled')) do |ff| %>
<%= ff.label :subject, t('subject'), class: 'label' %> <%= ff.text_field :subject, required: true, class: 'base-input', dir: 'auto' %> @@ -24,23 +24,41 @@ <%= ff.text_area :body, required: true, class: 'base-input w-full py-2', dir: 'auto' %>
- <% if can?(:manage, :reply_to) %> + <% if can?(:manage, :reply_to) || can?(:manage, :personalization_advanced) %>
<%= ff.label :reply_to, t('reply_to'), class: 'label' %> <%= ff.email_field :reply_to, class: 'base-input', dir: 'auto', placeholder: t(:email) %>
<% end %> -
- - <%= t('attach_documents') %> - - <%= ff.check_box :attach_documents, { checked: ff.object.attach_documents != false, class: 'toggle' }, 'true', 'false' %> -
-
- - <%= t('attach_audit_log_pdf') %> - - <%= ff.check_box :attach_audit_log, { checked: ff.object.attach_audit_log != false, class: 'toggle' }, 'true', 'false' %> +
+
+ + <%= t('attach_documents') %> + + <%= ff.check_box :attach_documents, { checked: ff.object.attach_documents != false, class: 'toggle' }, 'true', 'false' %> +
+
+ + <%= t('attach_audit_log_pdf') %> + + <%= ff.check_box :attach_audit_log, { checked: ff.object.attach_audit_log != false, class: 'toggle' }, 'true', 'false' %> +
+ <% unless Docuseal.multitenant? %> +
+ + <%= t('bcc_recipients') %> + + <%= ff.check_box :bcc_recipients, { checked: ff.object.bcc_recipients == true, class: 'toggle' }, 'true', 'false' %> +
+ <% end %> + <% if !Docuseal.multitenant? || can?(:manage, :personalization_advanced) %> +
+ + <%= t('send_emails_automatically_on_completion') %> + + <%= ff.check_box :enabled, { checked: ff.object.enabled != false, class: 'toggle' }, 'true', 'false' %> +
+ <% end %>
<% end %>
diff --git a/app/views/templates_preferences/show.html.erb b/app/views/templates_preferences/show.html.erb index 12c020b1..db878d70 100644 --- a/app/views/templates_preferences/show.html.erb +++ b/app/views/templates_preferences/show.html.erb @@ -206,7 +206,7 @@ <%= t('send_emails_automatically_on_completion') %> - <%= ff.check_box :documents_copy_email_enabled, { checked: ff.object.documents_copy_email_enabled != false, class: 'toggle', onchange: 'this.form.requestSubmit()' }, 'true', 'false' %> + <%= ff.check_box :documents_copy_email_enabled, { checked: ff.object.documents_copy_email_enabled != false && configs['enabled'] != false, class: 'toggle', onchange: 'this.form.requestSubmit()', disabled: configs['enabled'] == false }, 'true', 'false' %>
<% end %>
diff --git a/config/locales/i18n.yml b/config/locales/i18n.yml index 2bd3c902..4a979547 100644 --- a/config/locales/i18n.yml +++ b/config/locales/i18n.yml @@ -20,6 +20,7 @@ en: &en language_ko: 한국어 hi_there: Hi there thanks: Thanks + bcc_recipients: BCC recipients edit_per_party: Edit per party reply_to: Reply to pending_by_me: Pending by me @@ -745,6 +746,7 @@ en: &en read: Read your data es: &es + bcc_recipients: Destinatarios CCO edit_per_party: Editar por parte signed: Firmado reply_to: Responder a @@ -1472,6 +1474,7 @@ es: &es read: Leer tus datos it: &it + bcc_recipients: Destinatari BCC edit_per_party: Modifica per partito signed: Firmato reply_to: Rispondi a @@ -2198,6 +2201,7 @@ it: &it read: Leggi i tuoi dati fr: &fr + bcc_recipients: Destinataires en CCI edit_per_party: Éditer par partie signed: Signé reply_to: Répondre à @@ -2926,6 +2930,7 @@ fr: &fr read: Lire vos données pt: &pt + bcc_recipients: Destinatários BCC edit_per_party: Edita por festa signed: Assinado reply_to: Responder a @@ -3653,6 +3658,7 @@ pt: &pt read: Ler seus dados de: &de + bcc_recipients: BCC-Empfänger edit_per_party: Bearbeiten pro Partei signed: Unterschrieben reply_to: Antworten auf