Account.needs_captcha: add hook, use live_config

This allows the minimum amount of karma needed to be exempt from the
captcha to be modified via live config. In addition, it adds the
ability to set a comment karma minimum, where previously it was required
to get link karma in order to be exempt from the captcha.

A hook has also been added to the function for private-code purposes.
This commit is contained in:
Chad Birch
2015-02-23 19:30:28 -07:00
parent 6812738ebe
commit 9c8be783e1
3 changed files with 20 additions and 1 deletions

View File

@@ -708,6 +708,9 @@ proxy_gilding_accounts =
cflag_min_votes = 7
cflag_lower_bound = 0.4
cflag_upper_bound = 0.6
# Karma requirements to disable captchas - must meet at least one
captcha_exempt_link_karma = 1
captcha_exempt_comment_karma = 1
#### Features
# Availability for the "force HTTPS" option

View File

@@ -301,6 +301,8 @@ class Globals(object):
'frontend_logging',
],
ConfigValue.int: [
'captcha_exempt_comment_karma',
'captcha_exempt_link_karma',
'cflag_min_votes',
],
ConfigValue.float: [

View File

@@ -294,7 +294,21 @@ class Account(Thing):
return ",".join((timestamp, signature))
def needs_captcha(self):
return not g.disable_captcha and self.link_karma < 1
if g.disable_captcha:
return False
hook = hooks.get_hook("account.is_captcha_exempt")
captcha_exempt = hook.call_until_return(account=self)
if captcha_exempt:
return False
if self.link_karma >= g.live_config["captcha_exempt_link_karma"]:
return False
if self.comment_karma >= g.live_config["captcha_exempt_comment_karma"]:
return False
return True
def modhash(self, rand=None, test=False):
if c.oauth_user: