mirror of
https://github.com/discourse/discourse-solved.git
synced 2025-07-12 00:13:27 +00:00
In https://github.com/discourse/discourse-solved/pull/342 we moved solutions away from topic_custom_fields into proper tables, with the tables as the proper source of truth to a topic's solution. The user's /my/activity/solved route uses user_actions which is not accurate, and a user has reported a bug where their solution is not reflected there (user actions are not a good representation of what a topic's solution is). This commit introduces - a new route to get solutions, and is mindful `hide_user_profiles_from_public` and such settings - also mindful of PMs and private categories - a new template that makes use of the `<UserStream>` to load posts safely and avoid reimplementation
88 lines
1.3 KiB
Ruby
88 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class DiscourseSolved::SolvedPostSerializer < ApplicationSerializer
|
|
attributes :created_at,
|
|
:archived,
|
|
:avatar_template,
|
|
:category_id,
|
|
:closed,
|
|
:cooked,
|
|
:excerpt,
|
|
:name,
|
|
:post_id,
|
|
:post_number,
|
|
:post_type,
|
|
:raw,
|
|
:slug,
|
|
:topic_id,
|
|
:topic_title,
|
|
:truncated,
|
|
:url,
|
|
:user_id,
|
|
:username
|
|
|
|
def archived
|
|
object.topic.archived
|
|
end
|
|
|
|
def avatar_template
|
|
object.user&.avatar_template
|
|
end
|
|
|
|
def category_id
|
|
object.topic.category_id
|
|
end
|
|
|
|
def closed
|
|
object.topic.closed
|
|
end
|
|
|
|
def excerpt
|
|
@excerpt ||= PrettyText.excerpt(cooked, 300, keep_emoji_images: true)
|
|
end
|
|
|
|
def name
|
|
object.user&.name
|
|
end
|
|
|
|
def include_name?
|
|
SiteSetting.enable_names?
|
|
end
|
|
|
|
def post_id
|
|
object.id
|
|
end
|
|
|
|
def slug
|
|
Slug.for(object.topic.title)
|
|
end
|
|
|
|
def include_slug?
|
|
object.topic.title.present?
|
|
end
|
|
|
|
def topic_title
|
|
object.topic.title
|
|
end
|
|
|
|
def truncated
|
|
true
|
|
end
|
|
|
|
def include_truncated?
|
|
cooked.length > 300
|
|
end
|
|
|
|
def url
|
|
"#{Discourse.base_url}#{object.url}"
|
|
end
|
|
|
|
def user_id
|
|
object.user_id
|
|
end
|
|
|
|
def username
|
|
object.user&.username
|
|
end
|
|
end
|