Set ratelimits on subreddits

This commit is contained in:
Keith Mitchell
2012-04-27 12:10:31 -07:00
parent 2f56f97713
commit a8d55dd77a
5 changed files with 22 additions and 0 deletions

View File

@@ -441,6 +441,11 @@ comment_visits_period = 600
#user-agents to rate-limit
agents =
# subreddit ratelimits
sr_banned_quota = 10000
sr_moderator_quota = 10000
sr_contributor_quota = 10000
sr_quota_time = 7200
# -- email --
# smtp server

View File

@@ -549,6 +549,17 @@ class ApiController(RedditController):
if (not c.user_is_admin
and (type in sr_types and not container.is_moderator(c.user))):
abort(403,'forbidden')
if type in sr_types and not c.user_is_admin:
quota_key = "sr%squota-%s" % (str(type), container._id36)
g.cache.add(quota_key, 0, time=g.sr_quota_time)
subreddit_quota = g.cache.incr(quota_key)
quota_limit = getattr(g, "sr_%s_quota" % type)
if subreddit_quota > quota_limit and container.use_quotas:
form.set_html(".status", errors.SUBREDDIT_RATELIMIT)
c.errors.add(errors.SUBREDDIT_RATELIMIT)
form.set_error(errors.SUBREDDIT_RATELIMIT, None)
return
# if we are (strictly) friending, the container
# had better be the current user.

View File

@@ -62,6 +62,7 @@ error_list = dict((
('BAD_SR_NAME', _('that name isn\'t going to work')),
('RATELIMIT', _('you are doing that too much. try again in %(time)s.')),
('QUOTA_FILLED', _("You've submitted too many links recently. Please try again in an hour.")),
('SUBREDDIT_RATELIMIT', _("you are doing that too much. try again later.")),
('EXPIRED', _('your session has expired')),
('DRACONIAN', _('you must accept the terms first')),
('BANNED_IP', "IP banned"),

View File

@@ -75,6 +75,10 @@ class Globals(object):
'min_membership_create_community',
'bcrypt_work_factor',
'cassandra_pool_size',
'sr_banned_quota',
'sr_moderator_quota',
'sr_contributor_quota',
'sr_quota_time',
],
ConfigValue.float: [

View File

@@ -79,6 +79,7 @@ class Subreddit(Thing, Printable):
link_flair_position = '', # one of ('', 'left', 'right')
flair_self_assign_enabled = False,
link_flair_self_assign_enabled = False,
use_quotas = True,
)
_essentials = ('type', 'name', 'lang')
_data_int_props = Thing._data_int_props + ('mod_actions', 'reported')