FIX: set notification level when changing post owner (#5616)

FIX: do not notify last post editor if they mention themself
This commit is contained in:
Maja Komel 2018-04-16 11:48:06 +02:00 committed by Gerhard Schlager
parent b602bab741
commit 3d99726981
4 changed files with 30 additions and 1 deletions

View File

@ -47,7 +47,7 @@ class PostAlerter
end
def after_save_post(post, new_record = false)
notified = [post.user]
notified = [post.user, post.last_editor].uniq
# mentions (users/groups)
mentioned_groups, mentioned_users = extract_mentions(post)

View File

@ -23,6 +23,12 @@ class PostOwnerChanger
post.set_owner(@new_owner, @acting_user, @skip_revision)
PostAction.remove_act(@new_owner, post, PostActionType.types[:like])
if post.post_number == 1
TopicUser.change(@new_owner.id, @topic.id, notification_level: NotificationLevels.topic_levels[:watching])
else
TopicUser.change(@new_owner.id, @topic.id, notification_level: NotificationLevels.topic_levels[:tracking])
end
@topic.update_statistics
@new_owner.user_stat.update(

View File

@ -410,6 +410,13 @@ describe PostAlerter do
expect(n.data_hash["original_username"]).to eq(admin.username)
end
it "doesn't notify the last post editor if they mention themself" do
post = create_post_with_alerts(user: user, raw: 'Post without a mention.')
expect {
post.revise(evil_trout, raw: "O hai, @eviltrout!")
}.not_to change(evil_trout.notifications, :count)
end
let(:alice) { Fabricate(:user, username: 'alice') }
let(:bob) { Fabricate(:user, username: 'bob') }
let(:carol) { Fabricate(:admin, username: 'carol') }

View File

@ -75,6 +75,22 @@ describe PostOwnerChanger do
expect(p1.reload.user).to eq(user_a)
end
context "sets topic notification level for the new owner" do
let(:p4) { Fabricate(:post, post_number: 2, topic_id: topic.id) }
it "'watching' if the first post gets a new owner" do
described_class.new(post_ids: [p1.id], topic_id: topic.id, new_owner: user_a, acting_user: editor).change_owner!
tu = TopicUser.find_by(user_id: user_a.id, topic_id: topic.id)
expect(tu.notification_level).to eq(3)
end
it "'tracking' if other than the first post gets a new owner" do
described_class.new(post_ids: [p4.id], topic_id: topic.id, new_owner: user_a, acting_user: editor).change_owner!
tu = TopicUser.find_by(user_id: user_a.id, topic_id: topic.id)
expect(tu.notification_level).to eq(2)
end
end
context "integration tests" do
let(:p1user) { p1.user }
let(:p2user) { p2.user }