From 4f6d5d92153dbb9c8b3c2c48731b129963254180 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Mon, 14 Jul 2014 16:58:10 -0400 Subject: [PATCH] FEATURE: add site settings rate_limit_new_user_create_topic and rate_limit_new_user_create_post to have different rate limits for topic and post creation for new users --- config/locales/server.en.yml | 2 ++ config/site_settings.yml | 2 ++ lib/rate_limiter/on_create_record.rb | 6 +++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 91fc149a3b2..8ed987852b4 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -796,6 +796,8 @@ en: rate_limit_create_topic: "After creating a topic, users must wait (n) seconds before creating another topic." rate_limit_create_post: "After posting, users must wait (n) seconds before creating another post." + rate_limit_new_user_create_topic: "After creating a topic, new users must wait (n) seconds before creating another topic." + rate_limit_new_user_create_post: "After posting, new users must wait (n) seconds before creating another post." max_likes_per_day: "Maximum number of likes per user per day." max_flags_per_day: "Maximum number of flags per user per day." diff --git a/config/site_settings.yml b/config/site_settings.yml index 823c56d96ee..255baac5ebd 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -543,6 +543,8 @@ rate_limits: default: 5 rate_limit_create_topic: 15 rate_limit_create_post: 5 + rate_limit_new_user_create_topic: 60 + rate_limit_new_user_create_post: 30 max_topics_per_day: 20 max_private_messages_per_day: 20 max_likes_per_day: 50 diff --git a/lib/rate_limiter/on_create_record.rb b/lib/rate_limiter/on_create_record.rb index be25f3e15af..764aae73a4d 100644 --- a/lib/rate_limiter/on_create_record.rb +++ b/lib/rate_limiter/on_create_record.rb @@ -13,7 +13,11 @@ class RateLimiter return @rate_limiter if @rate_limiter.present? limit_key = "create_#{self.class.name.underscore}" - max_setting = SiteSetting.send("rate_limit_#{limit_key}") + max_setting = if user.new_user? and SiteSetting.has_setting?("rate_limit_new_user_#{limit_key}") + SiteSetting.send("rate_limit_new_user_#{limit_key}") + else + SiteSetting.send("rate_limit_#{limit_key}") + end @rate_limiter = RateLimiter.new(user, limit_key, 1, max_setting) end