FIX: ensures `all_mentioned_user_ids` is not used as identifier (#21491)

A follow-up to 54b2a85b. That commit didn't fix the issue because the to_notify hash that we return from the notify_edit method isn't used anywhere apart from tests (that's confusing, we're going to fix that soon).
This commit is contained in:
Andrei Prigorshnev 2023-05-12 17:47:48 +04:00 committed by GitHub
parent c1cde16966
commit b85d057df4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -89,13 +89,14 @@ module Chat
.pluck(:user_id)
to_notify = list_users_to_notify
needs_notification_ids = to_notify[:all_mentioned_user_ids] - already_notified_user_ids
mentioned_user_ids = to_notify.extract!(:all_mentioned_user_ids)[:all_mentioned_user_ids]
needs_notification_ids = mentioned_user_ids - already_notified_user_ids
return if needs_notification_ids.blank?
notify_creator_of_inaccessible_mentions(to_notify)
notify_mentioned_users(to_notify, already_notified_user_ids: already_notified_user_ids)
to_notify.except(:all_mentioned_user_ids)
to_notify
end
private

View File

@ -124,7 +124,8 @@ describe Chat::Notifier do
describe "editing a direct mention into a global mention" do
let(:mention) { "hello @#{user_2.username}!" }
it "doesn't return :all_mentioned_user_ids" do
it "doesn't send notifications with :all_mentioned_user_ids as an identifier" do
Jobs.run_immediately!
msg = build_cooked_msg(mention, user_1)
Chat::MessageUpdater.update(
@ -133,8 +134,12 @@ describe Chat::Notifier do
new_content: "hello @all",
)
to_notify = described_class.new(msg, msg.created_at).notify_edit
expect(to_notify[:all_mentioned_user_ids]).not_to be_present
described_class.new(msg, msg.created_at).notify_edit
notifications = Notification.where(user: user_2)
notifications.each do |notification|
expect(notification.data).not_to include("\"identifier\":\"all_mentioned_user_ids\"")
end
end
end