A platform for community discussion. Free, open, simple.
FEATURE: allow selecting a tag when moving posts to a new topic (#6072)
Maja Komel18f5f646b1d0
diff --git a/app/assets/javascripts/discourse/controllers/split-topic.js.es6 b/app/assets/javascripts/discourse/controllers/split-topic.js.es6index 3ee7ae31078..e7e3dc8230a 100644--- a/app/assets/javascripts/discourse/controllers/split-topic.js.es6+++ b/app/assets/javascripts/discourse/controllers/split-topic.js.es6@@ -8,6 +8,8 @@ export default Ember.Controller.extend(ModalFunctionality, {topicName: null,saving: false,categoryId: null,+ tags: null,+ canAddTags: Ember.computed.alias("site.can_create_tag"),topicController: Ember.inject.controller("topic"),selectedPostsCount: Ember.computed.alias(@@ -29,7 +31,8 @@ export default Ember.Controller.extend(ModalFunctionality, {"modal.modalClass": "split-modal",saving: false,categoryId: null,- topicName: ""+ topicName: "",+ tags: null});},@@ -40,7 +43,8 @@ export default Ember.Controller.extend(ModalFunctionality, {const options = {title: this.get("topicName"),post_ids: this.get("topicController.selectedPostIds"),- category_id: this.get("categoryId")+ category_id: this.get("categoryId"),+ tags: this.get("tags")};movePosts(this.get("model.id"), options)diff --git a/app/assets/javascripts/discourse/templates/modal/split-topic.hbs b/app/assets/javascripts/discourse/templates/modal/split-topic.hbsindex 219584343fd..4022af325ad 100644--- a/app/assets/javascripts/discourse/templates/modal/split-topic.hbs+++ b/app/assets/javascripts/discourse/templates/modal/split-topic.hbs@@ -7,6 +7,10 @@<label>{{i18n 'categories.category'}}</label>{{category-chooser value=categoryId class="small"}}+ {{#if canAddTags}}+ <label>{{i18n 'tagging.tags'}}</label>+ {{tag-chooser tags=tags filterable=true categoryId=categoryId}}+ {{/if}}</form>{{/d-modal-body}}diff --git a/app/assets/stylesheets/desktop/modal.scss b/app/assets/stylesheets/desktop/modal.scssindex 4adeaa4bfba..68b1f167ec2 100644--- a/app/assets/stylesheets/desktop/modal.scss+++ b/app/assets/stylesheets/desktop/modal.scss@@ -127,6 +127,10 @@width: 300px;}+ .category-chooser {+ margin-bottom: 9px;+ }+form {margin-top: 20px;#split-topic-name,diff --git a/app/assets/stylesheets/mobile/modal.scss b/app/assets/stylesheets/mobile/modal.scssindex 4a1441084a2..20b8c4f93cc 100644--- a/app/assets/stylesheets/mobile/modal.scss+++ b/app/assets/stylesheets/mobile/modal.scss@@ -55,6 +55,10 @@margin-right: 10px;}+ .category-chooser {+ margin-bottom: 9px;+ }+button {margin-top: 10px;display: block;diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rbindex fd20607f9e8..5d2af04a1ae 100644--- a/app/controllers/topics_controller.rb+++ b/app/controllers/topics_controller.rb@@ -550,6 +550,7 @@ class TopicsController < ApplicationControllerpost_ids = params.require(:post_ids)topic_id = params.require(:topic_id)params.permit(:category_id)+ params.permit(:tags)topic = Topic.with_deleted.find_by(id: topic_id)guardian.ensure_can_move_posts!(topic)@@ -792,6 +793,7 @@ class TopicsController < ApplicationControllerargs[:title] = params[:title] if params[:title].present?args[:destination_topic_id] = params[:destination_topic_id].to_i if params[:destination_topic_id].present?args[:category_id] = params[:category_id].to_i if params[:category_id].present?+ args[:tags] = params[:tags] if params[:tags].present?topic.move_posts(current_user, post_ids_including_replies, args)enddiff --git a/app/models/post_mover.rb b/app/models/post_mover.rbindex 9f7eff0d18b..c8813e9a19d 100644--- a/app/models/post_mover.rb+++ b/app/models/post_mover.rb@@ -19,19 +19,21 @@ class PostMoverendend- def to_new_topic(title, category_id = nil)+ def to_new_topic(title, category_id = nil, tags = nil)@move_type = PostMover.move_types[:new_topic]post = Post.find_by(id: post_ids.first)raise Discourse::InvalidParameters unless postTopic.transaction do- move_posts_to Topic.create!(+ new_topic = Topic.create!(user: post.user,title: title,category_id: category_id,created_at: post.created_at)+ DiscourseTagging.tag_topic_by_names(new_topic, Guardian.new(user), tags)+ move_posts_to new_topicendenddiff --git a/app/models/topic.rb b/app/models/topic.rbindex f7d973bbd24..86ce4a7a59a 100644--- a/app/models/topic.rb+++ b/app/models/topic.rb@@ -915,7 +915,7 @@ class Topic < ActiveRecord::Baseif opts[:destination_topic_id]post_mover.to_topic opts[:destination_topic_id]elsif opts[:title]- post_mover.to_new_topic(opts[:title], opts[:category_id])+ post_mover.to_new_topic(opts[:title], opts[:category_id], opts[:tags])endenddiff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rbindex 49ce2674d36..03163d05c6b 100644--- a/spec/models/post_mover_spec.rb+++ b/spec/models/post_mover_spec.rb@@ -19,7 +19,7 @@ describe PostMover doendcontext 'move_posts' do- let(:user) { Fabricate(:user) }+ let(:user) { Fabricate(:user, admin: true) }let(:another_user) { Fabricate(:evil_trout) }let(:category) { Fabricate(:category, user: user) }let!(:topic) { Fabricate(:topic, user: user) }@@ -39,6 +39,7 @@ describe PostMover dolet(:p6) { Fabricate(:post, topic: topic) }before do+ SiteSetting.tagging_enabled = trueSiteSetting.queue_jobs = falsep1.replies << p3p2.replies << p4@@ -178,7 +179,7 @@ describe PostMover doit "works correctly" dotopic.expects(:add_moderator_post).once- new_topic = topic.move_posts(user, [p2.id, p4.id], title: "new testing topic name", category_id: category.id)+ new_topic = topic.move_posts(user, [p2.id, p4.id], title: "new testing topic name", category_id: category.id, tags: ["tag1", "tag2"])expect(TopicUser.find_by(user_id: user.id, topic_id: topic.id).last_read_post_number).to eq(p3.post_number)@@ -187,6 +188,7 @@ describe PostMover doexpect(new_topic.like_count).to eq(1)expect(new_topic.category).to eq(category)+ expect(new_topic.tags.pluck(:name)).to eq(["tag1", "tag2"])expect(topic.featured_user1_id).to be_blankexpect(new_topic.posts.by_post_number).to match_array([p2, p4])diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex 2dda7ea7831..486e751c3a8 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -45,6 +45,7 @@ RSpec.describe TopicsController dodescribe '#move_posts' dobefore doSiteSetting.min_topic_title_length = 2+ SiteSetting.tagging_enabled = trueendit 'needs you to be logged in' do@@ -101,10 +102,12 @@ RSpec.describe TopicsController dopost "/t/#{topic.id}/move-posts.json", params: {title: 'Logan is a good movie',post_ids: [p2.id],- category_id: 123+ category_id: 123,+ tags: ["tag1", "tag2"]}end.to change { Topic.count }.by(1)+ expect(Tag.count).to eq(2)expect(response.status).to eq(200)result = ::JSON.parse(response.body)