Skip to content

Commit 22d4c1b

Browse files
authored
Merge from docusealco/wip
2 parents fd86836 + e3dfb0a commit 22d4c1b

19 files changed

Lines changed: 402 additions & 55 deletions

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ source 'https://rubygems.org'
44

55
ruby '4.0.1'
66

7+
gem 'addressable'
78
gem 'arabic-letter-connector', require: false
89
gem 'aws-sdk-s3', require: false
910
gem 'aws-sdk-secretsmanager', require: false
@@ -28,7 +29,6 @@ gem 'oj'
2829
gem 'onnxruntime', require: false
2930
gem 'pagy'
3031
gem 'pg', require: false
31-
gem 'premailer-rails'
3232
gem 'pretender'
3333
gem 'puma', require: false
3434
gem 'rack'
@@ -43,7 +43,7 @@ gem 'shakapacker'
4343
gem 'sidekiq'
4444
gem 'sqlite3', require: false
4545
gem 'strip_attributes'
46-
gem 'trilogy', github: 'trilogy-libraries/trilogy', glob: 'contrib/ruby/*.gemspec', require: false
46+
gem 'trilogy', require: false
4747
gem 'turbo-rails'
4848
gem 'twitter_cldr', require: false
4949
gem 'tzinfo-data'

Gemfile.lock

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
GIT
2-
remote: https://github.com/trilogy-libraries/trilogy.git
3-
revision: 3963d490459df7a2b5bedb42424c3285f25eab22
4-
glob: contrib/ruby/*.gemspec
5-
specs:
6-
trilogy (2.10.0)
7-
bigdecimal
8-
91
GEM
102
remote: https://rubygems.org/
113
specs:
@@ -116,7 +108,7 @@ GEM
116108
cgi
117109
rexml
118110
base64 (0.3.0)
119-
bcrypt (3.1.21)
111+
bcrypt (3.1.22)
120112
better_html (2.2.0)
121113
actionview (>= 7.0)
122114
activesupport (>= 7.0)
@@ -158,8 +150,6 @@ GEM
158150
bigdecimal
159151
rexml
160152
crass (1.0.6)
161-
css_parser (1.21.1)
162-
addressable
163153
csv (3.3.5)
164154
csv-safe (3.3.1)
165155
csv (~> 3.0)
@@ -171,16 +161,16 @@ GEM
171161
irb (~> 1.10)
172162
reline (>= 0.3.8)
173163
declarative (0.0.20)
174-
devise (4.9.4)
164+
devise (5.0.3)
175165
bcrypt (~> 3.0)
176166
orm_adapter (~> 0.1)
177-
railties (>= 4.1.0)
167+
railties (>= 7.0)
178168
responders
179169
warden (~> 1.2.3)
180-
devise-two-factor (6.3.1)
181-
activesupport (>= 7.0, < 8.2)
182-
devise (>= 4.0, < 5.0)
183-
railties (>= 7.0, < 8.2)
170+
devise-two-factor (6.4.0)
171+
activesupport (>= 7.2, < 8.2)
172+
devise (>= 4.0, < 6.0)
173+
railties (>= 7.2, < 8.2)
184174
rotp (~> 6.0)
185175
diff-lcs (1.6.2)
186176
digest-crc (0.7.0)
@@ -189,7 +179,7 @@ GEM
189179
dotenv (3.2.0)
190180
drb (2.2.3)
191181
email_typo (0.2.3)
192-
erb (6.0.1)
182+
erb (6.0.2)
193183
erb_lint (0.9.0)
194184
activesupport
195185
better_html (>= 2.0.1)
@@ -272,19 +262,19 @@ GEM
272262
geom2d (~> 0.4, >= 0.4.1)
273263
openssl (>= 2.2.1)
274264
strscan (>= 3.1.2)
275-
htmlentities (4.4.2)
276265
i18n (1.14.8)
277266
concurrent-ruby (~> 1.0)
278267
image_processing (1.14.0)
279268
mini_magick (>= 4.9.5, < 6)
280269
ruby-vips (>= 2.0.17, < 3)
281270
io-console (0.8.2)
282-
irb (1.16.0)
271+
irb (1.17.0)
283272
pp (>= 0.6.0)
273+
prism (>= 1.3.0)
284274
rdoc (>= 4.0.0)
285275
reline (>= 0.4.2)
286276
jmespath (1.6.2)
287-
json (2.18.1)
277+
json (2.19.2)
288278
jwt (3.1.2)
289279
base64
290280
language_server-protocol (3.17.0.5)
@@ -306,7 +296,7 @@ GEM
306296
activesupport (>= 4)
307297
railties (>= 4)
308298
request_store (~> 1.0)
309-
loofah (2.25.0)
299+
loofah (2.25.1)
310300
crass (~> 1.0.2)
311301
nokogiri (>= 1.12.0)
312302
mail (2.9.0)
@@ -321,7 +311,8 @@ GEM
321311
mini_magick (5.3.1)
322312
logger
323313
mini_mime (1.1.5)
324-
minitest (6.0.1)
314+
minitest (6.0.2)
315+
drb (~> 2.0)
325316
prism (~> 1.5)
326317
msgpack (1.8.0)
327318
multi_json (1.19.1)
@@ -337,17 +328,17 @@ GEM
337328
net-smtp (0.5.1)
338329
net-protocol
339330
nio4r (2.7.5)
340-
nokogiri (1.19.1-aarch64-linux-gnu)
331+
nokogiri (1.19.2-aarch64-linux-gnu)
341332
racc (~> 1.4)
342-
nokogiri (1.19.1-aarch64-linux-musl)
333+
nokogiri (1.19.2-aarch64-linux-musl)
343334
racc (~> 1.4)
344-
nokogiri (1.19.1-arm64-darwin)
335+
nokogiri (1.19.2-arm64-darwin)
345336
racc (~> 1.4)
346-
nokogiri (1.19.1-x86_64-linux-gnu)
337+
nokogiri (1.19.2-x86_64-linux-gnu)
347338
racc (~> 1.4)
348-
nokogiri (1.19.1-x86_64-linux-musl)
339+
nokogiri (1.19.2-x86_64-linux-musl)
349340
racc (~> 1.4)
350-
numo-narray-alt (0.9.13)
341+
numo-narray-alt (0.10.3)
351342
oj (3.16.13)
352343
bigdecimal (>= 3.0)
353344
ostruct (>= 0.2)
@@ -376,18 +367,10 @@ GEM
376367
pg (1.6.3-x86_64-linux-musl)
377368
pp (0.6.3)
378369
prettyprint
379-
premailer (1.27.0)
380-
addressable
381-
css_parser (>= 1.19.0)
382-
htmlentities (>= 4.0.0)
383-
premailer-rails (1.12.0)
384-
actionmailer (>= 3)
385-
net-smtp
386-
premailer (~> 1.7, >= 1.7.9)
387370
pretender (0.6.0)
388371
actionpack (>= 7.1)
389372
prettyprint (0.2.0)
390-
prism (1.8.0)
373+
prism (1.9.0)
391374
pry (0.16.0)
392375
coderay (~> 1.1)
393376
method_source (~> 1.0)
@@ -429,8 +412,8 @@ GEM
429412
activesupport (>= 5.0.0)
430413
minitest
431414
nokogiri (>= 1.6)
432-
rails-html-sanitizer (1.6.2)
433-
loofah (~> 2.21)
415+
rails-html-sanitizer (1.7.0)
416+
loofah (~> 2.25)
434417
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
435418
rails-i18n (8.1.0)
436419
i18n (>= 0.7, < 2)
@@ -446,7 +429,7 @@ GEM
446429
zeitwerk (~> 2.6)
447430
rainbow (3.1.1)
448431
rake (13.3.1)
449-
rdoc (7.1.0)
432+
rdoc (7.2.0)
450433
erb
451434
psych (>= 4.0.0)
452435
tsort
@@ -562,6 +545,8 @@ GEM
562545
thor (1.5.0)
563546
timeout (0.6.0)
564547
trailblazer-option (0.1.2)
548+
trilogy (2.10.0)
549+
bigdecimal
565550
tsort (0.2.0)
566551
turbo-rails (2.0.21)
567552
actionpack (>= 7.1.0)
@@ -601,7 +586,7 @@ GEM
601586
xpath (3.2.0)
602587
nokogiri (~> 1.8)
603588
yaml (0.4.0)
604-
zeitwerk (2.7.4)
589+
zeitwerk (2.7.5)
605590

606591
PLATFORMS
607592
aarch64-linux
@@ -611,6 +596,7 @@ PLATFORMS
611596
x86_64-linux-musl
612597

613598
DEPENDENCIES
599+
addressable
614600
annotaterb
615601
arabic-letter-connector
616602
aws-sdk-s3
@@ -647,7 +633,6 @@ DEPENDENCIES
647633
onnxruntime
648634
pagy
649635
pg
650-
premailer-rails
651636
pretender
652637
pry-rails
653638
puma
@@ -669,7 +654,7 @@ DEPENDENCIES
669654
simplecov
670655
sqlite3
671656
strip_attributes
672-
trilogy!
657+
trilogy
673658
turbo-rails
674659
twitter_cldr
675660
tzinfo-data

app/controllers/api/templates_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def update
6969
SearchEntries.enqueue_reindex(@template)
7070

7171
WebhookUrls.enqueue_events(@template, 'template.updated')
72+
WebhookUrls.enqueue_events(@template, 'template.archived') if archived == true
7273

7374
render json: @template.as_json(only: %i[id updated_at])
7475
end
@@ -78,6 +79,8 @@ def destroy
7879
@template.destroy!
7980
else
8081
@template.update!(archived_at: Time.current)
82+
83+
WebhookUrls.enqueue_events(@template, 'template.archived')
8184
end
8285

8386
render json: @template.as_json(only: %i[id archived_at])

app/controllers/templates_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def destroy
8484
else
8585
@template.update!(archived_at: Time.current)
8686

87+
WebhookUrls.enqueue_events(@template, 'template.archived')
88+
8789
I18n.t('template_has_been_archived')
8890
end
8991

app/controllers/templates_restore_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class TemplatesRestoreController < ApplicationController
66
def create
77
@template.update!(archived_at: nil)
88

9+
WebhookUrls.enqueue_events(@template, 'template.updated')
10+
911
redirect_to template_path(@template), notice: I18n.t('template_has_been_unarchived')
1012
end
1113
end

app/controllers/webhook_events_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def show
1515
Submissions::SerializeForApi.call(@webhook_event.record)
1616
when 'template.created', 'template.updated'
1717
Templates::SerializeForApi.call(@webhook_event.record)
18-
when 'submission.archived'
18+
when 'submission.archived', 'template.archived'
1919
@webhook_event.record.as_json(only: %i[id archived_at])
2020
end
2121
end

app/javascript/template_builder/builder.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,10 +2735,13 @@ export default {
27352735
} else {
27362736
this.isSaving = true
27372737

2738-
this.documentRefs.filter((ref) => ref.update).map((ref) => ref.update())
2738+
const dynamicDocumentRefs = this.documentRefs.filter((ref) => ref.isDynamic)
2739+
2740+
dynamicDocumentRefs.map((ref) => ref.update())
2741+
27392742
this.rebuildVariablesSchema({ disable: false })
27402743

2741-
const dynamicDocumentSaves = this.documentRefs.filter((ref) => ref.saveBody).map((ref) => ref.saveBody())
2744+
const dynamicDocumentSaves = dynamicDocumentRefs.map((ref) => ref.saveBody())
27422745

27432746
Promise.all([this.save(), ...dynamicDocumentSaves]).then(() => {
27442747
window.Turbo.visit(`/templates/${this.template.id}`)
@@ -3028,6 +3031,8 @@ export default {
30283031
} else {
30293032
dynamicDocumentRef.syncVariablesSchema(this.template.variables_schema, parsed, { disable })
30303033
}
3034+
} else {
3035+
this.template.variables_schema = {}
30313036
}
30323037
}
30333038
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
class SendTemplateArchivedWebhookRequestJob
4+
include Sidekiq::Job
5+
6+
sidekiq_options queue: :webhooks
7+
8+
MAX_ATTEMPTS = 10
9+
10+
def perform(params = {})
11+
template = Template.find_by(id: params['template_id'])
12+
13+
return unless template
14+
15+
webhook_url = WebhookUrl.find_by(id: params['webhook_url_id'])
16+
17+
return unless webhook_url
18+
19+
attempt = params['attempt'].to_i
20+
21+
return if webhook_url.url.blank? || webhook_url.events.exclude?('template.archived')
22+
23+
resp = SendWebhookRequest.call(webhook_url, event_type: 'template.archived',
24+
event_uuid: params['event_uuid'],
25+
record: template,
26+
attempt:,
27+
data: template.as_json(only: %i[id archived_at]))
28+
29+
if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
30+
(!Docuseal.multitenant? || template.account.account_configs.exists?(key: :plan))
31+
SendTemplateArchivedWebhookRequestJob.perform_in((2**attempt).minutes, {
32+
**params,
33+
'attempt' => attempt + 1,
34+
'last_status' => resp&.status.to_i
35+
})
36+
end
37+
end
38+
end

app/mailers/application_mailer.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class ApplicationMailer < ActionMailer::Base
55
layout 'mailer'
66

77
register_interceptor ActionMailerConfigsInterceptor
8+
register_interceptor HtmlToPlainTextInterceptor
9+
register_preview_interceptor HtmlToPlainTextInterceptor
810

911
register_observer ActionMailerEventsObserver
1012

app/models/webhook_url.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class WebhookUrl < ApplicationRecord
3434
submission.archived
3535
template.created
3636
template.updated
37+
template.archived
3738
].freeze
3839

3940
belongs_to :account

0 commit comments

Comments
 (0)