FIX: correct edit notification username for PMs (#9649)

When the tag is added to PM by admin, notification has an incorrect username (post author username instead of admin username)
This commit is contained in:
Krzysztof Kotlarek 2020-05-07 07:52:21 +10:00 committed by GitHub
parent ec2f3169ff
commit 05799538e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -628,7 +628,9 @@ class PostAlerter
each_user_in_batches(notify) do |user|
notification_type = already_seen_user_ids.include?(user.id) ? Notification.types[:edited] : Notification.types[:posted]
create_notification(user, notification_type, post)
opts = {}
opts[:display_username] = post.last_editor.username if notification_type == Notification.types[:edited]
create_notification(user, notification_type, post, opts)
end
end

View File

@ -1128,12 +1128,16 @@ describe PostAlerter do
describe '#notify_post_users' do
fab!(:topic) { Fabricate(:topic) }
fab!(:post) { Fabricate(:post, topic: topic) }
fab!(:last_editor) { Fabricate(:user) }
fab!(:tag) { Fabricate(:tag) }
it 'creates single edit notification when post is modified' do
TopicUser.create!(user_id: user.id, topic_id: topic.id, notification_level: TopicUser.notification_levels[:watching], highest_seen_post_number: post.post_number)
PostRevisor.new(post).revise!(last_editor, tags: [tag.name])
PostAlerter.new.notify_post_users(post, [])
expect(Notification.count).to eq(1)
expect(Notification.last.notification_type).to eq(Notification.types[:edited])
expect(JSON.parse(Notification.last.data)["display_username"]).to eq(last_editor.username)
PostAlerter.new.notify_post_users(post, [])
expect(Notification.count).to eq(1)