FIX: properly unassign topics if there are no **more** flags to handle

FIX: properly unassign topics if there are no more flags to handle

From 5800f768f555c0262b1428271fd43c332bd484ba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9gis=20Hanol?= <regis@hanol.fr>
Date: Tue, 14 Aug 2018 18:20:00 +0200
Subject: [PATCH] FIX: properly unassign topics if there are no **more** flags
 to handle


diff --git a/plugin.rb b/plugin.rb
index 38a59ca..65db180 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -217,7 +217,8 @@ after_initialize do
   on(:flag_reviewed) do |post|
     if SiteSetting.assign_locks_flags? &&
       post.topic &&
-      FlagQuery.flagged_post_actions(topic_id: post.topic.id).count == 0
+      FlagQuery.flagged_post_actions(topic_id: post.topic_id, filter: "old").count > 0 &&
+      FlagQuery.flagged_post_actions(topic_id: post.topic_id).count == 0
 
       assigner = ::TopicAssigner.new(post.topic, Discourse.system_user)
       assigner.unassign

GitHub

I think we should update our test cases to prevent this from regressing.

Another bigger question is why “flag_reviewed” is firing when you delete a post with zero flags…

@tgxworld I was actually waiting to investigate what @SamSaffron noted before writing a spec :wink:

On 15 Aug 2018, at 01:46, Sam notifications@github.com wrote:

Another bigger question is why “flag_reviewed” is firing when you delete a post with zero flags…


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

It’s now properly fixed in FIX: don't trigger 'flag_reviewed' when no flags were reviewed · discourse/discourse@93201d8 · GitHub :ok_hand: