mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 12:51:24 +08:00
FEATURE: allow selecting a tag when moving posts to a new topic (#6072)
This commit is contained in:
@ -8,6 +8,8 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||||||
topicName: null,
|
topicName: null,
|
||||||
saving: false,
|
saving: false,
|
||||||
categoryId: null,
|
categoryId: null,
|
||||||
|
tags: null,
|
||||||
|
canAddTags: Ember.computed.alias("site.can_create_tag"),
|
||||||
|
|
||||||
topicController: Ember.inject.controller("topic"),
|
topicController: Ember.inject.controller("topic"),
|
||||||
selectedPostsCount: Ember.computed.alias(
|
selectedPostsCount: Ember.computed.alias(
|
||||||
@ -29,7 +31,8 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||||||
"modal.modalClass": "split-modal",
|
"modal.modalClass": "split-modal",
|
||||||
saving: false,
|
saving: false,
|
||||||
categoryId: null,
|
categoryId: null,
|
||||||
topicName: ""
|
topicName: "",
|
||||||
|
tags: null
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -40,7 +43,8 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||||||
const options = {
|
const options = {
|
||||||
title: this.get("topicName"),
|
title: this.get("topicName"),
|
||||||
post_ids: this.get("topicController.selectedPostIds"),
|
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)
|
movePosts(this.get("model.id"), options)
|
||||||
|
@ -7,6 +7,10 @@
|
|||||||
|
|
||||||
<label>{{i18n 'categories.category'}}</label>
|
<label>{{i18n 'categories.category'}}</label>
|
||||||
{{category-chooser value=categoryId class="small"}}
|
{{category-chooser value=categoryId class="small"}}
|
||||||
|
{{#if canAddTags}}
|
||||||
|
<label>{{i18n 'tagging.tags'}}</label>
|
||||||
|
{{tag-chooser tags=tags filterable=true categoryId=categoryId}}
|
||||||
|
{{/if}}
|
||||||
</form>
|
</form>
|
||||||
{{/d-modal-body}}
|
{{/d-modal-body}}
|
||||||
|
|
||||||
|
@ -127,6 +127,10 @@
|
|||||||
width: 300px;
|
width: 300px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.category-chooser {
|
||||||
|
margin-bottom: 9px;
|
||||||
|
}
|
||||||
|
|
||||||
form {
|
form {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
#split-topic-name,
|
#split-topic-name,
|
||||||
|
@ -55,6 +55,10 @@
|
|||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.category-chooser {
|
||||||
|
margin-bottom: 9px;
|
||||||
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
display: block;
|
display: block;
|
||||||
|
@ -550,6 +550,7 @@ class TopicsController < ApplicationController
|
|||||||
post_ids = params.require(:post_ids)
|
post_ids = params.require(:post_ids)
|
||||||
topic_id = params.require(:topic_id)
|
topic_id = params.require(:topic_id)
|
||||||
params.permit(:category_id)
|
params.permit(:category_id)
|
||||||
|
params.permit(:tags)
|
||||||
|
|
||||||
topic = Topic.with_deleted.find_by(id: topic_id)
|
topic = Topic.with_deleted.find_by(id: topic_id)
|
||||||
guardian.ensure_can_move_posts!(topic)
|
guardian.ensure_can_move_posts!(topic)
|
||||||
@ -792,6 +793,7 @@ class TopicsController < ApplicationController
|
|||||||
args[:title] = params[:title] if params[:title].present?
|
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[: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[: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)
|
topic.move_posts(current_user, post_ids_including_replies, args)
|
||||||
end
|
end
|
||||||
|
@ -19,19 +19,21 @@ class PostMover
|
|||||||
end
|
end
|
||||||
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]
|
@move_type = PostMover.move_types[:new_topic]
|
||||||
|
|
||||||
post = Post.find_by(id: post_ids.first)
|
post = Post.find_by(id: post_ids.first)
|
||||||
raise Discourse::InvalidParameters unless post
|
raise Discourse::InvalidParameters unless post
|
||||||
|
|
||||||
Topic.transaction do
|
Topic.transaction do
|
||||||
move_posts_to Topic.create!(
|
new_topic = Topic.create!(
|
||||||
user: post.user,
|
user: post.user,
|
||||||
title: title,
|
title: title,
|
||||||
category_id: category_id,
|
category_id: category_id,
|
||||||
created_at: post.created_at
|
created_at: post.created_at
|
||||||
)
|
)
|
||||||
|
DiscourseTagging.tag_topic_by_names(new_topic, Guardian.new(user), tags)
|
||||||
|
move_posts_to new_topic
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -915,7 +915,7 @@ class Topic < ActiveRecord::Base
|
|||||||
if opts[:destination_topic_id]
|
if opts[:destination_topic_id]
|
||||||
post_mover.to_topic opts[:destination_topic_id]
|
post_mover.to_topic opts[:destination_topic_id]
|
||||||
elsif opts[:title]
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ describe PostMover do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'move_posts' do
|
context 'move_posts' do
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user, admin: true) }
|
||||||
let(:another_user) { Fabricate(:evil_trout) }
|
let(:another_user) { Fabricate(:evil_trout) }
|
||||||
let(:category) { Fabricate(:category, user: user) }
|
let(:category) { Fabricate(:category, user: user) }
|
||||||
let!(:topic) { Fabricate(:topic, user: user) }
|
let!(:topic) { Fabricate(:topic, user: user) }
|
||||||
@ -39,6 +39,7 @@ describe PostMover do
|
|||||||
let(:p6) { Fabricate(:post, topic: topic) }
|
let(:p6) { Fabricate(:post, topic: topic) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
SiteSetting.tagging_enabled = true
|
||||||
SiteSetting.queue_jobs = false
|
SiteSetting.queue_jobs = false
|
||||||
p1.replies << p3
|
p1.replies << p3
|
||||||
p2.replies << p4
|
p2.replies << p4
|
||||||
@ -178,7 +179,7 @@ describe PostMover do
|
|||||||
|
|
||||||
it "works correctly" do
|
it "works correctly" do
|
||||||
topic.expects(:add_moderator_post).once
|
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)
|
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.like_count).to eq(1)
|
||||||
|
|
||||||
expect(new_topic.category).to eq(category)
|
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(topic.featured_user1_id).to be_blank
|
||||||
expect(new_topic.posts.by_post_number).to match_array([p2, p4])
|
expect(new_topic.posts.by_post_number).to match_array([p2, p4])
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ RSpec.describe TopicsController do
|
|||||||
describe '#move_posts' do
|
describe '#move_posts' do
|
||||||
before do
|
before do
|
||||||
SiteSetting.min_topic_title_length = 2
|
SiteSetting.min_topic_title_length = 2
|
||||||
|
SiteSetting.tagging_enabled = true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'needs you to be logged in' do
|
it 'needs you to be logged in' do
|
||||||
@ -101,10 +102,12 @@ RSpec.describe TopicsController do
|
|||||||
post "/t/#{topic.id}/move-posts.json", params: {
|
post "/t/#{topic.id}/move-posts.json", params: {
|
||||||
title: 'Logan is a good movie',
|
title: 'Logan is a good movie',
|
||||||
post_ids: [p2.id],
|
post_ids: [p2.id],
|
||||||
category_id: 123
|
category_id: 123,
|
||||||
|
tags: ["tag1", "tag2"]
|
||||||
}
|
}
|
||||||
end.to change { Topic.count }.by(1)
|
end.to change { Topic.count }.by(1)
|
||||||
|
|
||||||
|
expect(Tag.count).to eq(2)
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
|
|
||||||
result = ::JSON.parse(response.body)
|
result = ::JSON.parse(response.body)
|
||||||
|
Reference in New Issue
Block a user