2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-03-31 12:58:56 -04:00
|
|
|
class NewPostResultSerializer < ApplicationSerializer
|
|
|
|
attributes :action,
|
|
|
|
:post,
|
|
|
|
:errors,
|
2015-04-24 15:44:59 -04:00
|
|
|
:success,
|
2015-04-28 15:06:27 -04:00
|
|
|
:pending_count,
|
2019-11-29 09:30:54 -05:00
|
|
|
:reason,
|
|
|
|
:message,
|
|
|
|
:route_to
|
2015-03-31 12:58:56 -04:00
|
|
|
|
2019-04-12 09:55:27 -04:00
|
|
|
has_one :pending_post, serializer: TopicPendingPostSerializer, root: false, embed: :objects
|
|
|
|
|
2015-03-31 12:58:56 -04:00
|
|
|
def post
|
2021-06-18 09:26:57 -04:00
|
|
|
post_serializer = PostSerializer.new(object.post, scope: scope, root: false, add_raw: true)
|
2015-03-31 12:58:56 -04:00
|
|
|
post_serializer.draft_sequence = DraftSequence.current(scope.user, object.post.topic.draft_key)
|
|
|
|
post_serializer.as_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_post?
|
|
|
|
object.post.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def success
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_success?
|
|
|
|
@object.success?
|
|
|
|
end
|
|
|
|
|
|
|
|
def errors
|
|
|
|
object.errors.full_messages
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_errors?
|
|
|
|
!object.errors.empty?
|
|
|
|
end
|
|
|
|
|
2015-04-28 15:06:27 -04:00
|
|
|
def reason
|
|
|
|
object.reason
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_reason?
|
2019-04-12 09:55:27 -04:00
|
|
|
scope.is_staff? && reason.present?
|
2015-04-28 15:06:27 -04:00
|
|
|
end
|
|
|
|
|
2015-03-31 12:58:56 -04:00
|
|
|
def action
|
|
|
|
object.action
|
|
|
|
end
|
|
|
|
|
2015-04-24 15:44:59 -04:00
|
|
|
def pending_count
|
|
|
|
object.pending_count
|
|
|
|
end
|
|
|
|
|
2019-04-12 09:55:27 -04:00
|
|
|
def pending_post
|
|
|
|
object.reviewable
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_pending_post?
|
|
|
|
object.reviewable.present?
|
|
|
|
end
|
|
|
|
|
2015-04-24 15:44:59 -04:00
|
|
|
def include_pending_count?
|
|
|
|
pending_count.present?
|
|
|
|
end
|
|
|
|
|
2019-11-29 09:30:54 -05:00
|
|
|
def route_to
|
|
|
|
object.route_to
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_route_to?
|
|
|
|
object.route_to.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
|
|
|
object.message
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_message?
|
|
|
|
object.message.present?
|
|
|
|
end
|
|
|
|
|
2015-03-31 12:58:56 -04:00
|
|
|
end
|