mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-21 16:06:12 +08:00
Related:
40fd82e2d1
This PR introduces three new plugin modifiers attached to
- `basic_post_serializer.cooked`
- `basic_topic_serializer.fancy_title`
- `topic_view_serializer.fancy_title`
Implementation note: I had wanted to add them in the `Post` and `Topic`
models themselves, but they do not directly provide access to the
request's scope which is needed for the use case.
55 lines
1.2 KiB
Ruby
Vendored
55 lines
1.2 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
# 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
|
|
|
|
attr_accessor :topic_view
|
|
|
|
def name
|
|
object.user && object.user.name
|
|
end
|
|
|
|
def username
|
|
object.user && object.user.username
|
|
end
|
|
|
|
def avatar_template
|
|
object.user && object.user.avatar_template
|
|
end
|
|
|
|
def cooked_hidden
|
|
object.hidden && !scope.is_staff?
|
|
end
|
|
|
|
def include_cooked_hidden?
|
|
cooked_hidden
|
|
end
|
|
|
|
def cooked
|
|
if cooked_hidden
|
|
if scope.current_user && object.user_id == scope.current_user.id
|
|
I18n.t("flagging.you_must_edit", path: "/my/messages")
|
|
else
|
|
I18n.t("flagging.user_must_edit")
|
|
end
|
|
else
|
|
cooked = object.filter_quotes(@parent_post)
|
|
modified = DiscoursePluginRegistry.apply_modifier(:basic_post_serializer_cooked, cooked, self)
|
|
modified || cooked
|
|
end
|
|
end
|
|
|
|
def include_name?
|
|
SiteSetting.enable_names?
|
|
end
|
|
|
|
def post_custom_fields
|
|
@post_custom_fields ||=
|
|
if @topic_view
|
|
(@topic_view.post_custom_fields || {})[object.id] || {}
|
|
else
|
|
object.custom_fields
|
|
end
|
|
end
|
|
end
|