FEATURE: keep the topic in closed status until the community flags are handled

This commit is contained in:
Vinoth Kannan
2019-01-08 16:13:10 +05:30
parent f947e3c6cc
commit 8f602be2fe
3 changed files with 103 additions and 43 deletions

View File

@@ -564,9 +564,7 @@ class PostAction < ActiveRecord::Base
MAXIMUM_FLAGS_PER_POST = 3
def self.auto_close_if_threshold_reached(topic)
return if topic.nil? || topic.closed?
def self.auto_close_threshold_reached?(topic)
flags = PostAction.active
.flags
.joins(:post)
@@ -580,6 +578,13 @@ class PostAction < ActiveRecord::Base
# we need a minimum number of flags
return if flags.sum { |f| f[1] } < SiteSetting.num_flags_to_close_topic
true
end
def self.auto_close_if_threshold_reached(topic)
return if topic.nil? || topic.closed?
return unless auto_close_threshold_reached?(topic)
# the threshold has been reached, we will close the topic waiting for intervention
topic.update_status("closed", true, Discourse.system_user,
message: I18n.t(