2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-06-28 13:55:34 -04:00
|
|
|
# The most basic attributes of a topic that we need to create a link for it.
|
|
|
|
class BasicPostSerializer < ApplicationSerializer
|
|
|
|
attributes :id, :name, :username, :avatar_template, :created_at, :cooked, :cooked_hidden
|
|
|
|
|
2019-08-19 03:20:56 -04:00
|
|
|
attr_accessor :topic_view
|
|
|
|
|
2013-06-28 13:55:34 -04:00
|
|
|
def name
|
2015-10-02 01:00:00 -04:00
|
|
|
object.user && object.user.name
|
2013-06-28 13:55:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def username
|
2015-10-02 01:00:00 -04:00
|
|
|
object.user && object.user.username
|
2013-06-28 13:55:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def avatar_template
|
2015-10-02 01:00:00 -04:00
|
|
|
object.user && object.user.avatar_template
|
2013-06-28 13:55:34 -04:00
|
|
|
end
|
|
|
|
|
2014-06-20 17:06:44 -04:00
|
|
|
def cooked_hidden
|
|
|
|
object.hidden && !scope.is_staff?
|
|
|
|
end
|
2015-09-10 20:12:40 -04:00
|
|
|
|
2014-06-20 17:06:44 -04:00
|
|
|
def include_cooked_hidden?
|
|
|
|
cooked_hidden
|
|
|
|
end
|
|
|
|
|
2013-06-28 13:55:34 -04:00
|
|
|
def cooked
|
2014-06-20 17:06:44 -04:00
|
|
|
if cooked_hidden
|
2013-06-28 13:55:34 -04:00
|
|
|
if scope.current_user && object.user_id == scope.current_user.id
|
2017-10-30 00:47:34 -04:00
|
|
|
I18n.t("flagging.you_must_edit", path: "/my/messages")
|
2013-06-28 13:55:34 -04:00
|
|
|
else
|
|
|
|
I18n.t("flagging.user_must_edit")
|
|
|
|
end
|
|
|
|
else
|
2020-03-24 05:12:52 -04:00
|
|
|
object.filter_quotes(@parent_post)
|
2013-06-28 13:55:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-30 15:45:13 -04:00
|
|
|
def include_name?
|
|
|
|
SiteSetting.enable_names?
|
|
|
|
end
|
|
|
|
|
2019-08-19 03:20:56 -04:00
|
|
|
def post_custom_fields
|
|
|
|
@post_custom_fields ||=
|
|
|
|
if @topic_view
|
|
|
|
(@topic_view.post_custom_fields || {})[object.id] || {}
|
|
|
|
else
|
|
|
|
object.custom_fields
|
|
|
|
end
|
|
|
|
end
|
2013-06-28 13:55:34 -04:00
|
|
|
end
|