2022-05-28 11:03:36 +02:00
|
|
|
class PostStatusChange < ApplicationRecord
|
2022-07-18 10:47:54 +02:00
|
|
|
include TenantOwnable
|
|
|
|
|
|
2022-05-28 11:03:36 +02:00
|
|
|
belongs_to :user
|
|
|
|
|
belongs_to :post
|
|
|
|
|
belongs_to :post_status, optional: true
|
2024-12-20 14:06:48 +01:00
|
|
|
|
|
|
|
|
after_create :run_webhooks
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def run_webhooks
|
|
|
|
|
entities = {
|
|
|
|
|
post: self.post.id,
|
|
|
|
|
board: self.post.board.id
|
|
|
|
|
}
|
|
|
|
|
entities[:post_author] = self.post.user.id if self.post.user_id
|
|
|
|
|
entities[:post_status] = self.post_status.id if self.post_status_id
|
|
|
|
|
|
|
|
|
|
Webhook.where(trigger: :post_status_change, is_enabled: true).each do |webhook|
|
|
|
|
|
RunWebhook.perform_later(
|
|
|
|
|
webhook_id: webhook.id,
|
|
|
|
|
current_tenant_id: Current.tenant.id,
|
|
|
|
|
entities: entities
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-05-28 11:03:36 +02:00
|
|
|
end
|