From 6c73c82a2740cc82b4ebeabb4460fc04951fcf59 Mon Sep 17 00:00:00 2001 From: Alex Turchyn Date: Fri, 7 Nov 2025 22:05:49 +0200 Subject: [PATCH] add ability to reset custom template emails to default --- .../templates_preferences_controller.rb | 26 +++ .../_submitter_completed_email_form.html.erb | 66 ++++++ ...bmitter_documents_copy_email_form.html.erb | 72 +++++++ .../_submitter_invitation_email_form.html.erb | 108 ++++++++++ app/views/templates_preferences/show.html.erb | 203 +----------------- config/locales/i18n.yml | 14 ++ config/routes.rb | 2 +- 7 files changed, 293 insertions(+), 198 deletions(-) create mode 100644 app/views/templates_preferences/_submitter_completed_email_form.html.erb create mode 100644 app/views/templates_preferences/_submitter_documents_copy_email_form.html.erb create mode 100644 app/views/templates_preferences/_submitter_invitation_email_form.html.erb diff --git a/app/controllers/templates_preferences_controller.rb b/app/controllers/templates_preferences_controller.rb index cbee0993..47e1a562 100644 --- a/app/controllers/templates_preferences_controller.rb +++ b/app/controllers/templates_preferences_controller.rb @@ -3,6 +3,13 @@ class TemplatesPreferencesController < ApplicationController load_and_authorize_resource :template + RESETTABLE_PREFERENCE_KEYS = { + AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY => %w[request_email_subject request_email_body submitters], + AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY => %w[documents_copy_email_subject documents_copy_email_body], + AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY => %w[completed_notification_email_subject + completed_notification_email_body] + }.freeze + def show; end def create @@ -15,6 +22,25 @@ class TemplatesPreferencesController < ApplicationController head :ok end + def destroy + authorize!(:update, @template) + + config_key = params[:config_key] + preferences_to_delete = RESETTABLE_PREFERENCE_KEYS[config_key] || [] + + return head :ok if preferences_to_delete.blank? + + preferences_to_delete.each do |key| + @template.preferences.delete(key) + end + + @template.save! + + render turbo_stream: turbo_stream.replace("#{config_key}_form", + partial: "templates_preferences/#{config_key}_form"), + status: :ok + end + private def template_params diff --git a/app/views/templates_preferences/_submitter_completed_email_form.html.erb b/app/views/templates_preferences/_submitter_completed_email_form.html.erb new file mode 100644 index 00000000..74626f79 --- /dev/null +++ b/app/views/templates_preferences/_submitter_completed_email_form.html.erb @@ -0,0 +1,66 @@ +
+ <% configs = AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY).value %> + <% template_email_preferences_values = @template.preferences.values_at('completed_notification_email_subject', 'completed_notification_email_body').compact_blank.presence %> + <% is_custom_template_email = template_email_preferences_values.present? %> + <% if is_custom_template_email %> + <%= button_to nil, template_preferences_path(@template), id: 'submitter_completed_email_reset_link', method: :delete, class: 'hidden', params: { config_key: AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY }, data: { turbo_confirm: t('are_you_sure_') }, form: { data: { close_on_submit: false } } %> + <% end %> + <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' }, data: { close_on_submit: false } do |f| %> + + <%= f.hidden_field :config_key, value: AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY %> + <%= 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, t('email_subject'), class: 'label' %> + <% if is_custom_template_email %> + + <% end %> +
+ <%= ff.text_field :completed_notification_email_subject, required: true, class: 'base-input', dir: 'auto' %> +
+
+
+ <%= ff.label :completed_notification_email_body, t('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' %> + +
+
+ + <%= t('attach_documents_to_the_email') %> + + + <%= ff.check_box :completed_notification_email_attach_documents, { checked: ff.object.completed_notification_email_attach_documents != false, class: 'toggle', disabled: configs['attach_documents'] == false }, 'true', 'false' %> + +
+
+ + <%= t('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', disabled: configs['attach_audit_log'] == false }, 'true', 'false' %> + +
+
+ + <%= t('send_emails_automatically_on_completion') %> + + + <%= ff.check_box :completed_notification_email_enabled, { checked: ff.object.completed_notification_email_enabled != false, class: 'toggle', disabled: configs['enabled'] == false }, 'true', 'false' %> + +
+ <% end %> +
+ <%= f.button button_title(title: t('save'), disabled_with: t('saving')), class: 'base-button' %> +
+ +
+
+ <% end %> +
diff --git a/app/views/templates_preferences/_submitter_documents_copy_email_form.html.erb b/app/views/templates_preferences/_submitter_documents_copy_email_form.html.erb new file mode 100644 index 00000000..0ce23e59 --- /dev/null +++ b/app/views/templates_preferences/_submitter_documents_copy_email_form.html.erb @@ -0,0 +1,72 @@ +
+ <% configs = AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY).value %> + <% template_email_preferences_values = @template.preferences.values_at('documents_copy_email_subject', 'documents_copy_email_body').compact_blank.presence %> + <% is_custom_template_email = template_email_preferences_values.present? %> + <% if is_custom_template_email %> + <%= button_to nil, template_preferences_path(@template), id: 'submitter_documents_copy_email_reset_link', method: :delete, class: 'hidden', params: { config_key: AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY }, data: { turbo_confirm: t('are_you_sure_') }, form: { data: { close_on_submit: false } } %> + <% end %> + <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' }, data: { close_on_submit: false } do |f| %> + + <%= f.hidden_field :config_key, value: AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY %> + <%= f.fields_for :preferences, Struct.new(:documents_copy_email_reply_to, :documents_copy_email_subject, :documents_copy_email_body, :documents_copy_email_enabled, :documents_copy_email_attach_audit, :documents_copy_email_attach_documents).new(@template.preferences['documents_copy_email_reply_to'].presence || configs['reply_to'], @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, configs['attach_documents'] != false && @template.preferences['documents_copy_email_attach_documents'] != false) do |ff| %> +
+
+ <%= ff.label :documents_copy_email_subject, t('email_subject'), class: 'label' %> + <% if is_custom_template_email %> + + <% end %> +
+ <%= ff.text_field :documents_copy_email_subject, required: true, class: 'base-input', dir: 'auto' %> +
+
+
+ <%= ff.label :documents_copy_email_body, t('email_body'), class: 'label' %> + + <%= svg_icon('info_circle', class: 'w-4 h-4') %> + +
+ + <%= ff.text_area :documents_copy_email_body, required: true, class: 'base-input w-full py-2', dir: 'auto' %> + +
+ <% if can?(:manage, :reply_to) %> +
+ <%= ff.label :documents_copy_email_reply_to, t('reply_to'), class: 'label' %> + <%= ff.email_field :documents_copy_email_reply_to, class: 'base-input', dir: 'auto', placeholder: t(:email) %> +
+ <% end %> +
+ + <%= t('attach_documents_to_the_email') %> + + + <%= ff.check_box :documents_copy_email_attach_documents, { checked: ff.object.documents_copy_email_attach_documents != false, class: 'toggle', disabled: configs['attach_documents'] == false }, 'true', 'false' %> + +
+
+ + <%= t('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', disabled: configs['attach_audit_log'] == false }, 'true', 'false' %> + +
+
+ + <%= t('send_emails_automatically_on_completion') %> + + + <%= ff.check_box :documents_copy_email_enabled, { checked: ff.object.documents_copy_email_enabled != false && configs['enabled'] != false, class: 'toggle', disabled: configs['enabled'] == false }, 'true', 'false' %> + +
+ <% end %> +
+ <%= f.button button_title(title: t('save'), disabled_with: t('saving')), class: 'base-button' %> +
+ +
+
+ <% end %> +
diff --git a/app/views/templates_preferences/_submitter_invitation_email_form.html.erb b/app/views/templates_preferences/_submitter_invitation_email_form.html.erb new file mode 100644 index 00000000..6f6118d6 --- /dev/null +++ b/app/views/templates_preferences/_submitter_invitation_email_form.html.erb @@ -0,0 +1,108 @@ +
+ <% template_email_preferences_values = @template.preferences.values_at('request_email_subject', 'request_email_body').compact_blank %> + <% default_template_email_preferences_values = AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY).value.values_at('subject', 'body') %> + <% is_custom_template_email = template_email_preferences_values.present? %> + <% multiple_submitters = @template.submitters.size > 1 && @template.submitters.size < 5 %> + <% if is_custom_template_email || @template.preferences['submitters'].to_a.any? %> + <%= button_to nil, template_preferences_path(@template), id: 'submitter_invitation_email_reset_link', method: :delete, class: 'hidden', params: { config_key: AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY }, data: { turbo_confirm: t('are_you_sure_') }, form: { data: { close_on_submit: false } } %> + <% end %> + <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' }, data: { close_on_submit: false } do |f| %> + + <%= f.hidden_field :config_key, value: AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY %> + <%= tag.input id: 'request_email_per_submitter', value: '1', name: 'request_email_per_submitter', class: 'peer', type: 'checkbox', hidden: true, checked: @template.preferences['submitters'].to_a.size > 1 %> +
+ <%= f.fields_for :preferences, Struct.new(:request_email_subject, :request_email_body).new(*(template_email_preferences_values.presence || default_template_email_preferences_values)) do |ff| %> +
+
+ <%= ff.label :request_email_subject, t('email_subject'), class: 'label' %> + <% if is_custom_template_email %> + + <% elsif multiple_submitters %> + + <% end %> +
+ <%= ff.text_field :request_email_subject, required: true, class: 'base-input', dir: 'auto' %> +
+
+
+ <%= ff.label :request_email_body, t('email_body'), class: 'label' %> + + <%= svg_icon('info_circle', class: 'w-4 h-4') %> + +
+ + <%= ff.text_area :request_email_body, required: true, class: 'base-input w-full py-2', dir: 'auto' %> + +
+ <% end %> +
+ <% if multiple_submitters %> + + <% end %> + <%= f.fields_for :preferences, Struct.new(:request_email_enabled).new(@template.preferences['request_email_enabled']) do |ff| %> +
+ + <%= t('send_signature_request_email') %> + + + <%= ff.check_box :request_email_enabled, { checked: ff.object.request_email_enabled != false, class: 'toggle' }, 'true', 'false' %> + +
+ <% end %> +
+ <%= f.button button_title(title: t('save'), disabled_with: t('saving')), class: 'base-button' %> +
+ +
+
+ <% end %> +
diff --git a/app/views/templates_preferences/show.html.erb b/app/views/templates_preferences/show.html.erb index 54f8d83f..71c0f7e4 100644 --- a/app/views/templates_preferences/show.html.erb +++ b/app/views/templates_preferences/show.html.erb @@ -98,92 +98,7 @@ <%= t('signature_request_email') %>
- <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' }, data: { close_on_submit: false } do |f| %> - - <%= tag.input id: 'request_email_per_submitter', value: '1', name: 'request_email_per_submitter', class: 'peer', type: 'checkbox', hidden: true, checked: @template.preferences['submitters'].to_a.size > 1 %> -
- <%= f.fields_for :preferences, Struct.new(:request_email_subject, :request_email_body).new(*(@template.preferences.values_at('request_email_subject', 'request_email_body').compact_blank.presence || AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY).value.values_at('subject', 'body'))) do |ff| %> -
-
- <%= ff.label :request_email_subject, t('email_subject'), class: 'label' %> - <% if @template.submitters.size > 1 && @template.submitters.size < 5 %> - - <% end %> -
- <%= ff.text_field :request_email_subject, required: true, class: 'base-input', dir: 'auto' %> -
-
-
- <%= ff.label :request_email_body, t('email_body'), class: 'label' %> - - <%= svg_icon('info_circle', class: 'w-4 h-4') %> - -
- - <%= ff.text_area :request_email_body, required: true, class: 'base-input w-full py-2', dir: 'auto' %> - -
- <% end %> -
- <% if @template.submitters.size > 1 && @template.submitters.size < 5 %> - - <% end %> - <%= f.fields_for :preferences, Struct.new(:request_email_enabled).new(@template.preferences['request_email_enabled']) do |ff| %> -
- - <%= 'Send signature request email' %> - - - <%= ff.check_box :request_email_enabled, { checked: ff.object.request_email_enabled != false, class: 'toggle' }, 'true', 'false' %> - -
- <% end %> -
- <%= f.button button_title(title: t('save'), disabled_with: t('saving')), class: 'base-button' %> -
- -
-
- <% end %> + <%= render 'templates_preferences/submitter_invitation_email_form' %>
@@ -192,63 +107,7 @@ <%= t('documents_copy_email') %>
- <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' }, data: { close_on_submit: false } do |f| %> - - <% 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_reply_to, :documents_copy_email_subject, :documents_copy_email_body, :documents_copy_email_enabled, :documents_copy_email_attach_audit, :documents_copy_email_attach_documents).new(@template.preferences['documents_copy_email_reply_to'].presence || configs['reply_to'], @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, configs['attach_documents'] != false && @template.preferences['documents_copy_email_attach_documents'] != false) do |ff| %> -
- <%= ff.label :documents_copy_email_subject, t('email_subject'), class: 'label' %> - <%= ff.text_field :documents_copy_email_subject, required: true, class: 'base-input', dir: 'auto' %> -
-
-
- <%= ff.label :documents_copy_email_body, t('email_body'), class: 'label' %> - - <%= svg_icon('info_circle', class: 'w-4 h-4') %> - -
- - <%= ff.text_area :documents_copy_email_body, required: true, class: 'base-input w-full py-2', dir: 'auto' %> - -
- <% if can?(:manage, :reply_to) %> -
- <%= ff.label :documents_copy_email_reply_to, t('reply_to'), class: 'label' %> - <%= ff.email_field :documents_copy_email_reply_to, class: 'base-input', dir: 'auto', placeholder: t(:email) %> -
- <% end %> -
- - <%= t('attach_documents_to_the_email') %> - - - <%= ff.check_box :documents_copy_email_attach_documents, { checked: ff.object.documents_copy_email_attach_documents != false, class: 'toggle', disabled: configs['attach_documents'] == false }, 'true', 'false' %> - -
-
- - <%= t('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', disabled: configs['attach_audit_log'] == false }, 'true', 'false' %> - -
-
- - <%= t('send_emails_automatically_on_completion') %> - - - <%= ff.check_box :documents_copy_email_enabled, { checked: ff.object.documents_copy_email_enabled != false && configs['enabled'] != false, class: 'toggle', disabled: configs['enabled'] == false }, 'true', 'false' %> - -
- <% end %> -
- <%= f.button button_title(title: t('save'), disabled_with: t('saving')), class: 'base-button' %> -
- -
-
- <% end %> + <%= render 'templates_preferences/submitter_documents_copy_email_form' %>
@@ -257,57 +116,7 @@ <%= t('completed_notification_email') %>
- <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' }, data: { close_on_submit: false } 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, :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, t('email_subject'), class: 'label' %> - <%= ff.text_field :completed_notification_email_subject, required: true, class: 'base-input', dir: 'auto' %> -
-
-
- <%= ff.label :completed_notification_email_body, t('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' %> - -
-
- - <%= t('attach_documents_to_the_email') %> - - - <%= ff.check_box :completed_notification_email_attach_documents, { checked: ff.object.completed_notification_email_attach_documents != false, class: 'toggle', disabled: configs['attach_documents'] == false }, 'true', 'false' %> - -
-
- - <%= t('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', disabled: configs['attach_audit_log'] == false }, 'true', 'false' %> - -
-
- - <%= t('send_emails_automatically_on_completion') %> - - - <%= ff.check_box :completed_notification_email_enabled, { checked: ff.object.completed_notification_email_enabled != false, class: 'toggle', disabled: configs['enabled'] == false }, 'true', 'false' %> - -
- <% end %> -
- <%= f.button button_title(title: t('save'), disabled_with: t('saving')), class: 'base-button' %> -
- -
-
- <% end %> + <%= render 'templates_preferences/submitter_completed_email_form' %>
@@ -359,9 +168,9 @@ <%= t('share_template_with_test_mode') %> - - <%= f.check_box :value, class: 'toggle', checked: @template.template_sharings.exists?(account_id: current_account.testing_accounts) %> - + + <%= f.check_box :value, class: 'toggle', checked: @template.template_sharings.exists?(account_id: current_account.testing_accounts) %> + <% end %>
diff --git a/config/locales/i18n.yml b/config/locales/i18n.yml index 30a30231..92d43e72 100644 --- a/config/locales/i18n.yml +++ b/config/locales/i18n.yml @@ -840,6 +840,8 @@ en: &en desktop: Desktop mobile: Mobile tablet: Tablet + reset_default: Reset default + send_signature_request_email: Send signature request email submission_sources: api: API bulk: Bulk Send @@ -1764,6 +1766,8 @@ es: &es desktop: Escritorio mobile: Móvil tablet: Tableta + reset_default: Restablecer por defecto + send_signature_request_email: Enviar correo de solicitud de firma submission_sources: api: API bulk: Envío masivo @@ -2689,6 +2693,8 @@ it: &it desktop: Desktop mobile: Mobile tablet: Tablet + reset_default: Reimposta predefinito + send_signature_request_email: Invia email di richiesta firma submission_sources: api: API bulk: Invio massivo @@ -3611,6 +3617,8 @@ fr: &fr desktop: Bureau mobile: Mobile tablet: Tablette + reset_default: Réinitialiser par défaut + send_signature_request_email: Envoyer un e-mail de demande de signature submission_sources: api: API bulk: Envoi en masse @@ -4537,6 +4545,8 @@ pt: &pt desktop: Computador mobile: Celular tablet: Tablet + reset_default: Redefinir para padrão + send_signature_request_email: Enviar e-mail de solicitação de assinatura submission_sources: api: API bulk: Envio em massa @@ -5463,6 +5473,8 @@ de: &de desktop: Desktop mobile: Mobil tablet: Tablet + reset_default: Standard zurücksetzen + send_signature_request_email: Signaturanfrage-E-Mail senden submission_sources: api: API bulk: Massenversand @@ -6750,6 +6762,8 @@ nl: &nl desktop: Desktop mobile: Mobiel tablet: Tablet + reset_default: Standaard herstellen + send_signature_request_email: E-mail met handtekeningaanvraag verzenden submission_sources: api: API bulk: Bulkverzending diff --git a/config/routes.rb b/config/routes.rb index 20a3035d..05abbfc4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -108,7 +108,7 @@ Rails.application.routes.draw do resource :preview, only: %i[show], controller: 'templates_preview' resource :form, only: %i[show], controller: 'templates_form_preview' resource :code_modal, only: %i[show], controller: 'templates_code_modal' - resource :preferences, only: %i[show create], controller: 'templates_preferences' + resource :preferences, only: %i[show create destroy], controller: 'templates_preferences' resource :share_link, only: %i[show create], controller: 'templates_share_link' resources :recipients, only: %i[create], controller: 'templates_recipients' resources :prefillable_fields, only: %i[create], controller: 'templates_prefillable_fields'