discourse/app/serializers/web_hook_flag_serializer.rb
Robin Ward b58867b6e9 FEATURE: New 'Reviewable' model to make reviewable items generic
Includes support for flags, reviewable users and queued posts, with REST API
backwards compatibility.

Co-Authored-By: romanrizzi <romanalejandro@gmail.com>
Co-Authored-By: jjaffeux <j.jaffeux@gmail.com>
2019-03-28 12:45:10 -04:00

48 lines
881 B
Ruby

class WebHookFlagSerializer < ApplicationSerializer
attributes :id,
:post,
:flag_type,
:created_by,
:created_at,
:resolved_at,
:resolved_by
def post
WebHookPostSerializer.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.disagreed_at || object.agreed_at || object.deferred_at
end
def include_resolved_at?
resolved_at.present?
end
def resolved_by
User.find(disposed_by_id).username
end
def include_resolved_by?
disposed_by_id.present?
end
protected
def disposed_by_id
object.disagreed_by_id || object.agreed_by_id || object.deferred_by_id
end
end