Files

44 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

2025-07-04 21:11:08 +03:00
# frozen_string_literal: true
class SendTestWebhookRequestJob
include Sidekiq::Job
sidekiq_options retry: 0
USER_AGENT = 'DocuSeal.com Webhook'
2025-12-18 12:45:33 +02:00
HttpsError = Class.new(StandardError)
LocalhostError = Class.new(StandardError)
2025-07-04 21:11:08 +03:00
def perform(params = {})
2025-12-03 13:20:52 +02:00
submitter = Submitter.find_by(id: params['submitter_id'])
2025-07-04 21:11:08 +03:00
2025-12-03 13:20:52 +02:00
return unless submitter
webhook_url = WebhookUrl.find_by(id: params['webhook_url_id'])
return unless webhook_url
2025-07-04 21:11:08 +03:00
2025-12-18 12:45:33 +02:00
if Docuseal.multitenant?
uri = begin
URI(webhook_url.url)
rescue URI::Error
Addressable::URI.parse(webhook_url.url).normalize
end
2026-02-16 08:08:41 +02:00
raise HttpsError, 'Only HTTPS is allowed.' if uri.scheme != 'https' || [443, nil].exclude?(uri.port)
2025-12-18 12:45:33 +02:00
raise LocalhostError, "Can't send to localhost." if uri.host.in?(SendWebhookRequest::LOCALHOSTS)
end
2025-07-04 21:11:08 +03:00
Faraday.post(webhook_url.url,
{
event_type: 'form.completed',
timestamp: Time.current.iso8601,
data: Submitters::SerializeForWebhook.call(submitter)
}.to_json,
'Content-Type' => 'application/json',
'User-Agent' => USER_AGENT,
**webhook_url.secret.to_h)
end
end