FEATURE: auto block fast typers

if tl0 enter text too fast they get automatically blocked, configurable
This commit is contained in:
Sam 2015-08-04 12:06:07 +10:00
parent 61536c911b
commit 6fdd53e3d6
4 changed files with 31 additions and 7 deletions

View File

@ -1078,6 +1078,8 @@ en:
auto_respond_to_flag_actions: "Enable automatic reply when disposing a flag." 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)" 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)"
auto_block_fast_typers_on_first_post: "Automatically block users that do not meet min_first_post_typing_time"
auto_block_fast_typers_max_trust_level: "Maximum trust level to auto block fast typers"
reply_by_email_enabled: "Enable replying to topics via email." reply_by_email_enabled: "Enable replying to topics via email."
reply_by_email_address: "Template for reply by email incoming email address, for example: %{reply_key}@reply.example.com or replies+%{reply_key}@example.com" reply_by_email_address: "Template for reply by email incoming email address, for example: %{reply_key}@reply.example.com or replies+%{reply_key}@example.com"

View File

@ -681,6 +681,8 @@ spam:
num_flags_to_close_topic: 12 num_flags_to_close_topic: 12
auto_respond_to_flag_actions: true auto_respond_to_flag_actions: true
min_first_post_typing_time: 3000 min_first_post_typing_time: 3000
auto_block_fast_typers_on_first_post: true
auto_block_fast_typers_max_trust_level: 0
rate_limits: rate_limits:
unique_posts_mins: unique_posts_mins:

View File

@ -28,23 +28,41 @@ class NewPostManager
@sorted_handlers.sort_by! {|h| -h[:priority]} @sorted_handlers.sort_by! {|h| -h[:priority]}
end end
def self.user_needs_approval?(manager) def self.is_fast_typer?(manager)
user = manager.user user = manager.user
args = manager.args args = manager.args
args[:first_post_checks] &&
user.post_count == 0 &&
args[:typing_duration_msecs].to_i < SiteSetting.min_first_post_typing_time
end
def self.user_needs_approval?(manager)
user = manager.user
return false if user.staff? return false if user.staff?
(user.post_count < SiteSetting.approve_post_count) || (user.post_count < SiteSetting.approve_post_count) ||
(user.trust_level < SiteSetting.approve_unless_trust_level.to_i) || (user.trust_level < SiteSetting.approve_unless_trust_level.to_i) ||
( is_fast_typer?(manager)
args[:first_post_checks] &&
user.post_count == 0 &&
args[:typing_duration_msecs].to_i < SiteSetting.min_first_post_typing_time
)
end end
def self.default_handler(manager) def self.default_handler(manager)
manager.enqueue('default') if user_needs_approval?(manager) if user_needs_approval?(manager)
result = manager.enqueue('default')
if is_fast_typer?(manager) &&
SiteSetting.auto_block_fast_typers_on_first_post &&
SiteSetting.auto_block_fast_typers_max_trust_level <= manager.user.trust_level
manager.user.update_columns(blocked: true)
end
result
end
end end
def self.queue_enabled? def self.queue_enabled?

View File

@ -492,6 +492,8 @@ describe PostsController do
expect(parsed["action"]).to eq("enqueued") expect(parsed["action"]).to eq("enqueued")
expect(user.blocked).to eq(true)
end end
it 'creates the post' do it 'creates the post' do