2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-05 16:53:59 +08:00
|
|
|
module HasDestroyedWebHook
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included { around_destroy :enqueue_destroyed_web_hook }
|
|
|
|
|
|
|
|
def enqueue_destroyed_web_hook
|
|
|
|
type = self.class.name.underscore.to_sym
|
2019-02-19 15:13:08 +08:00
|
|
|
|
2023-10-09 11:35:31 +08:00
|
|
|
if WebHook.active_web_hooks("#{type}_destroyed").exists?
|
2019-02-19 15:13:08 +08:00
|
|
|
payload = WebHook.generate_payload(type, self)
|
|
|
|
yield
|
|
|
|
WebHook.enqueue_hooks(type, "#{type}_destroyed".to_sym, id: id, payload: payload)
|
|
|
|
else
|
|
|
|
yield
|
|
|
|
end
|
2018-10-05 16:53:59 +08:00
|
|
|
end
|
|
|
|
end
|