@@ -15,7 +15,10 @@ module ReplaceEmailVariables
15
15
SUBMITTER_SLUG = /\{ +submitter\. slug\} +/i
16
16
SUBMISSION_LINK = /\{ +submission\. link\} +/i
17
17
SUBMISSION_ID = /\{ +submission\. id\} +/i
18
- SUBMISSION_SUBMITTERS = /\{ +submission\. submitters\} +/i
18
+ SUBMITTERS = /\{ +(?:submission\. )?submitters\} +/i
19
+ SUBMITTERS_N_EMAIL = /\{ +submitters\[ (?<index>\d +)\] \. email\} +/i
20
+ SUBMITTERS_N_NAME = /\{ +submitters\[ (?<index>\d +)\] \. name\} +/i
21
+ SUBMITTERS_N_FIRST_NAME = /\{ +submitters\[ (?<index>\d +)\] \. first_name\} +/i
19
22
DOCUMENTS_LINKS = /\{ +documents\. links\} +/i
20
23
DOCUMENTS_LINK = /\{ +documents\. link\} +/i
21
24
@@ -37,13 +40,25 @@ def call(text, submitter:, tracking_event_type: 'click_email', html_escape: fals
37
40
text = replace ( text , SUBMISSION_LINK , html_escape :) do
38
41
submitter . submission ? build_submission_link ( submitter . submission ) : ''
39
42
end
40
- text = replace ( text , SUBMISSION_SUBMITTERS , html_escape :) { build_submission_submitters ( submitter . submission ) }
43
+ text = replace ( text , SUBMITTERS , html_escape :) { build_submission_submitters ( submitter . submission ) }
41
44
text = replace ( text , DOCUMENTS_LINKS , html_escape :) { build_documents_links_text ( submitter , sig ) }
42
45
text = replace ( text , DOCUMENTS_LINK , html_escape :) { build_documents_links_text ( submitter , sig ) }
43
46
text = replace ( text , ACCOUNT_NAME , html_escape :) { submitter . submission . account . name }
44
47
text = replace ( text , SENDER_NAME , html_escape :) { submitter . submission . created_by_user &.full_name }
45
48
text = replace ( text , SENDER_FIRST_NAME , html_escape :) { submitter . submission . created_by_user &.first_name }
46
49
50
+ text = replace ( text , SUBMITTERS_N_NAME , html_escape :) do |match |
51
+ build_submitters_n_field ( submitter . submission , match [ :index ] . to_i - 1 , :name )
52
+ end
53
+
54
+ text = replace ( text , SUBMITTERS_N_EMAIL , html_escape :) do |match |
55
+ build_submitters_n_field ( submitter . submission , match [ :index ] . to_i - 1 , :email )
56
+ end
57
+
58
+ text = replace ( text , SUBMITTERS_N_FIRST_NAME , html_escape :) do |match |
59
+ build_submitters_n_field ( submitter . submission , match [ :index ] . to_i - 1 , :first_name )
60
+ end
61
+
47
62
replace ( text , SENDER_EMAIL , html_escape :) { submitter . submission . created_by_user &.email . to_s . sub ( /\+ \w +@/ , '@' ) }
48
63
end
49
64
# rubocop:enable Metrics
@@ -54,12 +69,18 @@ def build_documents_links_text(submitter, sig = nil)
54
69
)
55
70
end
56
71
72
+ def build_submitters_n_field ( submission , index , field_name )
73
+ uuid = ( submission . template_submitters || submission . template . submitters ) . dig ( index , 'uuid' )
74
+
75
+ submission . submitters . find { |s | s . uuid == uuid } . try ( field_name )
76
+ end
77
+
57
78
def replace ( text , var , html_escape : false )
58
79
text . gsub ( var ) do
59
80
if html_escape
60
- ERB ::Util . html_escape ( yield )
81
+ ERB ::Util . html_escape ( yield ( Regexp . last_match ) )
61
82
else
62
- yield
83
+ yield ( Regexp . last_match )
63
84
end
64
85
end
65
86
end
0 commit comments