From 7282435e17836997b8e084eff7122d246dce62a2 Mon Sep 17 00:00:00 2001 From: Jeff Wong Date: Tue, 24 Mar 2020 14:57:44 -0700 Subject: [PATCH] FEATURE: Unassign the review queue topic when a flag is handled --- app/models/reviewable_flagged_post.rb | 23 +++++++++++++++++++++ spec/models/reviewable_flagged_post_spec.rb | 14 +++++++++++++ 2 files changed, 37 insertions(+) diff --git a/app/models/reviewable_flagged_post.rb b/app/models/reviewable_flagged_post.rb index 340d63c8b5c..1dc89856b22 100644 --- a/app/models/reviewable_flagged_post.rb +++ b/app/models/reviewable_flagged_post.rb @@ -120,6 +120,7 @@ class ReviewableFlaggedPost < Reviewable end if actions.first.present? + unassign_topic performed_by, post DiscourseEvent.trigger(:flag_reviewed, post) DiscourseEvent.trigger(:flag_deferred, actions.first) end @@ -190,6 +191,7 @@ class ReviewableFlaggedPost < Reviewable Post.with_deleted.where(id: target_id).update_all(cached) if actions.first.present? + unassign_topic performed_by, post DiscourseEvent.trigger(:flag_reviewed, post) DiscourseEvent.trigger(:flag_disagreed, actions.first) end @@ -256,6 +258,7 @@ protected DiscourseEvent.trigger(:confirmed_spam_post, post) if trigger_spam if actions.first.present? + unassign_topic performed_by, post DiscourseEvent.trigger(:flag_reviewed, post) DiscourseEvent.trigger(:flag_agreed, actions.first) yield(actions.first) if block_given? @@ -279,6 +282,26 @@ protected end end + def unassign_topic(performed_by, post) + topic = post.topic + return unless topic && performed_by && SiteSetting.reviewable_claiming != 'disabled' + ReviewableClaimedTopic.where(topic_id: topic.id).delete_all + topic.reviewables.find_each do |reviewable| + reviewable.log_history(:unclaimed, performed_by) + end + + user_ids = User.staff.pluck(:id) + + if SiteSetting.enable_category_group_review? && group_id = topic.category&.reviewable_by_group_id.presence + user_ids.concat(GroupUser.where(group_id: group_id).pluck(:user_id)) + user_ids.uniq! + end + + data = { topic_id: topic.id } + + MessageBus.publish("/reviewable_claimed", data, user_ids: user_ids) + end + private def destroyer(performed_by, post) diff --git a/spec/models/reviewable_flagged_post_spec.rb b/spec/models/reviewable_flagged_post_spec.rb index f656e5763b1..07124680d87 100644 --- a/spec/models/reviewable_flagged_post_spec.rb +++ b/spec/models/reviewable_flagged_post_spec.rb @@ -93,6 +93,20 @@ RSpec.describe ReviewableFlaggedPost, type: :model do expect(post).not_to be_hidden end + describe "with reviewable claiming enabled" do + fab!(:claimed) { Fabricate(:reviewable_claimed_topic, topic: post.topic, user: moderator) } + it "clears the claimed topic on resolve" do + SiteSetting.reviewable_claiming = 'required' + reviewable.perform(moderator, :agree_and_keep) + expect(reviewable).to be_approved + expect(score.reload).to be_agreed + expect(post).not_to be_hidden + expect(ReviewableClaimedTopic.where(topic_id: post.topic.id).exists?).to eq(false) + expect(post.topic.reviewables.first.history.where(reviewable_history_type: ReviewableHistory.types[:unclaimed]).size).to eq(1) + end + + end + it "agree_and_suspend agrees with the flags and keeps the post" do reviewable.perform(moderator, :agree_and_suspend) expect(reviewable).to be_approved