mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-27 07:48:16 -05:00
Implement domain bans that inform user of block at submit time.
This commit is contained in:
@@ -187,6 +187,7 @@ class ApiController(RedditController):
|
||||
VCaptcha(),
|
||||
VRatelimit(rate_user = True, rate_ip = True,
|
||||
prefix = "rate_submit_"),
|
||||
VShamedDomain('url'),
|
||||
ip = ValidIP(),
|
||||
sr = VSubmitSR('sr', 'kind'),
|
||||
url = VUrl(['url', 'sr', 'resubmit']),
|
||||
@@ -248,7 +249,8 @@ class ApiController(RedditController):
|
||||
check_domain = True
|
||||
|
||||
# check for no url, or clear that error field on return
|
||||
if form.has_errors("url", errors.NO_URL, errors.BAD_URL):
|
||||
if form.has_errors("url", errors.NO_URL, errors.BAD_URL,
|
||||
errors.DOMAIN_BANNED):
|
||||
pass
|
||||
elif form.has_errors("url", errors.ALREADY_SUB):
|
||||
check_domain = False
|
||||
@@ -266,13 +268,8 @@ class ApiController(RedditController):
|
||||
g.log.warning("%s is trying to submit url=None (title: %r)"
|
||||
% (request.ip, title))
|
||||
elif check_domain:
|
||||
|
||||
banmsg = is_banned_domain(url, request.ip)
|
||||
|
||||
# Uncomment if we want to let spammers know we're on to them
|
||||
# if banmsg:
|
||||
# form.set_html(".field-url.BAD_URL", banmsg)
|
||||
# return
|
||||
|
||||
else:
|
||||
form.has_errors('text', errors.TOO_LONG)
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@ error_list = dict((
|
||||
('OAUTH2_ACCESS_DENIED', _('access denied by the user')),
|
||||
('CONFIRM', _("please confirm the form")),
|
||||
('NO_API', _('cannot perform this action via the API')),
|
||||
('DOMAIN_BANNED', _('%(domain)s is not allowed on reddit: %(reason)s')),
|
||||
))
|
||||
errors = Storage([(e, e) for e in error_list.keys()])
|
||||
|
||||
|
||||
@@ -1025,6 +1025,17 @@ class VUrl(VRequired):
|
||||
pass
|
||||
return params
|
||||
|
||||
class VShamedDomain(Validator):
|
||||
def run(self, url):
|
||||
if not url:
|
||||
return
|
||||
|
||||
is_shamed, domain, reason = is_shamed_domain(url, request.ip)
|
||||
|
||||
if is_shamed:
|
||||
self.set_error(errors.DOMAIN_BANNED, dict(domain=domain,
|
||||
reason=reason))
|
||||
|
||||
class VExistingUname(VRequired):
|
||||
def __init__(self, item, *a, **kw):
|
||||
VRequired.__init__(self, item, errors.NO_USER, *a, **kw)
|
||||
|
||||
@@ -329,6 +329,9 @@ def is_banned_IP(ip):
|
||||
def is_banned_domain(dom, ip):
|
||||
return None
|
||||
|
||||
def is_shamed_domain(dom, ip):
|
||||
return False, None, None
|
||||
|
||||
def valid_thing(v, karma, *a, **kw):
|
||||
return not v._thing1._spam
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ ${thing.formtabs_menu}
|
||||
<input id="url" name="url" type="text" value="${thing.url}"/>
|
||||
${error_field("NO_URL", "url", "div")}
|
||||
${error_field("BAD_URL", "url", "div")}
|
||||
${error_field("DOMAIN_BANNED", "url", "div")}
|
||||
${error_field("ALREADY_SUB", "url", "div")}
|
||||
${error_field("NO_LINKS", "sr")}
|
||||
${error_field("NO_SELFS", "sr")}
|
||||
|
||||
Reference in New Issue
Block a user