A platform for community discussion. Free, open, simple.
FIX: set notification level when changing post owner (#5616)
Maja Komel3d99726981da
diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rbindex 44973d7adf8..2c30ada8185 100644--- a/app/services/post_alerter.rb+++ b/app/services/post_alerter.rb@@ -47,7 +47,7 @@ class PostAlerterenddef 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)diff --git a/app/services/post_owner_changer.rb b/app/services/post_owner_changer.rbindex 4e2d894cbec..8d4e261e8b8 100644--- a/app/services/post_owner_changer.rb+++ b/app/services/post_owner_changer.rb@@ -23,6 +23,12 @@ class PostOwnerChangerpost.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(diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rbindex e36d603df0c..20b6e8a7785 100644--- a/spec/services/post_alerter_spec.rb+++ b/spec/services/post_alerter_spec.rb@@ -410,6 +410,13 @@ describe PostAlerter doexpect(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') }diff --git a/spec/services/post_owner_changer_spec.rb b/spec/services/post_owner_changer_spec.rbindex e462bbe9bd7..5ad9d8af574 100644--- a/spec/services/post_owner_changer_spec.rb+++ b/spec/services/post_owner_changer_spec.rb@@ -75,6 +75,22 @@ describe PostOwnerChanger doexpect(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" dolet(:p1user) { p1.user }let(:p2user) { p2.user }