diff --git a/app/assets/javascripts/discourse/controllers/split-topic.js.es6 b/app/assets/javascripts/discourse/controllers/split-topic.js.es6
index 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.hbs
index 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 @@
{{category-chooser value=categoryId class="small"}}
+ {{#if canAddTags}}
+
+ {{tag-chooser tags=tags filterable=true categoryId=categoryId}}
+ {{/if}}
{{/d-modal-body}}
diff --git a/app/assets/stylesheets/desktop/modal.scss b/app/assets/stylesheets/desktop/modal.scss
index 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.scss
index 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.rb
index fd20607f9e8..5d2af04a1ae 100644
--- a/app/controllers/topics_controller.rb
+++ b/app/controllers/topics_controller.rb
@@ -550,6 +550,7 @@ class TopicsController < ApplicationController
post_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 < ApplicationController
args[: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)
end
diff --git a/app/models/post_mover.rb b/app/models/post_mover.rb
index 9f7eff0d18b..c8813e9a19d 100644
--- a/app/models/post_mover.rb
+++ b/app/models/post_mover.rb
@@ -19,19 +19,21 @@ class PostMover
end
end
- 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 post
Topic.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_topic
end
end
diff --git a/app/models/topic.rb b/app/models/topic.rb
index f7d973bbd24..86ce4a7a59a 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -915,7 +915,7 @@ class Topic < ActiveRecord::Base
if 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])
end
end
diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rb
index 49ce2674d36..03163d05c6b 100644
--- a/spec/models/post_mover_spec.rb
+++ b/spec/models/post_mover_spec.rb
@@ -19,7 +19,7 @@ describe PostMover do
end
context '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 do
let(:p6) { Fabricate(:post, topic: topic) }
before do
+ SiteSetting.tagging_enabled = true
SiteSetting.queue_jobs = false
p1.replies << p3
p2.replies << p4
@@ -178,7 +179,7 @@ describe PostMover do
it "works correctly" do
topic.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 do
expect(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_blank
expect(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.rb
index 2dda7ea7831..486e751c3a8 100644
--- a/spec/requests/topics_controller_spec.rb
+++ b/spec/requests/topics_controller_spec.rb
@@ -45,6 +45,7 @@ RSpec.describe TopicsController do
describe '#move_posts' do
before do
SiteSetting.min_topic_title_length = 2
+ SiteSetting.tagging_enabled = true
end
it 'needs you to be logged in' do
@@ -101,10 +102,12 @@ RSpec.describe TopicsController do
post "/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)