diff --git a/app/models/submitter.rb b/app/models/submitter.rb index f6121788..22ecbb19 100644 --- a/app/models/submitter.rb +++ b/app/models/submitter.rb @@ -67,8 +67,8 @@ class Submitter < ApplicationRecord scope :completed, -> { where.not(completed_at: nil) } - after_destroy :anonymize_email_events, if: -> { Docuseal.multitenant? } after_update :export_submission_on_status_change + after_destroy :anonymize_email_events, if: -> { Docuseal.multitenant? } def status if declined_at? @@ -126,10 +126,10 @@ class Submitter < ApplicationRecord def export_submission_on_status_change status_fields = %w[completed_at declined_at opened_at sent_at] - return unless (saved_changes.keys & status_fields).any? + return unless saved_changes.keys.intersect?(status_fields) ExportSubmissionService.new(submission).call - rescue => e + rescue StandardError => e Rails.logger.error("Failed to export submission on status change: #{e.message}") end end diff --git a/app/services/export_submission_service.rb b/app/services/export_submission_service.rb index 02ff57b8..d254508c 100644 --- a/app/services/export_submission_service.rb +++ b/app/services/export_submission_service.rb @@ -65,11 +65,11 @@ class ExportSubmissionService < ExportService if statuses.include?('declined') 'declined' - elsif statuses.all? { |s| s == 'completed' } + elsif statuses.all?('completed') 'completed' - elsif statuses.any? { |s| s == 'opened' } + elsif statuses.any?('opened') 'in_progress' - elsif statuses.any? { |s| s == 'sent' } + elsif statuses.any?('sent') 'sent' else 'pending'