mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 12:02:46 +08:00
FIX: only show participants the user can see
This commit is contained in:
parent
e5db126a8e
commit
0096ee40da
|
@ -21,7 +21,6 @@ class TopicViewSerializer < ApplicationSerializer
|
||||||
:created_at,
|
:created_at,
|
||||||
:views,
|
:views,
|
||||||
:reply_count,
|
:reply_count,
|
||||||
:participant_count,
|
|
||||||
:like_count,
|
:like_count,
|
||||||
:last_posted_at,
|
:last_posted_at,
|
||||||
:visible,
|
:visible,
|
||||||
|
@ -35,17 +34,18 @@ class TopicViewSerializer < ApplicationSerializer
|
||||||
:deleted_at,
|
:deleted_at,
|
||||||
:pending_posts_count,
|
:pending_posts_count,
|
||||||
:user_id,
|
:user_id,
|
||||||
:pm_with_non_human_user?
|
:pm_with_non_human_user?,
|
||||||
|
:featured_link,
|
||||||
|
:pinned_globally,
|
||||||
|
:pinned_at,
|
||||||
|
:pinned_until
|
||||||
|
|
||||||
attributes :draft,
|
attributes :draft,
|
||||||
:draft_key,
|
:draft_key,
|
||||||
:draft_sequence,
|
:draft_sequence,
|
||||||
:posted,
|
:posted,
|
||||||
:unpinned,
|
:unpinned,
|
||||||
:pinned_globally,
|
:pinned,
|
||||||
:pinned, # Is topic pinned and viewer hasn't cleared the pin?
|
|
||||||
:pinned_at, # Ignores clear pin
|
|
||||||
:pinned_until,
|
|
||||||
:details,
|
:details,
|
||||||
:highest_post_number,
|
:highest_post_number,
|
||||||
:last_read_post_number,
|
:last_read_post_number,
|
||||||
|
@ -59,10 +59,10 @@ class TopicViewSerializer < ApplicationSerializer
|
||||||
:bookmarked,
|
:bookmarked,
|
||||||
:message_archived,
|
:message_archived,
|
||||||
:tags,
|
:tags,
|
||||||
:featured_link,
|
|
||||||
:topic_timer,
|
:topic_timer,
|
||||||
:unicode_title,
|
:unicode_title,
|
||||||
:message_bus_last_id
|
:message_bus_last_id,
|
||||||
|
:participant_count
|
||||||
|
|
||||||
# TODO: Split off into proper object / serializer
|
# TODO: Split off into proper object / serializer
|
||||||
def details
|
def details
|
||||||
|
@ -193,10 +193,6 @@ class TopicViewSerializer < ApplicationSerializer
|
||||||
end
|
end
|
||||||
alias_method :include_posted?, :has_topic_user?
|
alias_method :include_posted?, :has_topic_user?
|
||||||
|
|
||||||
def pinned_globally
|
|
||||||
object.topic.pinned_globally
|
|
||||||
end
|
|
||||||
|
|
||||||
def pinned
|
def pinned
|
||||||
PinnedCheck.pinned?(object.topic, object.topic_user)
|
PinnedCheck.pinned?(object.topic, object.topic_user)
|
||||||
end
|
end
|
||||||
|
@ -205,14 +201,6 @@ class TopicViewSerializer < ApplicationSerializer
|
||||||
PinnedCheck.unpinned?(object.topic, object.topic_user)
|
PinnedCheck.unpinned?(object.topic, object.topic_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pinned_at
|
|
||||||
object.topic.pinned_at
|
|
||||||
end
|
|
||||||
|
|
||||||
def pinned_until
|
|
||||||
object.topic.pinned_until
|
|
||||||
end
|
|
||||||
|
|
||||||
def actions_summary
|
def actions_summary
|
||||||
result = []
|
result = []
|
||||||
return [] unless post = object.posts&.first
|
return [] unless post = object.posts&.first
|
||||||
|
@ -243,7 +231,7 @@ class TopicViewSerializer < ApplicationSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def bookmarked
|
def bookmarked
|
||||||
object.topic_user.try(:bookmarked)
|
object.topic_user&.bookmarked
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_pending_posts_count?
|
def include_pending_posts_count?
|
||||||
|
@ -266,10 +254,6 @@ class TopicViewSerializer < ApplicationSerializer
|
||||||
SiteSetting.topic_featured_link_enabled
|
SiteSetting.topic_featured_link_enabled
|
||||||
end
|
end
|
||||||
|
|
||||||
def featured_link
|
|
||||||
object.topic.featured_link
|
|
||||||
end
|
|
||||||
|
|
||||||
def include_unicode_title?
|
def include_unicode_title?
|
||||||
!!(object.topic.title =~ /:([\w\-+]*):/)
|
!!(object.topic.title =~ /:([\w\-+]*):/)
|
||||||
end
|
end
|
||||||
|
@ -282,6 +266,10 @@ class TopicViewSerializer < ApplicationSerializer
|
||||||
private_message?(object.topic)
|
private_message?(object.topic)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def participant_count
|
||||||
|
object.participants.size
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def private_message?(topic)
|
def private_message?(topic)
|
||||||
|
|
|
@ -276,18 +276,21 @@ class TopicView
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_counts_by_user
|
def post_counts_by_user
|
||||||
@post_counts_by_user ||= Post.where(topic_id: @topic.id)
|
@post_counts_by_user ||= begin
|
||||||
.where("user_id IS NOT NULL")
|
return {} if @posts.blank?
|
||||||
.group(:user_id)
|
Post.where(id: @posts.pluck(:id))
|
||||||
.order("count_all DESC")
|
.where("user_id IS NOT NULL")
|
||||||
.limit(24)
|
.group(:user_id)
|
||||||
.count
|
.order("count_all DESC")
|
||||||
|
.limit(24)
|
||||||
|
.count
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def participants
|
def participants
|
||||||
@participants ||= begin
|
@participants ||= begin
|
||||||
participants = {}
|
participants = {}
|
||||||
User.where(id: post_counts_by_user.map { |k, v| k }).includes(:primary_group).each { |u| participants[u.id] = u }
|
User.where(id: post_counts_by_user.keys).includes(:primary_group).each { |u| participants[u.id] = u }
|
||||||
participants
|
participants
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -160,13 +160,18 @@ describe TopicView do
|
||||||
end
|
end
|
||||||
|
|
||||||
context '.post_counts_by_user' do
|
context '.post_counts_by_user' do
|
||||||
it 'returns the two posters with their counts' do
|
it 'returns the two posters with their appropriate counts' do
|
||||||
expect(topic_view.post_counts_by_user.to_a).to match_array([[first_poster.id, 2], [coding_horror.id, 1]])
|
Fabricate(:post, topic: topic, user: coding_horror, post_type: Post.types[:whisper])
|
||||||
|
|
||||||
|
expect(topic_view.post_counts_by_user.to_a).to match_array([[first_poster.id, 2], [coding_horror.id, 2]])
|
||||||
|
|
||||||
|
expect(TopicView.new(topic.id, first_poster).post_counts_by_user.to_a).to match_array([[first_poster.id, 2], [coding_horror.id, 1]])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't return counts for posts with authors who have been deleted" do
|
it "doesn't return counts for posts with authors who have been deleted" do
|
||||||
p2.user_id = nil
|
p2.user_id = nil
|
||||||
p2.save!
|
p2.save!
|
||||||
|
|
||||||
expect(topic_view.post_counts_by_user.to_a).to match_array([[first_poster.id, 2]])
|
expect(topic_view.post_counts_by_user.to_a).to match_array([[first_poster.id, 2]])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user