mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: webhook for flag events
This commit is contained in:
@@ -68,6 +68,12 @@ module Jobs
|
||||
args[:payload] = TagSerializer.new(tag, scope: guardian, root: false).as_json
|
||||
end
|
||||
|
||||
def setup_flag(args)
|
||||
flag = PostAction.find(args[:flag_id])
|
||||
return if flag.blank?
|
||||
args[:payload] = WebHookFlagSerializer.new(flag, scope: guardian, root: false).as_json
|
||||
end
|
||||
|
||||
def ping_event?(event_type)
|
||||
event_type.to_s == 'ping'.freeze
|
||||
end
|
||||
|
||||
@@ -155,6 +155,7 @@ SQL
|
||||
|
||||
DiscourseEvent.trigger(:confirmed_spam_post, post) if trigger_spam
|
||||
DiscourseEvent.trigger(:flag_reviewed, post)
|
||||
DiscourseEvent.trigger(:flag_agreed, actions.first) if actions.first.present?
|
||||
|
||||
update_flagged_posts_count
|
||||
end
|
||||
@@ -188,6 +189,7 @@ SQL
|
||||
|
||||
Post.with_deleted.where(id: post.id).update_all(cached)
|
||||
DiscourseEvent.trigger(:flag_reviewed, post)
|
||||
DiscourseEvent.trigger(:flag_disagreed, actions.first) if actions.first.present?
|
||||
|
||||
update_flagged_posts_count
|
||||
end
|
||||
@@ -206,6 +208,7 @@ SQL
|
||||
end
|
||||
|
||||
DiscourseEvent.trigger(:flag_reviewed, post)
|
||||
DiscourseEvent.trigger(:flag_deferred, actions.first) if actions.first.present?
|
||||
update_flagged_posts_count
|
||||
end
|
||||
|
||||
@@ -306,6 +309,10 @@ SQL
|
||||
end
|
||||
end
|
||||
|
||||
if post_action && PostActionType.notify_flag_type_ids.include?(post_action_type_id)
|
||||
DiscourseEvent.trigger(:flag_created, post_action)
|
||||
end
|
||||
|
||||
GivenDailyLike.increment_for(user.id) if post_action_type_id == PostActionType.types[:like]
|
||||
|
||||
# agree with other flags
|
||||
|
||||
@@ -5,6 +5,7 @@ class WebHookEventType < ActiveRecord::Base
|
||||
GROUP = 4
|
||||
CATEGORY = 5
|
||||
TAG = 6
|
||||
FLAG = 7
|
||||
|
||||
has_and_belongs_to_many :web_hooks
|
||||
|
||||
|
||||
43
app/serializers/web_hook_flag_serializer.rb
Normal file
43
app/serializers/web_hook_flag_serializer.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
class WebHookFlagSerializer < ApplicationSerializer
|
||||
attributes :id,
|
||||
:post,
|
||||
:flag_type,
|
||||
:created_by,
|
||||
:created_at,
|
||||
:resolved_at,
|
||||
:resolved_by
|
||||
|
||||
def post
|
||||
BasicPostSerializer.new(object.post, scope: scope, root: false).as_json
|
||||
end
|
||||
|
||||
def flag_type
|
||||
object.post_action_type_key
|
||||
end
|
||||
|
||||
def include_post?
|
||||
object.post.present?
|
||||
end
|
||||
|
||||
def created_by
|
||||
object.user && object.user.username
|
||||
end
|
||||
|
||||
def resolved_at
|
||||
object.disposed_at
|
||||
end
|
||||
|
||||
def include_resolved_at?
|
||||
object.disposed_at.present?
|
||||
end
|
||||
|
||||
def resolved_by
|
||||
if object.disposed_by_id.present?
|
||||
User.find(object.disposed_by_id).username
|
||||
end
|
||||
end
|
||||
|
||||
def include_resolved_by?
|
||||
object.disposed_by_id.present?
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user