mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Keep ReviewableQueuedPosts even with user delete reviewable actions (#22501)
Performing a `Delete User`/`Delete and Block User` reviewable actions for a queued post reviewable from the `review.show` route results in an error popup even if the action completes successfully. This happens because unlike other reviewable types, a user delete action on a queued post reviewable results in the deletion of the reviewable itself. A subsequent attempt to reload the reviewable record results in 404. The deletion happens as part of the call to `UserDestroyer` which includes a step for destroying reviewables created by the user being destroyed. At the root of this is the creator of the queued post being set as the creator of the reviewable as instead of the system user. This change assigns the creator of the reviewable to the system user and uses the more approapriate `target_created_by` column for the creator of the post being queued.
This commit is contained in:
@@ -16,6 +16,12 @@ class ReviewableQueuedPost < Reviewable
|
||||
|
||||
after_commit :compute_user_stats, only: %i[create update]
|
||||
|
||||
def updatable_reviewable_scores
|
||||
# Approvals are possible for already rejected queued posts. We need the
|
||||
# scores to be updated when this happens.
|
||||
reviewable_scores.pending.or(reviewable_scores.disagreed)
|
||||
end
|
||||
|
||||
def build_actions(actions, guardian, args)
|
||||
unless approved?
|
||||
if topic&.closed?
|
||||
@@ -25,9 +31,11 @@ class ReviewableQueuedPost < Reviewable
|
||||
a.confirm_message = "reviewables.actions.approve_post.confirm_closed"
|
||||
end
|
||||
else
|
||||
actions.add(:approve_post) do |a|
|
||||
a.icon = "check"
|
||||
a.label = "reviewables.actions.approve_post.title"
|
||||
if target_created_by.present?
|
||||
actions.add(:approve_post) do |a|
|
||||
a.icon = "check"
|
||||
a.label = "reviewables.actions.approve_post.title"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -39,7 +47,7 @@ class ReviewableQueuedPost < Reviewable
|
||||
end
|
||||
end
|
||||
|
||||
delete_user_actions(actions) if pending? && guardian.can_delete_user?(created_by)
|
||||
delete_user_actions(actions) if pending? && guardian.can_delete_user?(target_created_by)
|
||||
|
||||
actions.add(:delete) if guardian.can_delete?(self)
|
||||
end
|
||||
@@ -79,7 +87,7 @@ class ReviewableQueuedPost < Reviewable
|
||||
)
|
||||
opts.merge!(guardian: Guardian.new(performed_by)) if performed_by.staff?
|
||||
|
||||
creator = PostCreator.new(created_by, opts)
|
||||
creator = PostCreator.new(target_created_by, opts)
|
||||
created_post = creator.create
|
||||
|
||||
unless created_post && creator.errors.blank?
|
||||
@@ -90,7 +98,7 @@ class ReviewableQueuedPost < Reviewable
|
||||
self.topic_id = created_post.topic_id if topic_id.nil?
|
||||
save
|
||||
|
||||
UserSilencer.unsilence(created_by, performed_by) if created_by.silenced?
|
||||
UserSilencer.unsilence(target_created_by, performed_by) if target_created_by.silenced?
|
||||
|
||||
StaffActionLogger.new(performed_by).log_post_approved(created_post) if performed_by.staff?
|
||||
|
||||
@@ -99,7 +107,7 @@ class ReviewableQueuedPost < Reviewable
|
||||
|
||||
Notification.create!(
|
||||
notification_type: Notification.types[:post_approved],
|
||||
user_id: created_by.id,
|
||||
user_id: target_created_by.id,
|
||||
data: { post_url: created_post.url }.to_json,
|
||||
topic_id: created_post.topic_id,
|
||||
post_number: created_post.post_number,
|
||||
@@ -148,9 +156,12 @@ class ReviewableQueuedPost < Reviewable
|
||||
private
|
||||
|
||||
def delete_user(performed_by, delete_options)
|
||||
reviewable_ids = Reviewable.where(created_by: created_by).pluck(:id)
|
||||
UserDestroyer.new(performed_by).destroy(created_by, delete_options)
|
||||
create_result(:success) { |r| r.remove_reviewable_ids = reviewable_ids }
|
||||
reviewable_ids = Reviewable.where(created_by: target_created_by).pluck(:id)
|
||||
|
||||
UserDestroyer.new(performed_by).destroy(target_created_by, delete_options)
|
||||
update_column(:target_created_by_id, nil)
|
||||
|
||||
create_result(:success, :rejected) { |r| r.remove_reviewable_ids += reviewable_ids }
|
||||
end
|
||||
|
||||
def delete_opts
|
||||
@@ -164,7 +175,7 @@ class ReviewableQueuedPost < Reviewable
|
||||
|
||||
def compute_user_stats
|
||||
return unless status_changed_from_or_to_pending?
|
||||
created_by.user_stat.update_pending_posts
|
||||
target_created_by&.user_stat&.update_pending_posts
|
||||
end
|
||||
|
||||
def status_changed_from_or_to_pending?
|
||||
|
||||
Reference in New Issue
Block a user