mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 02:48:28 +08:00
Select +Replies for bulk operations
This commit is contained in:
@ -191,6 +191,16 @@ class ApplicationController < ActionController::Base
|
||||
user
|
||||
end
|
||||
|
||||
def post_ids_including_replies
|
||||
post_ids = params[:post_ids].map {|p| p.to_i}
|
||||
if params[:reply_post_ids]
|
||||
post_ids << PostReply.where(post_id: params[:reply_post_ids].map {|p| p.to_i}).pluck(:reply_id)
|
||||
post_ids.flatten!
|
||||
post_ids.uniq!
|
||||
end
|
||||
post_ids
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def preload_anonymous_data
|
||||
|
@ -150,10 +150,11 @@ class PostsController < ApplicationController
|
||||
|
||||
params.require(:post_ids)
|
||||
|
||||
posts = Post.where(id: params[:post_ids])
|
||||
posts = Post.where(id: post_ids_including_replies)
|
||||
raise Discourse::InvalidParameters.new(:post_ids) if posts.blank?
|
||||
|
||||
# Make sure we can delete the posts
|
||||
|
||||
posts.each {|p| guardian.ensure_can_delete!(p) }
|
||||
|
||||
Post.transaction do
|
||||
|
@ -244,7 +244,7 @@ class TopicsController < ApplicationController
|
||||
topic = Topic.where(id: params[:topic_id]).first
|
||||
guardian.ensure_can_move_posts!(topic)
|
||||
|
||||
dest_topic = move_post_to_destination(topic)
|
||||
dest_topic = move_posts_to_destination(topic)
|
||||
render_topic_changes(dest_topic)
|
||||
end
|
||||
|
||||
@ -333,12 +333,12 @@ class TopicsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def move_post_to_destination(topic)
|
||||
def move_posts_to_destination(topic)
|
||||
args = {}
|
||||
args[:title] = params[:title] if params[:title].present?
|
||||
args[:destination_topic_id] = params[:destination_topic_id].to_i if params[:destination_topic_id].present?
|
||||
|
||||
topic.move_posts(current_user, params[:post_ids].map {|p| p.to_i}, args)
|
||||
topic.move_posts(current_user, post_ids_including_replies, args)
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user