FEATURE: Unassign the review queue topic when a flag is handled
This commit is contained in:
parent
2501c0cd0f
commit
7282435e17
|
@ -120,6 +120,7 @@ class ReviewableFlaggedPost < Reviewable
|
||||||
end
|
end
|
||||||
|
|
||||||
if actions.first.present?
|
if actions.first.present?
|
||||||
|
unassign_topic performed_by, post
|
||||||
DiscourseEvent.trigger(:flag_reviewed, post)
|
DiscourseEvent.trigger(:flag_reviewed, post)
|
||||||
DiscourseEvent.trigger(:flag_deferred, actions.first)
|
DiscourseEvent.trigger(:flag_deferred, actions.first)
|
||||||
end
|
end
|
||||||
|
@ -190,6 +191,7 @@ class ReviewableFlaggedPost < Reviewable
|
||||||
Post.with_deleted.where(id: target_id).update_all(cached)
|
Post.with_deleted.where(id: target_id).update_all(cached)
|
||||||
|
|
||||||
if actions.first.present?
|
if actions.first.present?
|
||||||
|
unassign_topic performed_by, post
|
||||||
DiscourseEvent.trigger(:flag_reviewed, post)
|
DiscourseEvent.trigger(:flag_reviewed, post)
|
||||||
DiscourseEvent.trigger(:flag_disagreed, actions.first)
|
DiscourseEvent.trigger(:flag_disagreed, actions.first)
|
||||||
end
|
end
|
||||||
|
@ -256,6 +258,7 @@ protected
|
||||||
DiscourseEvent.trigger(:confirmed_spam_post, post) if trigger_spam
|
DiscourseEvent.trigger(:confirmed_spam_post, post) if trigger_spam
|
||||||
|
|
||||||
if actions.first.present?
|
if actions.first.present?
|
||||||
|
unassign_topic performed_by, post
|
||||||
DiscourseEvent.trigger(:flag_reviewed, post)
|
DiscourseEvent.trigger(:flag_reviewed, post)
|
||||||
DiscourseEvent.trigger(:flag_agreed, actions.first)
|
DiscourseEvent.trigger(:flag_agreed, actions.first)
|
||||||
yield(actions.first) if block_given?
|
yield(actions.first) if block_given?
|
||||||
|
@ -279,6 +282,26 @@ protected
|
||||||
end
|
end
|
||||||
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
|
private
|
||||||
|
|
||||||
def destroyer(performed_by, post)
|
def destroyer(performed_by, post)
|
||||||
|
|
|
@ -93,6 +93,20 @@ RSpec.describe ReviewableFlaggedPost, type: :model do
|
||||||
expect(post).not_to be_hidden
|
expect(post).not_to be_hidden
|
||||||
end
|
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
|
it "agree_and_suspend agrees with the flags and keeps the post" do
|
||||||
reviewable.perform(moderator, :agree_and_suspend)
|
reviewable.perform(moderator, :agree_and_suspend)
|
||||||
expect(reviewable).to be_approved
|
expect(reviewable).to be_approved
|
||||||
|
|
Loading…
Reference in New Issue