Skip to content

Commit

Permalink
Add report.updated webhook (mastodon#24211)
Browse files Browse the repository at this point in the history
  • Loading branch information
VyrCossont authored Jul 24, 2023
1 parent 173a268 commit 394d1f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions app/models/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class Report < ApplicationRecord

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
:flag
Expand Down Expand Up @@ -155,7 +156,11 @@ def validate_rule_ids
errors.add(:rule_ids, I18n.t('reports.errors.invalid_rules')) unless rules.size == rule_ids&.size
end

def trigger_webhooks
def trigger_create_webhooks
TriggerWebhookWorker.perform_async('report.created', 'Report', id)
end

def trigger_update_webhooks
TriggerWebhookWorker.perform_async('report.updated', 'Report', id)
end
end
3 changes: 2 additions & 1 deletion app/models/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Webhook < ApplicationRecord
account.created
account.updated
report.created
report.updated
status.created
status.updated
).freeze
Expand Down Expand Up @@ -59,7 +60,7 @@ def self.permission_for_event(event)
case event
when 'account.approved', 'account.created', 'account.updated'
:manage_users
when 'report.created'
when 'report.created', 'report.updated'
:manage_reports
when 'status.created', 'status.updated'
:view_devops
Expand Down

0 comments on commit 394d1f1

Please sign in to comment.