diff --git a/app/models/post_action.rb b/app/models/post_action.rb index e90767a087c..39d36c22422 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -497,8 +497,18 @@ SQL return if flags.sum { |f| f[1] } < SiteSetting.num_flags_to_close_topic # the threshold has been reached, we will close the topic waiting for intervention - message = I18n.t("temporarily_closed_due_to_flags") - topic.update_status("closed", true, Discourse.system_user, message: message) + topic.update_status("closed", true, Discourse.system_user, + message: I18n.t( + "temporarily_closed_due_to_flags", + count: SiteSetting.num_hours_to_close_topic + ) + ) + + topic.set_or_create_status_update( + TopicStatusUpdate.types[:open], + SiteSetting.num_hours_to_close_topic, + by_user: Discourse.system_user + ) end def self.auto_hide_if_needed(acting_user, post, post_action_type) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 12ee021f749..9108c348879 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1286,6 +1286,7 @@ en: num_flaggers_to_close_topic: "Minimum number of unique flaggers that is required to automatically pause a topic for intervention" num_flags_to_close_topic: "Minimum number of active flags that is required to automatically pause a topic for intervention" + num_hours_to_close_topic: "Number of hours to pause a topic for intervention." auto_respond_to_flag_actions: "Enable automatic reply when disposing a flag." min_first_post_typing_time: "Minimum amount of time in milliseconds a user must type during first post, if threshold is not met post will automatically enter the needs approval queue. Set to 0 to disable (not recommended)" @@ -1912,7 +1913,9 @@ en: deferred: "Thanks for letting us know. We're looking into it." deferred_and_deleted: "Thanks for letting us know. We've removed the post." - temporarily_closed_due_to_flags: "This topic is temporarily closed due to a large number of community flags." + temporarily_closed_due_to_flags: + one: "This topic is temporarily closed for 1 hour due to a large number of community flags." + other: "This topic is temporarily closed for %{count} hours due to a large number of community flags." system_messages: post_hidden: diff --git a/config/site_settings.yml b/config/site_settings.yml index 7302d23e905..eb36c891b42 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -944,6 +944,9 @@ spam: max_age_unmatched_ips: 365 num_flaggers_to_close_topic: 5 num_flags_to_close_topic: 12 + num_hours_to_close_topic: + default: 4 + min: 1 auto_respond_to_flag_actions: true min_first_post_typing_time: 3000 auto_block_fast_typers_on_first_post: true diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index aa7daba215e..9ed0e704991 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -447,11 +447,11 @@ describe PostAction do expect(post.hidden).to eq(false) end - it "will automatically close a topic due to large community flagging" do - SiteSetting.stubs(:flags_required_to_hide_post).returns(0) - - SiteSetting.stubs(:num_flags_to_close_topic).returns(3) - SiteSetting.stubs(:num_flaggers_to_close_topic).returns(2) + it "will automatically pause a topic due to large community flagging" do + SiteSetting.flags_required_to_hide_post = 0 + SiteSetting.num_flags_to_close_topic = 3 + SiteSetting.num_flaggers_to_close_topic = 2 + SiteSetting.num_hours_to_close_topic = 1 topic = Fabricate(:topic) post1 = create_post(topic: topic) @@ -490,6 +490,11 @@ describe PostAction do expect(topic.reload.closed).to eq(true) + topic_status_update = TopicStatusUpdate.last + + expect(topic_status_update.topic).to eq(topic) + expect(topic_status_update.execute_at).to be_within(1.second).of(1.hour.from_now) + expect(topic_status_update.status_type).to eq(TopicStatusUpdate.types[:open]) end end