mirror of
https://github.com/discourse/discourse.git
synced 2026-08-11 02:59:07 +08:00
## Summary Align private-message read receipts with recipient-group visibility settings. `PostReadersController#ensure_can_see_readers!` (`app/controllers/post_readers_controller.rb:42`) now returns reader details only when the requester can view the membership of every recipient group and belongs to a group with read-state publishing enabled. `TopicView#show_read_indicator?` (`lib/topic_view.rb:297`) applies the same visibility rule to the UI. Realtime `:read` events from `TopicTrackingState.trigger_post_read_count_update` (`app/models/topic_tracking_state.rb:600`) continue to publish `readers_count`, but no longer include `reader_id`. Reader identities remain available through the authorized `/post_readers.json` endpoint. Tests cover group private messages with restricted member visibility. ## Source - Patch Triage: https://patch.discourse.org/patch-triage/1151 Co-authored-by: discourse-patch-triage <272280883+discourse-patch-triage[bot]@users.noreply.github.com>
54 lines
1.4 KiB
Ruby
Vendored
54 lines
1.4 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class PostReadersController < ApplicationController
|
|
requires_login
|
|
|
|
def index
|
|
post = Post.includes(topic: %i[topic_allowed_groups topic_allowed_users]).find(params[:id])
|
|
guardian.ensure_can_see!(post)
|
|
ensure_can_see_readers!(post)
|
|
|
|
readers =
|
|
User
|
|
.real
|
|
.where(staged: false)
|
|
.where.not(id: post.user_id)
|
|
.joins(:topic_users)
|
|
.where.not(topic_users: { last_read_post_number: nil })
|
|
.where(
|
|
"topic_users.topic_id = ? AND topic_users.last_read_post_number >= ?",
|
|
post.topic_id,
|
|
post.post_number,
|
|
)
|
|
|
|
readers = readers.where("admin OR moderator") if post.whisper?
|
|
|
|
readers =
|
|
readers.map do |r|
|
|
{
|
|
id: r.id,
|
|
avatar_template: r.avatar_template,
|
|
username: r.username,
|
|
username_lower: r.username_lower,
|
|
}
|
|
end
|
|
|
|
render_json_dump(post_readers: readers)
|
|
end
|
|
|
|
private
|
|
|
|
def ensure_can_see_readers!(post)
|
|
allowed_groups = post.topic.allowed_groups.to_a
|
|
|
|
show_readers =
|
|
allowed_groups.all? { |group| guardian.can_see_group_members?(group) } &&
|
|
GroupUser
|
|
.where(user: current_user)
|
|
.joins(:group)
|
|
.where(groups: { id: allowed_groups.map(&:id), publish_read_state: true })
|
|
.exists?
|
|
|
|
raise Discourse::InvalidAccess unless show_readers
|
|
end
|
|
end
|