A platform for community discussion. Free, open, simple.
FIX: topic owner should watch the new topic when moving posts to a new topic
OsamaSayegh547b571d8422
diff --git a/app/models/post_mover.rb b/app/models/post_mover.rbindex 1e18ea3d3e9..ec4cb3f02f0 100644--- a/app/models/post_mover.rb+++ b/app/models/post_mover.rb@@ -34,6 +34,8 @@ class PostMover)DiscourseTagging.tag_topic_by_names(new_topic, Guardian.new(user), tags)move_posts_to new_topic+ force_user_to_watch_new_topic+ new_topicendend@@ -223,4 +225,13 @@ class PostMoverdestination_topic.update_columns(attrs)endend++ def force_user_to_watch_new_topic+ TopicUser.change(+ destination_topic.user,+ destination_topic.id,+ notification_level: TopicUser.notification_levels[:watching],+ notifications_reason_id: TopicUser.notification_reasons[:created_topic]+ )+ endenddiff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex e98a2ab94ae..b57c190756a 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -58,9 +58,12 @@ RSpec.describe TopicsController dodescribe 'moving to a new topic' dolet(:user) { Fabricate(:user) }+ let(:user2) { Fabricate(:user) }let(:moderator) { Fabricate(:moderator) }let(:p1) { Fabricate(:post, user: user, post_number: 1) }let(:p2) { Fabricate(:post, user: user, post_number: 2, topic: p1.topic) }+ let(:p3) { Fabricate(:post, user: user2, post_number: 3, topic: p1.topic) }+ let(:p4) { Fabricate(:post, user: user2, post_number: 4, topic: p1.topic) }let!(:topic) { p1.topic }it "raises an error without post_ids" do@@ -116,6 +119,30 @@ RSpec.describe TopicsController doexpect(Tag.all.pluck(:name)).to contain_exactly("tag1", "tag2")end+ it "forces resulting topic owner to watch the new topic" do+ expect do+ post "/t/#{topic.id}/move-posts.json", params: {+ title: 'Logan is a good movie',+ post_ids: [p3.id, p4.id],+ }+ end.to change { Topic.count }.by(1)++ expect(response.status).to eq(200)++ result = ::JSON.parse(response.body)++ expect(result['success']).to eq(true)+ new_topic = p3.reload.topic+ expect(result['url']).to eq(new_topic.relative_url)++ expect(TopicUser.exists?(+ user_id: user2.id,+ topic_id: new_topic.id,+ notification_level: TopicUser.notification_levels[:watching],+ notifications_reason_id: TopicUser.notification_reasons[:created_topic]+ )).to eq(true)+ end+describe 'when topic has been deleted' doit 'should still be able to move posts' doPostDestroyer.new(Fabricate(:admin), topic.first_post).destroy