Add report.updated webhook (#24211)

shrike
Vyr Cossont 2023-07-24 08:37:38 -07:00 committed by GitHub
parent 173a268025
commit 394d1f19b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -58,7 +58,8 @@ class Report < ApplicationRecord
before_validation :set_uri, only: :create before_validation :set_uri, only: :create
after_create_commit :trigger_webhooks after_create_commit :trigger_create_webhooks
after_update_commit :trigger_update_webhooks
def object_type def object_type
:flag :flag
@ -155,7 +156,11 @@ class Report < ApplicationRecord
errors.add(:rule_ids, I18n.t('reports.errors.invalid_rules')) unless rules.size == rule_ids&.size errors.add(:rule_ids, I18n.t('reports.errors.invalid_rules')) unless rules.size == rule_ids&.size
end end
def trigger_webhooks def trigger_create_webhooks
TriggerWebhookWorker.perform_async('report.created', 'Report', id) TriggerWebhookWorker.perform_async('report.created', 'Report', id)
end end
def trigger_update_webhooks
TriggerWebhookWorker.perform_async('report.updated', 'Report', id)
end
end end

View File

@ -20,6 +20,7 @@ class Webhook < ApplicationRecord
account.created account.created
account.updated account.updated
report.created report.created
report.updated
status.created status.created
status.updated status.updated
).freeze ).freeze
@ -59,7 +60,7 @@ class Webhook < ApplicationRecord
case event case event
when 'account.approved', 'account.created', 'account.updated' when 'account.approved', 'account.created', 'account.updated'
:manage_users :manage_users
when 'report.created' when 'report.created', 'report.updated'
:manage_reports :manage_reports
when 'status.created', 'status.updated' when 'status.created', 'status.updated'
:view_devops :view_devops