diff --git a/app/controllers/templates_preferences_controller.rb b/app/controllers/templates_preferences_controller.rb index a2da8f63..7eecc555 100644 --- a/app/controllers/templates_preferences_controller.rb +++ b/app/controllers/templates_preferences_controller.rb @@ -21,7 +21,9 @@ class TemplatesPreferencesController < ApplicationController params.require(:template).permit( 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_enabled documents_copy_email_attach_audit + completed_notification_email_subject completed_notification_email_body + completed_notification_email_enabled completed_notification_email_attach_audit] ).tap do |attrs| attrs[:preferences] = attrs[:preferences].transform_values do |value| if %w[true false].include?(value) diff --git a/app/jobs/process_submitter_completion_job.rb b/app/jobs/process_submitter_completion_job.rb index 7583a8f8..f9697218 100644 --- a/app/jobs/process_submitter_completion_job.rb +++ b/app/jobs/process_submitter_completion_job.rb @@ -26,7 +26,8 @@ class ProcessSubmitterCompletionJob < ApplicationJob user = submission.created_by_user || submitter.template.author - if submitter.account.users.exists?(id: user.id) && submission.preferences['send_email'] != false + if submitter.account.users.exists?(id: user.id) && submission.preferences['send_email'] != false && + submitter.template.preferences['completed_notification_email_enabled'] != false if submission.submitters.map(&:email).exclude?(user.email) && user.user_configs.find_by(key: UserConfig::RECEIVE_COMPLETED_EMAIL)&.value != false && user.role != 'integration' diff --git a/app/mailers/submitter_mailer.rb b/app/mailers/submitter_mailer.rb index b95fea9f..3802425a 100644 --- a/app/mailers/submitter_mailer.rb +++ b/app/mailers/submitter_mailer.rb @@ -48,16 +48,21 @@ 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, with_audit_log: (@email_config.nil? || @email_config.value['attach_audit_log'] != false) && + @submitter.template.preferences['completed_notification_email_attach_audit'] != false ) + @subject = @submitter.template.preferences['completed_notification_email_subject'].presence + @subject ||= @email_config.value['subject'] if @email_config + + @body = @submitter.template.preferences['completed_notification_email_body'].presence + @body ||= @email_config.value['body'] if @email_config + subject = - if @email_config - ReplaceEmailVariables.call(@email_config.value['subject'], submitter:) + if @subject.present? + ReplaceEmailVariables.call(@subject, submitter:) else - submitters = submitter.submission.submitters.order(:completed_at) - .map { |e| e.name || e.email || e.phone }.join(', ') - %(#{submitter.submission.template.name} has been completed by #{submitters}) + build_completed_subject(submitter) end assign_message_metadata('submitter_completed', @submitter) @@ -77,7 +82,8 @@ class SubmitterMailer < ApplicationMailer @email_config = AccountConfigs.find_for_account(@current_account, AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY) @documents = add_completed_email_attachments!( - submitter, with_audit_log: @email_config.nil? || @email_config.value['attach_audit_log'] != false + submitter, with_audit_log: @submitter.template.preferences['documents_copy_email_attach_audit'] != false && + (@email_config.nil? || @email_config.value['attach_audit_log'] != false) ) @subject = @submitter.template.preferences['documents_copy_email_subject'].presence @@ -105,6 +111,12 @@ class SubmitterMailer < ApplicationMailer private + def build_completed_subject(submitter) + submitters = submitter.submission.submitters.order(:completed_at) + .map { |e| e.name || e.email || e.phone }.join(', ') + %(#{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) diff --git a/app/views/notifications_settings/_bcc_form.html.erb b/app/views/notifications_settings/_bcc_form.html.erb index 98f4301c..2fae007f 100644 --- a/app/views/notifications_settings/_bcc_form.html.erb +++ b/app/views/notifications_settings/_bcc_form.html.erb @@ -4,7 +4,7 @@ <%= f.label :value, class: 'label' do %> - Completed documents BCC address + Completed documents notification BCC address <%= svg_icon('info_circle', class: 'w-4 h-4') %> 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 e86189cf..f6805366 100644 --- a/app/views/personalization_settings/_submitter_completed_email_form.html.erb +++ b/app/views/personalization_settings/_submitter_completed_email_form.html.erb @@ -2,7 +2,7 @@
- Form Completed Email + Completed Notification Email
diff --git a/app/views/submitter_mailer/completed_email.html.erb b/app/views/submitter_mailer/completed_email.html.erb index 00dacf26..aa4d0085 100644 --- a/app/views/submitter_mailer/completed_email.html.erb +++ b/app/views/submitter_mailer/completed_email.html.erb @@ -1,5 +1,5 @@ -<% if @email_config %> - <%= render 'custom_content', content: @email_config.value['body'], submitter: @submitter %> +<% if @body.present? %> + <%= render 'custom_content', content: @body, submitter: @submitter %> <% else %>

Hi there,

"<%= @submitter.submission.template.name %>" form has been completed by <%= @submitter.submission.submitters.order(:completed_at).map { |e| e.name || e.email || e.phone }.join(', ') %>.

diff --git a/app/views/templates_preferences/show.html.erb b/app/views/templates_preferences/show.html.erb index fd68ca8a..90d62d9b 100644 --- a/app/views/templates_preferences/show.html.erb +++ b/app/views/templates_preferences/show.html.erb @@ -24,7 +24,7 @@ <%= ff.label :bcc_completed, class: 'label' do %> - Completed documents BCC address + Completed documents notification BCC address <% end %> @@ -82,7 +82,8 @@
<%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' } do |f| %> - <%= f.fields_for :preferences, Struct.new(:documents_copy_email_subject, :documents_copy_email_body, :documents_copy_email_enabled).new(*(@template.preferences.values_at('documents_copy_email_subject', 'documents_copy_email_body').compact_blank.presence || AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY).value.values_at('subject', 'body')), @template.preferences['documents_copy_email_enabled']) do |ff| %> + <% configs = AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY).value %> + <%= f.fields_for :preferences, Struct.new(:documents_copy_email_subject, :documents_copy_email_body, :documents_copy_email_enabled, :documents_copy_email_attach_audit).new(@template.preferences['documents_copy_email_subject'].presence || configs['subject'], @template.preferences['documents_copy_email_body'].presence || configs['body'], @template.preferences['documents_copy_email_enabled'], configs['attach_audit_log'] != false && @template.preferences['documents_copy_email_attach_audit'] != false) do |ff| %>
<%= ff.label :documents_copy_email_subject, 'Email subject', class: 'label' %> <%= ff.text_field :documents_copy_email_subject, required: true, class: 'base-input', dir: 'auto' %> @@ -98,6 +99,12 @@ <%= ff.text_area :documents_copy_email_body, required: true, class: 'base-input w-full py-2', dir: 'auto' %>
+
+ + Attach Audit Log PDF to the email + + <%= ff.check_box :documents_copy_email_attach_audit, { checked: ff.object.documents_copy_email_attach_audit != false, class: 'toggle', onchange: 'this.form.requestSubmit()', disabled: configs['attach_audit_log'] == false }, 'true', 'false' %> +
Send emails automatically on completion @@ -114,6 +121,53 @@ <% end %>
+
+ +
+ Completed notification email +
+
+ <%= 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| %> +
+ <%= 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.label :completed_notification_email_body, 'Email body', class: 'label' %> + + <%= svg_icon('info_circle', class: 'w-4 h-4') %> + +
+ + <%= ff.text_area :completed_notification_email_body, required: true, class: 'base-input w-full py-2', dir: 'auto' %> + +
+
+ + Attach Audit Log PDF to the email + + <%= 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' %> +
+
+ + Send emails automatically on completion + + <%= ff.check_box :completed_notification_email_enabled, { checked: ff.object.completed_notification_email_enabled != false, class: 'toggle', onchange: 'this.form.requestSubmit()' }, 'true', 'false' %> +
+ <% end %> +
+ <%= f.button button_title(title: 'Save', disabled_with: 'Saving'), class: 'base-button' %> +
+ +
+
+ <% end %> +
+
<% if show_api %> diff --git a/spec/system/personalization_spec.rb b/spec/system/personalization_spec.rb index 0fee68e0..d5e4f113 100644 --- a/spec/system/personalization_spec.rb +++ b/spec/system/personalization_spec.rb @@ -14,7 +14,7 @@ RSpec.describe 'Personalization' do it 'shows the personalization page' do expect(page).to have_content('Email Templates') expect(page).to have_content('Signature Request Email') - expect(page).to have_content('Form Completed Email') + expect(page).to have_content('Completed Notification Email') expect(page).to have_content('Documents Copy Email') expect(page).to have_content('Company Logo') expect(page).to have_content('Unlock with DocuSeal Pro')