mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 05:42:36 +08:00
## Summary Correctly skip moved-post notification creation for recipients who lack visibility of the destination topic. The live notification channel now only publishes moved-post metadata to authors who can actually access the destination, preventing disclosure of restricted topic titles through the real-time notification stream. ## Source - Patch Triage: https://patch.discourse.org/patch-triage/1550 Co-authored-by: discourse-patch-triage <272280883+discourse-patch-triage[bot]@users.noreply.github.com>
35 lines
1.1 KiB
Ruby
Vendored
35 lines
1.1 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class NotifyMovedPosts < ::Jobs::Base
|
|
def execute(args)
|
|
raise Discourse::InvalidParameters.new(:post_ids) if args[:post_ids].blank?
|
|
raise Discourse::InvalidParameters.new(:moved_by_id) if args[:moved_by_id].blank?
|
|
|
|
posts =
|
|
Post
|
|
.includes(:user, :topic)
|
|
.where(id: args[:post_ids])
|
|
.where.not(user_id: args[:moved_by_id])
|
|
.order(post_number: :asc)
|
|
return if posts.blank?
|
|
|
|
moved_by = User.find_by(id: args[:moved_by_id])
|
|
|
|
# Make sure we don't notify the same user twice (in case multiple posts were moved at once.)
|
|
users_notified = Set.new
|
|
posts.each do |p|
|
|
next if users_notified.include?(p.user_id)
|
|
next if !p.user.guardian.can_see?(p.topic)
|
|
|
|
p.user.notifications.create(
|
|
notification_type: Notification.types[:moved_post],
|
|
topic_id: p.topic_id,
|
|
post_number: p.post_number,
|
|
data: { topic_title: p.topic.title, display_username: moved_by.username }.to_json,
|
|
)
|
|
users_notified << p.user_id
|
|
end
|
|
end
|
|
end
|
|
end
|