-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd853c6
commit be4a050
Showing
2 changed files
with
64 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
module Submissions | ||
module AssignDefinedSubmitters | ||
module_function | ||
|
||
def call(submission) | ||
submission.submitters_order = 'preserved' | ||
|
||
assign_defined_submitters(submission) | ||
assign_linked_submitters(submission) | ||
|
||
if submission.submitters.size == 1 && submission.template.submitters.size == 2 | ||
submission.submitters.new( | ||
account_id: submission.account_id, | ||
uuid: submission.template.submitters.second['uuid'], | ||
email: submission.template.author.email | ||
) | ||
end | ||
|
||
submission | ||
end | ||
|
||
def assign_defined_submitters(submission) | ||
submission.template.submitters.to_a.select do |item| | ||
next if item['email'].blank? && item['is_requester'].blank? | ||
|
||
submission.submitters.new( | ||
account_id: submission.account_id, | ||
uuid: item['uuid'], | ||
email: item['is_requester'] ? submission.template.author.email : item['email'] | ||
) | ||
end | ||
end | ||
|
||
def assign_linked_submitters(submission) | ||
submission.template.submitters.to_a.select do |item| | ||
next if item['linked_to_uuid'].blank? | ||
|
||
email = submission.submitters.find { |s| s.uuid == item['linked_to_uuid'] }&.email | ||
|
||
next unless email | ||
|
||
submission.submitters.new( | ||
account_id: submission.account_id, | ||
uuid: item['uuid'], | ||
email: | ||
) | ||
end | ||
end | ||
end | ||
end |