diff --git a/app/controllers/submitters_reset_signature_controller.rb b/app/controllers/submitters_reset_signature_controller.rb new file mode 100644 index 00000000..1fabbd6b --- /dev/null +++ b/app/controllers/submitters_reset_signature_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class SubmittersResetSignatureController < ApplicationController + load_and_authorize_resource :submitter, parent: false + + def update + authorize!(:update, @submitter) + + if @submitter.completed_at.blank? + return redirect_back(fallback_location: submission_path(@submitter.submission), + alert: I18n.t('signature_has_not_been_completed_yet')) + end + + # Remove the previously generated signature artifacts. + @submitter.documents.purge + @submitter.attachments.purge + @submitter.preview_documents.purge + + # Re-open the submitter's form so they can sign again from scratch. + @submitter.update!(completed_at: nil, opened_at: nil, declined_at: nil, values: {}) + + # Email the signer a fresh invitation to correct their signature. + SendSubmitterInvitationEmailJob.perform_async('submitter_id' => @submitter.id) + + @submitter.update!(sent_at: Time.current) + + redirect_back(fallback_location: submission_path(@submitter.submission), + notice: I18n.t('correction_request_has_been_sent')) + end +end diff --git a/app/views/submissions/show.html.erb b/app/views/submissions/show.html.erb index 56994bd7..0b41e0c3 100644 --- a/app/views/submissions/show.html.erb +++ b/app/views/submissions/show.html.erb @@ -283,6 +283,11 @@ <%= button_to t('resubmit'), submitters_resubmit_path(submitter), method: :put, class: 'btn btn-sm btn-primary w-full', form: { target: '_blank' }, data: { turbo: false } %> <% end %> + <% if signed_in? && submitter && submitter.completed_at? && !@submission.archived_at? && !@submission.template&.archived_at? && can?(:update, @submission) && (Docuseal.multitenant? || Accounts.can_send_emails?(current_account)) && !@submission.expired? %> +
+ <%= button_to t('correct_signature'), submitters_reset_signature_path(submitter), method: :put, class: 'btn btn-sm btn-outline w-full', data: { turbo_confirm: t('are_you_sure_you_want_to_reset_this_signature') } %> +
+ <% end %>
diff --git a/config/locales/i18n.yml b/config/locales/i18n.yml index 876ca15b..16067943 100644 --- a/config/locales/i18n.yml +++ b/config/locales/i18n.yml @@ -195,6 +195,10 @@ en: &en send_copy_to_email: Send copy to Email sending: Sending resubmit: Resubmit + correct_signature: Correct Signature + correction_request_has_been_sent: A request to correct the signature has been emailed to the signer. + signature_has_not_been_completed_yet: This signature has not been completed yet. + are_you_sure_you_want_to_reset_this_signature: This will delete the signer's current signature and email them to sign again. Continue? form_has_been_deleted_by_html: 'Form has been deleted by %{name}.' or: or download_documents: Download documents @@ -1512,6 +1516,10 @@ es: &es microsoft_account_has_been_connected: La cuenta de Microsoft ha sido conectada. but_not_activated: pero no activado email_has_been_sent: El correo ha sido enviado. + correct_signature: Corregir firma + correction_request_has_been_sent: Se envió al firmante un correo para corregir su firma. + signature_has_not_been_completed_yet: Esta firma aún no ha sido completada. + are_you_sure_you_want_to_reset_this_signature: Esto eliminará la firma actual del firmante y le enviará un correo para firmar de nuevo. ¿Continuar? email_has_been_sent_already: El correo ya ha sido enviado. initial_setup: Configuración inicial demo_environment: Entorno de demostración diff --git a/config/routes.rb b/config/routes.rb index ad8505e5..43ecda4a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -82,6 +82,7 @@ Rails.application.routes.draw do resources :testing_api_settings, only: %i[index] resources :submitters_autocomplete, only: %i[index] resources :submitters_resubmit, only: %i[update] + resources :submitters_reset_signature, only: %i[update] resources :template_folders_autocomplete, only: %i[index] resources :webhook_secret, only: %i[show update] resources :webhook_hmac, only: %i[show]