mirror of https://github.com/docusealco/docuseal
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
863 B
28 lines
863 B
# frozen_string_literal: true
|
|
|
|
module WebhookUrls
|
|
module_function
|
|
|
|
def for_account_id(account_id, events)
|
|
events = Array.wrap(events)
|
|
|
|
rel = WebhookUrl.where(account_id:)
|
|
|
|
event_arel = events.map { |event| Arel::Table.new(:webhook_urls)[:events].matches("%\"#{event}\"%") }.reduce(:or)
|
|
|
|
if Docuseal.multitenant?
|
|
rel.where(event_arel)
|
|
else
|
|
linked_account_rel =
|
|
AccountLinkedAccount.where(linked_account_id: account_id).where.not(account_type: :testing).select(:account_id)
|
|
|
|
webhook_urls = rel.or(WebhookUrl.where(account_id: linked_account_rel).where(event_arel))
|
|
|
|
account_urls, linked_urls = webhook_urls.partition { |w| w.account_id == account_id }
|
|
|
|
account_urls.select { |w| w.events.intersect?(events) }.presence ||
|
|
(account_urls.present? ? WebhookUrl.none : linked_urls)
|
|
end
|
|
end
|
|
end
|