FEATURE: automatically close topics with 10k+ posts
FEATURE: automatically close messages with 2k+ posts Both configurable via `auto_close_messages_post_count` and `auto_close_topics_post_count`
This commit is contained in:
parent
22b2f5285c
commit
0113fce420
|
@ -1281,6 +1281,8 @@ en:
|
||||||
approve_post_count: "The amount of posts from a new or basic user that must be approved"
|
approve_post_count: "The amount of posts from a new or basic user that must be approved"
|
||||||
approve_unless_trust_level: "Posts for users below this trust level must be approved"
|
approve_unless_trust_level: "Posts for users below this trust level must be approved"
|
||||||
notify_about_queued_posts_after: "If there are posts that have been waiting to be reviewed for more than this many hours, an email will be sent to the contact_email. Set to 0 to disable these emails."
|
notify_about_queued_posts_after: "If there are posts that have been waiting to be reviewed for more than this many hours, an email will be sent to the contact_email. Set to 0 to disable these emails."
|
||||||
|
auto_close_messages_post_count: "Maximum number of posts allowed in a message before it is automatically closed (0 to disable)"
|
||||||
|
auto_close_topics_post_count: "Maximum number of posts allowed in a topic before it is automatically closed (0 to disable)"
|
||||||
|
|
||||||
default_email_digest_frequency: "How often users receive digest emails by default."
|
default_email_digest_frequency: "How often users receive digest emails by default."
|
||||||
default_include_tl0_in_digests: "Include posts from new users in digest emails by default. Users can change this in their preferences."
|
default_include_tl0_in_digests: "Include posts from new users in digest emails by default. Users can change this in their preferences."
|
||||||
|
@ -1391,6 +1393,12 @@ en:
|
||||||
archived_disabled: "This topic is now unarchived. It is no longer frozen, and can be changed."
|
archived_disabled: "This topic is now unarchived. It is no longer frozen, and can be changed."
|
||||||
closed_enabled: "This topic is now closed. New replies are no longer allowed."
|
closed_enabled: "This topic is now closed. New replies are no longer allowed."
|
||||||
closed_disabled: "This topic is now opened. New replies are allowed."
|
closed_disabled: "This topic is now opened. New replies are allowed."
|
||||||
|
autoclosed_message_max_posts:
|
||||||
|
one: "This message was automatically closed after reaching the limit of 1 post per message"
|
||||||
|
other: "This message was automatically closed after reaching the limit of %{count} posts per message"
|
||||||
|
autoclosed_topic_max_posts:
|
||||||
|
one: "This topic was automatically closed after reaching the limit of 1 post per topic"
|
||||||
|
other: "This topic was automatically closed after reaching the limit of %{count} posts per topic"
|
||||||
autoclosed_enabled_days:
|
autoclosed_enabled_days:
|
||||||
one: "This topic was automatically closed after 1 day. New replies are no longer allowed."
|
one: "This topic was automatically closed after 1 day. New replies are no longer allowed."
|
||||||
other: "This topic was automatically closed after %{count} days. New replies are no longer allowed."
|
other: "This topic was automatically closed after %{count} days. New replies are no longer allowed."
|
||||||
|
|
|
@ -505,6 +505,8 @@ posting:
|
||||||
notify_about_queued_posts_after:
|
notify_about_queued_posts_after:
|
||||||
default: 24
|
default: 24
|
||||||
min: 0
|
min: 0
|
||||||
|
auto_close_messages_post_count: 200
|
||||||
|
auto_close_topics_post_count: 10000
|
||||||
|
|
||||||
email:
|
email:
|
||||||
email_time_window_mins:
|
email_time_window_mins:
|
||||||
|
|
|
@ -148,6 +148,8 @@ class PostCreator
|
||||||
BadgeGranter.queue_badge_grant(Badge::Trigger::PostRevision, post: @post)
|
BadgeGranter.queue_badge_grant(Badge::Trigger::PostRevision, post: @post)
|
||||||
|
|
||||||
trigger_after_events(@post)
|
trigger_after_events(@post)
|
||||||
|
|
||||||
|
auto_close
|
||||||
end
|
end
|
||||||
|
|
||||||
if @post || @spam
|
if @post || @spam
|
||||||
|
@ -221,6 +223,26 @@ class PostCreator
|
||||||
DiscourseEvent.trigger(:post_created, post, @opts, @user)
|
DiscourseEvent.trigger(:post_created, post, @opts, @user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def auto_close
|
||||||
|
if @post.topic.private_message? &&
|
||||||
|
!@post.topic.closed &&
|
||||||
|
SiteSetting.auto_close_messages_post_count > 0 &&
|
||||||
|
SiteSetting.auto_close_messages_post_count <= @post.topic.posts_count
|
||||||
|
|
||||||
|
@post.topic.update_status(:closed, true, Discourse.system_user,
|
||||||
|
message: I18n.t('topic_statuses.autoclosed_message_max_posts', count: SiteSetting.auto_close_messages_post_count))
|
||||||
|
|
||||||
|
elsif !@post.topic.private_message? &&
|
||||||
|
!@post.topic.closed &&
|
||||||
|
SiteSetting.auto_close_topics_post_count > 0 &&
|
||||||
|
SiteSetting.auto_close_topics_post_count <= @post.topic.posts_count
|
||||||
|
|
||||||
|
@post.topic.update_status(:closed, true, Discourse.system_user,
|
||||||
|
message: I18n.t('topic_statuses.autoclosed_topic_max_posts', count: SiteSetting.auto_close_messages_post_count))
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def transaction(&blk)
|
def transaction(&blk)
|
||||||
Post.transaction do
|
Post.transaction do
|
||||||
if new_topic?
|
if new_topic?
|
||||||
|
|
|
@ -547,6 +547,32 @@ describe PostCreator do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'auto closing' do
|
||||||
|
it 'closes private messages that have more than N posts' do
|
||||||
|
SiteSetting.auto_close_messages_post_count = 2
|
||||||
|
|
||||||
|
admin = Fabricate(:admin)
|
||||||
|
|
||||||
|
post1 = create_post(archetype: Archetype.private_message,
|
||||||
|
target_usernames: [admin.username])
|
||||||
|
|
||||||
|
_post2 = create_post(user: post1.user, topic_id: post1.topic_id)
|
||||||
|
|
||||||
|
post1.topic.reload
|
||||||
|
expect(post1.topic.closed).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'closes topics that have more than N posts' do
|
||||||
|
SiteSetting.auto_close_topics_post_count = 2
|
||||||
|
|
||||||
|
post1 = create_post
|
||||||
|
_post2 = create_post(user: post1.user, topic_id: post1.topic_id)
|
||||||
|
|
||||||
|
post1.topic.reload
|
||||||
|
expect(post1.topic.closed).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'private message to group' do
|
context 'private message to group' do
|
||||||
let(:target_user1) { Fabricate(:coding_horror) }
|
let(:target_user1) { Fabricate(:coding_horror) }
|
||||||
let(:target_user2) { Fabricate(:moderator) }
|
let(:target_user2) { Fabricate(:moderator) }
|
||||||
|
|
Loading…
Reference in New Issue