mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 23:36:11 +08:00
rate limits for topics and posts on first day
max_topics_in_first_day and max_replies_in_first_day
This commit is contained in:
@ -17,6 +17,7 @@ class Post < ActiveRecord::Base
|
||||
versioned if: :raw_changed?
|
||||
|
||||
rate_limit
|
||||
rate_limit :limit_posts_per_day
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :topic, counter_cache: :posts_count
|
||||
@ -54,6 +55,12 @@ class Post < ActiveRecord::Base
|
||||
@types ||= Enum.new(:regular, :moderator_action)
|
||||
end
|
||||
|
||||
def limit_posts_per_day
|
||||
if user.created_at > 1.day.ago && post_number > 1
|
||||
RateLimiter.new(user, "first-day-replies-per-day:#{Date.today.to_s}", SiteSetting.max_replies_in_first_day, 1.day.to_i)
|
||||
end
|
||||
end
|
||||
|
||||
def trash!(trashed_by=nil)
|
||||
self.topic_links.each(&:destroy)
|
||||
super(trashed_by)
|
||||
|
@ -66,6 +66,9 @@ class SiteSetting < ActiveRecord::Base
|
||||
setting(:flags_required_to_hide_post, 3)
|
||||
setting(:cooldown_minutes_after_hiding_posts, 10)
|
||||
|
||||
setting(:max_topics_in_first_day, 5)
|
||||
setting(:max_replies_in_first_day, 10)
|
||||
|
||||
setting(:num_flags_to_block_new_user, 3)
|
||||
setting(:num_users_to_block_new_user, 3)
|
||||
setting(:notify_mods_when_user_blocked, false)
|
||||
|
@ -183,6 +183,9 @@ class Topic < ActiveRecord::Base
|
||||
# Additional rate limits on topics: per day and private messages per day
|
||||
def limit_topics_per_day
|
||||
RateLimiter.new(user, "topics-per-day:#{Date.today.to_s}", SiteSetting.max_topics_per_day, 1.day.to_i)
|
||||
if user.created_at > 1.day.ago
|
||||
RateLimiter.new(user, "first-day-topics-per-day:#{Date.today.to_s}", SiteSetting.max_topics_in_first_day, 1.day.to_i)
|
||||
end
|
||||
end
|
||||
|
||||
def limit_private_messages_per_day
|
||||
|
Reference in New Issue
Block a user