Add administrative webhooks (#18510)
* Add administrative webhooks * Fix error when webhook is deleted before delivery worker runs
This commit is contained in:
parent
17ba5e1e61
commit
a2871cd747
33 changed files with 530 additions and 8 deletions
22
app/services/webhook_service.rb
Normal file
22
app/services/webhook_service.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class WebhookService < BaseService
|
||||
def call(event, object)
|
||||
@event = Webhooks::EventPresenter.new(event, object)
|
||||
@body = serialize_event
|
||||
|
||||
webhooks_for_event.each do |webhook_id|
|
||||
Webhooks::DeliveryWorker.perform_async(webhook_id, @body)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def webhooks_for_event
|
||||
Webhook.enabled.where('? = ANY(events)', @event.type).pluck(:id)
|
||||
end
|
||||
|
||||
def serialize_event
|
||||
Oj.dump(ActiveModelSerializers::SerializableResource.new(@event, serializer: REST::Admin::WebhookEventSerializer, scope: nil, scope_name: :current_user).as_json)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue