mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-04 05:09:20 +08:00
Followup 5ec959c72c
Since Rewinds can be public, we also need to limit the following:
* Do not show tags in restricted groups for Most Vierwed Tags. Instead,
only show tags that anon will be able to see, so tags with no or
low permissions.
* Do not show Most Viewed Categories that are restricted categories
* Do not show whispers in Best Posts
65 lines
2 KiB
Ruby
65 lines
2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseRewind
|
|
module Action
|
|
class BestPosts < BaseReport
|
|
FakeData = {
|
|
data: [
|
|
{
|
|
post_number: 5,
|
|
topic_id: 42,
|
|
like_count: 23,
|
|
reply_count: 8,
|
|
excerpt: "This is a great explanation of how ActiveRecord works under the hood...",
|
|
},
|
|
{
|
|
post_number: 12,
|
|
topic_id: 89,
|
|
like_count: 19,
|
|
reply_count: 5,
|
|
excerpt:
|
|
"Here's a comprehensive guide to testing Rails applications with RSpec and system tests...",
|
|
},
|
|
{
|
|
post_number: 3,
|
|
topic_id: 156,
|
|
like_count: 15,
|
|
reply_count: 12,
|
|
excerpt:
|
|
"The key to understanding PostgreSQL performance is looking at your query plans...",
|
|
},
|
|
],
|
|
identifier: "best-posts",
|
|
}
|
|
|
|
def call
|
|
return FakeData if should_use_fake_data?
|
|
|
|
best_posts =
|
|
Post
|
|
.public_posts
|
|
.joins(topic: :category)
|
|
.where(user_id: user.id)
|
|
.where(posts: { created_at: date, deleted_at: nil })
|
|
.where("post_number > 1")
|
|
.where("NOT categories.read_restricted")
|
|
.where.not(post_type: Post.types[:whisper])
|
|
.order("like_count DESC NULLS LAST, posts.created_at ASC")
|
|
.limit(3)
|
|
.select(:post_number, :topic_id, :like_count, :reply_count, :raw, :cooked)
|
|
.map do |post|
|
|
{
|
|
post_number: post.post_number,
|
|
topic_id: post.topic_id,
|
|
like_count: post.like_count,
|
|
reply_count: post.reply_count,
|
|
excerpt:
|
|
post.excerpt(200, { strip_links: true, remap_emoji: true, keep_images: true }),
|
|
}
|
|
end
|
|
|
|
{ data: best_posts, identifier: "best-posts" }
|
|
end
|
|
end
|
|
end
|
|
end
|