mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 03:51:07 +08:00
FIX: topic and post counts are not updated when ownership of a post is changed
This commit is contained in:
@ -332,24 +332,15 @@ class TopicsController < ApplicationController
|
||||
|
||||
guardian.ensure_can_change_post_owner!
|
||||
|
||||
post_ids = params[:post_ids].to_a
|
||||
topic = Topic.find_by(id: params[:topic_id].to_i)
|
||||
new_user = User.find_by(username: params[:username])
|
||||
|
||||
return render json: failed_json, status: 422 unless post_ids && topic && new_user
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
post_ids.each do |post_id|
|
||||
post = Post.find(post_id)
|
||||
# update topic owner (first avatar)
|
||||
topic.user = new_user if post.is_first_post?
|
||||
post.set_owner(new_user, current_user)
|
||||
end
|
||||
begin
|
||||
PostOwnerChanger.new( post_ids: params[:post_ids].to_a,
|
||||
topic_id: params[:topic_id].to_i,
|
||||
new_owner: User.find_by(username: params[:username]),
|
||||
acting_user: current_user ).change_owner!
|
||||
render json: success_json
|
||||
rescue ArgumentError
|
||||
render json: failed_json, status: 422
|
||||
end
|
||||
|
||||
topic.update_statistics
|
||||
|
||||
render json: success_json
|
||||
end
|
||||
|
||||
def clear_pin
|
||||
|
Reference in New Issue
Block a user