adjust webhooks

This commit is contained in:
Pete Matsyburka
2024-11-01 15:35:02 +02:00
parent 84edb6dbda
commit 2542f26d96
40 changed files with 156 additions and 235 deletions
+5 -5
View File
@@ -63,15 +63,15 @@ class ProcessSubmitterCompletionJob
end
def enqueue_completed_webhooks(submitter, is_all_completed: false)
submitter.account.webhook_urls.with_events(%w[form.completed submission.completed]).each do |webhook|
WebhookUrls.for_account_id(submitter.account_id, %w[form.completed submission.completed]).each do |webhook|
if webhook.events.include?('form.completed')
SendFormCompletedWebhookRequestJob.perform_async({ 'submitter_id' => submitter.id,
'webhook_url_id' => webhook.id })
SendFormCompletedWebhookRequestJob.perform_async('submitter_id' => submitter.id,
'webhook_url_id' => webhook.id)
end
if webhook.events.include?('submission.completed') && is_all_completed
SendSubmissionCompletedWebhookRequestJob.perform_async({ 'submission_id' => submitter.submission_id,
'webhook_url_id' => webhook.id })
SendSubmissionCompletedWebhookRequestJob.perform_async('submission_id' => submitter.submission_id,
'webhook_url_id' => webhook.id)
end
end
end
@@ -11,12 +11,10 @@ class SendFormCompletedWebhookRequestJob
def perform(params = {})
submitter = Submitter.find(params['submitter_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
attempt = params['attempt'].to_i
webhook_url = submitter.account.webhook_urls.find_by(id: params['webhook_url_id'])
return unless webhook_url
return if webhook_url.url.blank? || webhook_url.events.exclude?('form.completed')
Submissions::EnsureResultGenerated.call(submitter)
@@ -11,12 +11,10 @@ class SendFormDeclinedWebhookRequestJob
def perform(params = {})
submitter = Submitter.find(params['submitter_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
attempt = params['attempt'].to_i
webhook_url = submitter.submission.account.webhook_urls.find_by(id: params['webhook_url_id'])
return unless webhook_url
return if webhook_url.url.blank? || webhook_url.events.exclude?('form.declined')
ActiveStorage::Current.url_options = Docuseal.default_url_options
@@ -11,12 +11,10 @@ class SendFormStartedWebhookRequestJob
def perform(params = {})
submitter = Submitter.find(params['submitter_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
attempt = params['attempt'].to_i
webhook_url = submitter.submission.account.webhook_urls.find_by(id: params['webhook_url_id'])
return unless webhook_url
return if webhook_url.url.blank? || webhook_url.events.exclude?('form.started')
ActiveStorage::Current.url_options = Docuseal.default_url_options
@@ -11,12 +11,10 @@ class SendFormViewedWebhookRequestJob
def perform(params = {})
submitter = Submitter.find(params['submitter_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
attempt = params['attempt'].to_i
webhook_url = submitter.submission.account.webhook_urls.find_by(id: params['webhook_url_id'])
return unless webhook_url
return if webhook_url.url.blank? || webhook_url.events.exclude?('form.viewed')
ActiveStorage::Current.url_options = Docuseal.default_url_options
@@ -11,12 +11,10 @@ class SendSubmissionArchivedWebhookRequestJob
def perform(params = {})
submission = Submission.find(params['submission_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
attempt = params['attempt'].to_i
webhook_url = submission.account.webhook_urls.find_by(id: params['webhook_url_id'])
return unless webhook_url
return if webhook_url.url.blank? || webhook_url.events.exclude?('submission.archived')
resp = begin
@@ -11,12 +11,10 @@ class SendSubmissionCompletedWebhookRequestJob
def perform(params = {})
submission = Submission.find(params['submission_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
attempt = params['attempt'].to_i
webhook_url = submission.account.webhook_urls.find_by(id: params['webhook_url_id'])
return unless webhook_url
return if webhook_url.url.blank? || webhook_url.events.exclude?('submission.completed')
resp = begin
@@ -11,12 +11,10 @@ class SendSubmissionCreatedWebhookRequestJob
def perform(params = {})
submission = Submission.find(params['submission_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
attempt = params['attempt'].to_i
webhook_url = submission.account.webhook_urls.find_by(id: params['webhook_url_id'])
return unless webhook_url
return if webhook_url.url.blank? || webhook_url.events.exclude?('submission.created')
resp = begin
@@ -11,12 +11,10 @@ class SendTemplateCreatedWebhookRequestJob
def perform(params = {})
template = Template.find(params['template_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
attempt = params['attempt'].to_i
webhook_url = template.account.webhook_urls.find_by(id: params['webhook_url_id'])
return unless webhook_url
return if webhook_url.url.blank? || webhook_url.events.exclude?('template.created')
resp = begin
@@ -11,12 +11,10 @@ class SendTemplateUpdatedWebhookRequestJob
def perform(params = {})
template = Template.find(params['template_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
attempt = params['attempt'].to_i
webhook_url = template.account.webhook_urls.find_by(id: params['webhook_url_id'])
return unless webhook_url
return if webhook_url.url.blank? || webhook_url.events.exclude?('template.updated')
resp = begin