add preserve submitters order option
This commit is contained in:
@@ -9,25 +9,26 @@ module Api
|
||||
template = current_account.templates.find(params[:template_id])
|
||||
|
||||
submissions =
|
||||
if (params[:emails] || params[:email]).present?
|
||||
if (emails = (params[:emails] || params[:email]).presence)
|
||||
Submissions.create_from_emails(template:,
|
||||
user: current_user,
|
||||
source: :api,
|
||||
mark_as_sent: params[:send_email] != 'false',
|
||||
emails: params[:emails] || params[:email])
|
||||
emails:)
|
||||
else
|
||||
submissions_attrs = normalize_submissions_params!(submissions_params[:submission], template)
|
||||
|
||||
Submissions.create_from_submitters(template:,
|
||||
user: current_user,
|
||||
source: :api,
|
||||
mark_as_sent: params[:send_email] != 'false',
|
||||
submissions_attrs:)
|
||||
Submissions.create_from_submitters(
|
||||
template:,
|
||||
user: current_user,
|
||||
source: :api,
|
||||
mark_as_sent: params[:send_email] != 'false',
|
||||
submitters_order: params[:submitters_order] || 'preserved',
|
||||
submissions_attrs:
|
||||
)
|
||||
end
|
||||
|
||||
submitters = submissions.flat_map(&:submitters)
|
||||
|
||||
Submitters.send_signature_requests(submitters, send_email: params[:send_email] != 'false')
|
||||
Submissions.send_signature_requests(submissions, send_email: params[:send_email] != 'false')
|
||||
|
||||
render json: submitters
|
||||
rescue UnknownFieldName, UnknownSubmitterName => e
|
||||
|
||||
@@ -26,16 +26,14 @@ class SubmissionsController < ApplicationController
|
||||
Submissions.create_from_submitters(template: @template,
|
||||
user: current_user,
|
||||
source: :invite,
|
||||
submitters_order: params[:preserve_order] == '1' ? 'preserved' : 'random',
|
||||
mark_as_sent: params[:send_email] == '1',
|
||||
submissions_attrs: submissions_params[:submission].to_h.values)
|
||||
end
|
||||
|
||||
submitters = submissions.flat_map(&:submitters)
|
||||
Submissions.send_signature_requests(submissions, params)
|
||||
|
||||
Submitters.send_signature_requests(submitters, params)
|
||||
|
||||
redirect_to template_path(@template),
|
||||
notice: "#{submitters.size} #{'recipient'.pluralize(submitters.size)} added"
|
||||
redirect_to template_path(@template), notice: 'New recipients have been added'
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
||||
@@ -4,6 +4,10 @@ class ProcessSubmitterCompletionJob < ApplicationJob
|
||||
def perform(submitter)
|
||||
is_all_completed = !submitter.submission.submitters.exists?(completed_at: nil)
|
||||
|
||||
if !is_all_completed && submitter.submission.submitters_order_preserved?
|
||||
enqueue_next_submitter_request_notification(submitter)
|
||||
end
|
||||
|
||||
Submissions::EnsureResultGenerated.call(submitter)
|
||||
|
||||
if submitter.account.encrypted_configs.exists?(key: EncryptedConfig::WEBHOOK_URL_KEY)
|
||||
@@ -25,8 +29,23 @@ class ProcessSubmitterCompletionJob < ApplicationJob
|
||||
SubmitterMailer.completed_email(submitter, user, bcc:).deliver_later!
|
||||
end
|
||||
|
||||
to = submitter.submission.submitters.order(:completed_at).select(&:email?).map(&:friendly_name).join(', ')
|
||||
to = submitter.submission.submitters.sort_by(&:completed_at).select(&:email?).map(&:friendly_name).join(', ')
|
||||
|
||||
SubmitterMailer.documents_copy_email(submitter, to:).deliver_later! if to.present?
|
||||
end
|
||||
|
||||
def enqueue_next_submitter_request_notification(submitter)
|
||||
next_submitter_item =
|
||||
submitter.submission.template_submitters.find do |e|
|
||||
sub = submitter.submission.submitters.find { |s| s.uuid == e['uuid'] }
|
||||
|
||||
sub.completed_at.blank? && sub.sent_at.blank?
|
||||
end
|
||||
|
||||
return unless next_submitter_item
|
||||
|
||||
next_submitter = submitter.submission.submitters.find { |s| s.uuid == next_submitter_item['uuid'] }
|
||||
|
||||
Submitters.send_signature_requests([next_submitter], send_email: true)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SendSubmitterInvitationEmailJob < ApplicationJob
|
||||
def perform(submitter)
|
||||
SubmitterMailer.invitation_email(submitter).deliver_now!
|
||||
|
||||
submitter.sent_at ||= Time.current
|
||||
submitter.save
|
||||
end
|
||||
end
|
||||
@@ -7,6 +7,7 @@
|
||||
# id :bigint not null, primary key
|
||||
# deleted_at :datetime
|
||||
# source :text not null
|
||||
# submitters_order :string not null
|
||||
# template_fields :text
|
||||
# template_schema :text
|
||||
# template_submitters :text
|
||||
@@ -37,6 +38,7 @@ class Submission < ApplicationRecord
|
||||
serialize :template_submitters, JSON
|
||||
|
||||
attribute :source, :string, default: 'link'
|
||||
attribute :submitters_order, :string, default: 'random'
|
||||
|
||||
has_many :template_schema_documents,
|
||||
->(e) { where(uuid: (e.template_schema.presence || e.template.schema).pluck('attachment_uuid')) },
|
||||
@@ -50,4 +52,9 @@ class Submission < ApplicationRecord
|
||||
embed: 'embed',
|
||||
link: 'link'
|
||||
}, scope: false, prefix: true
|
||||
|
||||
enum :submitters_order, {
|
||||
random: 'random',
|
||||
preserved: 'preserved'
|
||||
}, scope: false, prefix: true
|
||||
end
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
</a>
|
||||
</dynamic-list>
|
||||
<div>
|
||||
<%= render('submitters_order', f:, template:) if Accounts.can_send_emails?(current_account) %>
|
||||
<%= render 'send_email', f:, template: %>
|
||||
<%= render 'send_sms', f: %>
|
||||
</div>
|
||||
|
||||
@@ -35,7 +35,10 @@
|
||||
</a>
|
||||
</dynamic-list>
|
||||
<% end %>
|
||||
<%= render 'send_email', f:, template: %>
|
||||
<div>
|
||||
<%= render 'send_email', f:, template: %>
|
||||
<%= render('submitters_order', f:, template:) if Accounts.can_send_emails?(current_account) %>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<%= f.button button_title(title: 'Add Recipients'), class: 'base-button' %>
|
||||
</div>
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
</a>
|
||||
</dynamic-list>
|
||||
<%= render 'send_sms', f: %>
|
||||
<%= render('submitters_order', f:, template:) if Accounts.can_send_emails?(current_account) %>
|
||||
<div class="form-control">
|
||||
<%= f.button button_title(title: 'Add Recipients'), class: 'base-button' %>
|
||||
</div>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<% is_smtp_configured = Accounts.can_send_emails?(current_account) %>
|
||||
<%= f.label :send_email, for: uuid = SecureRandom.uuid, class: 'flex items-center cursor-pointer' do %>
|
||||
<%= f.check_box :send_email, id: uuid, class: 'base-checkbox', disabled: !is_smtp_configured, checked: is_smtp_configured %>
|
||||
<span class="label">Send Email</span>
|
||||
<span class="label">Send emails</span>
|
||||
<% end %>
|
||||
<% unless is_smtp_configured %>
|
||||
<div class="alert my-4">
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<% if template.submitters.size > 1 %>
|
||||
<div class="form-control">
|
||||
<%= f.label :preserve_order, for: uuid = SecureRandom.uuid, class: 'flex items-center cursor-pointer' do %>
|
||||
<%= f.check_box :preserve_order, id: uuid, class: 'base-checkbox', checked: template.submissions.last&.submitters_order.in?(['preserved', nil]) %>
|
||||
<span class="label">Preserve submitters order</span>
|
||||
<span class="tooltip" data-tip="When checked, notifications will be sent to the second submitter once the form is completed by the previous submitter. Uncheck this option to send notifications to all submitters simultaneously right away.">
|
||||
<%= svg_icon('info_circle', class: 'w-4 h-4') %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
Reference in New Issue
Block a user