mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
You can now 'move' the first post of a topic to another topic as a merge. In that
case, the first post is cloned instead of being deleted from the original topic.
This commit is contained in:
@@ -24,13 +24,12 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
|
||||
|
||||
canMoveSelected: function() {
|
||||
if (!this.get('content.can_move_posts')) return false;
|
||||
// For now, we can move it if we can delete it since the posts need to be deleted.
|
||||
return this.get('canDeleteSelected');
|
||||
return (this.get('selectedPostsCount') > 0);
|
||||
}.property('canDeleteSelected'),
|
||||
|
||||
canDeleteSelected: function() {
|
||||
var selectedPosts = this.get('selectedPosts');
|
||||
if (!(selectedPosts && selectedPosts.length > 0)) return false;
|
||||
if (this.get('selectedPostsCount') === 0) return false;
|
||||
|
||||
var canDelete = true;
|
||||
selectedPosts.each(function(p) {
|
||||
|
||||
@@ -462,7 +462,7 @@ class Topic < ActiveRecord::Base
|
||||
invite
|
||||
end
|
||||
|
||||
def move_posts_to_topic(post_ids, destination_topic)
|
||||
def move_posts_to_topic(moved_by, post_ids, destination_topic)
|
||||
to_move = posts.where(id: post_ids).order(:created_at)
|
||||
raise Discourse::InvalidParameters.new(:post_ids) if to_move.blank?
|
||||
|
||||
@@ -472,11 +472,18 @@ class Topic < ActiveRecord::Base
|
||||
max_post_number = destination_topic.posts.maximum(:post_number) || 0
|
||||
|
||||
to_move.each_with_index do |post, i|
|
||||
first_post_number ||= post.post_number
|
||||
row_count = Post.update_all ["post_number = :post_number, topic_id = :topic_id, sort_order = :post_number", post_number: max_post_number+i+1, topic_id: destination_topic.id], id: post.id, topic_id: id
|
||||
|
||||
# We raise an error if any of the posts can't be moved
|
||||
raise Discourse::InvalidParameters.new(:post_ids) if row_count == 0
|
||||
if post.post_number == 1
|
||||
# We have a special case for the OP, we copy it instead of deleting it.
|
||||
result = PostCreator.new(post.user,
|
||||
raw: post.raw,
|
||||
topic_id: destination_topic.id,
|
||||
acting_user: moved_by).create
|
||||
else
|
||||
first_post_number ||= post.post_number
|
||||
# Move the post and raise an error if it couldn't be moved
|
||||
row_count = Post.update_all ["post_number = :post_number, topic_id = :topic_id, sort_order = :post_number", post_number: max_post_number+i+1, topic_id: destination_topic.id], id: post.id, topic_id: id
|
||||
raise Discourse::InvalidParameters.new(:post_ids) if row_count == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -493,7 +500,7 @@ class Topic < ActiveRecord::Base
|
||||
# If we're moving to a new topic...
|
||||
Topic.transaction do
|
||||
topic = Topic.create(user: moved_by, title: opts[:title], category: category)
|
||||
first_post_number = move_posts_to_topic(post_ids, topic)
|
||||
first_post_number = move_posts_to_topic(moved_by, post_ids, topic)
|
||||
end
|
||||
|
||||
elsif opts[:destination_topic_id].present?
|
||||
@@ -501,7 +508,7 @@ class Topic < ActiveRecord::Base
|
||||
|
||||
topic = Topic.where(id: opts[:destination_topic_id]).first
|
||||
Guardian.new(moved_by).ensure_can_see!(topic)
|
||||
first_post_number = move_posts_to_topic(post_ids, topic)
|
||||
first_post_number = move_posts_to_topic(moved_by, post_ids, topic)
|
||||
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user