Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement domain bans that inform user of block at submit time.
  • Loading branch information
spladug committed Jun 5, 2012
1 parent dbaa48e commit 44ebdeb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
11 changes: 4 additions & 7 deletions r2/r2/controllers/api.py
Expand Up @@ -187,6 +187,7 @@ def POST_compose(self, form, jquery, to, subject, body, ip):
VCaptcha(),
VRatelimit(rate_user = True, rate_ip = True,
prefix = "rate_submit_"),
VShamedDomain('url'),
ip = ValidIP(),
sr = VSubmitSR('sr', 'kind'),
url = VUrl(['url', 'sr', 'resubmit']),
Expand Down Expand Up @@ -248,7 +249,8 @@ def POST_submit(self, form, jquery, url, selftext, kind, title,
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
Expand All @@ -266,13 +268,8 @@ def POST_submit(self, form, jquery, url, selftext, kind, title,
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

banmsg = is_banned_domain(url, request.ip)
else:
form.has_errors('text', errors.TOO_LONG)

Expand Down
1 change: 1 addition & 0 deletions r2/r2/controllers/errors.py
Expand Up @@ -94,6 +94,7 @@
('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()])

Expand Down
11 changes: 11 additions & 0 deletions r2/r2/controllers/validator/validator.py
Expand Up @@ -1025,6 +1025,17 @@ def param_docs(self):
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)
Expand Down
3 changes: 3 additions & 0 deletions r2/r2/models/admintools.py
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions r2/r2/templates/newlink.html
Expand Up @@ -72,6 +72,7 @@ <h1>${unsafe(_("submit to %(sr)s") % dict(sr=sr))}</h1>
<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")}
Expand Down

1 comment on commit 44ebdeb

@sixcorners
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of banning link shorteners why not follow the link and pull the rel="canonical" from the page, then use that link? Why not do this too for all pages? http://support.google.com/webmasters/bin/answer.py?hl=en&answer=139394

Please sign in to comment.