adjust tempalte preferences
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<%= f.label :value, class: 'label' do %>
|
||||
<span class="flex items-center space-x-1">
|
||||
<span>
|
||||
Completed documents BCC address
|
||||
Completed documents notification BCC address
|
||||
</span>
|
||||
<span class="tooltip" data-tip="Send email copy with completed documents to a specified BCC address.">
|
||||
<%= svg_icon('info_circle', class: 'w-4 h-4') %>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<input type="checkbox">
|
||||
<div class="collapse-title text-xl font-medium">
|
||||
<div>
|
||||
Form Completed Email
|
||||
Completed Notification Email
|
||||
</div>
|
||||
</div>
|
||||
<div class="collapse-content">
|
||||
|
||||
@@ -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 %>
|
||||
<p>Hi there,</p>
|
||||
<p>"<%= @submitter.submission.template.name %>" form has been completed by <%= @submitter.submission.submitters.order(:completed_at).map { |e| e.name || e.email || e.phone }.join(', ') %>.</p>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<%= ff.label :bcc_completed, class: 'label' do %>
|
||||
<span class="flex items-center space-x-1 justify-between w-full">
|
||||
<span>
|
||||
Completed documents BCC address
|
||||
Completed documents notification BCC address
|
||||
</span>
|
||||
</span>
|
||||
<% end %>
|
||||
@@ -82,7 +82,8 @@
|
||||
<div class="collapse-content">
|
||||
<%= 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_alert2"></toggle-on-submit>
|
||||
<%= 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| %>
|
||||
<div class="form-control">
|
||||
<%= 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' %>
|
||||
</autoresize-textarea>
|
||||
</div>
|
||||
<div class="flex items-center justify-between pt-2.5 px-1 mb-2">
|
||||
<span>
|
||||
Attach Audit Log PDF to the email
|
||||
</span>
|
||||
<%= 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' %>
|
||||
</div>
|
||||
<div class="flex items-center justify-between py-2.5 px-1 mb-2">
|
||||
<span>
|
||||
Send emails automatically on completion
|
||||
@@ -114,6 +121,53 @@
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="collapse collapse-arrow join-item border border-base-300">
|
||||
<input type="checkbox" name="accordion">
|
||||
<div class="collapse-title text-xl font-medium">
|
||||
Completed notification email
|
||||
</div>
|
||||
<div class="collapse-content">
|
||||
<%= 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>
|
||||
<% 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| %>
|
||||
<div class="form-control">
|
||||
<%= ff.label :completed_notification_email_subject, 'Email subject', class: 'label' %>
|
||||
<%= ff.text_field :completed_notification_email_subject, required: true, class: 'base-input', dir: 'auto' %>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<div class="flex items-center">
|
||||
<%= ff.label :completed_notification_email_body, 'Email body', class: 'label' %>
|
||||
<span class="tooltip tooltip-right" data-tip="Use following placeholders text: <%= AccountConfig::DEFAULT_VALUES.dig(AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY, 'body').scan(/{{.*?}}/).join(', ') %>">
|
||||
<%= svg_icon('info_circle', class: 'w-4 h-4') %>
|
||||
</span>
|
||||
</div>
|
||||
<autoresize-textarea>
|
||||
<%= ff.text_area :completed_notification_email_body, required: true, class: 'base-input w-full py-2', dir: 'auto' %>
|
||||
</autoresize-textarea>
|
||||
</div>
|
||||
<div class="flex items-center justify-between pt-2.5 px-1 mb-2">
|
||||
<span>
|
||||
Attach Audit Log PDF to the email
|
||||
</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' %>
|
||||
</div>
|
||||
<div class="flex items-center justify-between py-2.5 px-1 mb-2">
|
||||
<span>
|
||||
Send emails automatically on completion
|
||||
</span>
|
||||
<%= ff.check_box :completed_notification_email_enabled, { checked: ff.object.completed_notification_email_enabled != false, class: 'toggle', onchange: 'this.form.requestSubmit()' }, 'true', 'false' %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="form-control pt-2">
|
||||
<%= f.button button_title(title: 'Save', disabled_with: 'Saving'), class: 'base-button' %>
|
||||
<div class="flex justify-center">
|
||||
<span id="email_saved_alert3" class="text-sm invisible font-normal mt-0.5">Changes have been saved</span>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% if show_api %>
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user