Skip to content
This repository
Browse code

Implement domain bans that inform user of block at submit time.

commit 44ebdeb378f4bf09d6bd1f395764868b57d9fd82 1 parent dbaa48e
Neil Williams authored June 04, 2012
11  r2/r2/controllers/api.py
@@ -187,6 +187,7 @@ def POST_compose(self, form, jquery, to, subject, body, ip):
187 187
                    VCaptcha(),
188 188
                    VRatelimit(rate_user = True, rate_ip = True,
189 189
                               prefix = "rate_submit_"),
  190
+                   VShamedDomain('url'),
190 191
                    ip = ValidIP(),
191 192
                    sr = VSubmitSR('sr', 'kind'),
192 193
                    url = VUrl(['url', 'sr', 'resubmit']),
@@ -248,7 +249,8 @@ def POST_submit(self, form, jquery, url, selftext, kind, title,
248 249
             check_domain = True
249 250
 
250 251
             # check for no url, or clear that error field on return
251  
-            if form.has_errors("url", errors.NO_URL, errors.BAD_URL):
  252
+            if form.has_errors("url", errors.NO_URL, errors.BAD_URL,
  253
+                                      errors.DOMAIN_BANNED):
252 254
                 pass
253 255
             elif form.has_errors("url", errors.ALREADY_SUB):
254 256
                 check_domain = False
@@ -266,13 +268,8 @@ def POST_submit(self, form, jquery, url, selftext, kind, title,
266 268
                 g.log.warning("%s is trying to submit url=None (title: %r)"
267 269
                               % (request.ip, title))
268 270
             elif check_domain:
269  
-                banmsg = is_banned_domain(url, request.ip)
270  
-
271  
-# Uncomment if we want to let spammers know we're on to them
272  
-#            if banmsg:
273  
-#                form.set_html(".field-url.BAD_URL", banmsg)
274  
-#                return
275 271
 
  272
+                banmsg = is_banned_domain(url, request.ip)
276 273
         else:
277 274
             form.has_errors('text', errors.TOO_LONG)
278 275
 
1  r2/r2/controllers/errors.py
@@ -94,6 +94,7 @@
94 94
         ('OAUTH2_ACCESS_DENIED', _('access denied by the user')),
95 95
         ('CONFIRM', _("please confirm the form")),
96 96
         ('NO_API', _('cannot perform this action via the API')),
  97
+        ('DOMAIN_BANNED', _('%(domain)s is not allowed on reddit: %(reason)s')),
97 98
     ))
98 99
 errors = Storage([(e, e) for e in error_list.keys()])
99 100
 
11  r2/r2/controllers/validator/validator.py
@@ -1025,6 +1025,17 @@ def param_docs(self):
1025 1025
             pass
1026 1026
         return params
1027 1027
 
  1028
+class VShamedDomain(Validator):
  1029
+    def run(self, url):
  1030
+        if not url:
  1031
+            return
  1032
+
  1033
+        is_shamed, domain, reason = is_shamed_domain(url, request.ip)
  1034
+
  1035
+        if is_shamed:
  1036
+            self.set_error(errors.DOMAIN_BANNED, dict(domain=domain,
  1037
+                                                      reason=reason))
  1038
+
1028 1039
 class VExistingUname(VRequired):
1029 1040
     def __init__(self, item, *a, **kw):
1030 1041
         VRequired.__init__(self, item, errors.NO_USER, *a, **kw)
3  r2/r2/models/admintools.py
@@ -329,6 +329,9 @@ def is_banned_IP(ip):
329 329
 def is_banned_domain(dom, ip):
330 330
     return None
331 331
 
  332
+def is_shamed_domain(dom, ip):
  333
+    return False, None, None
  334
+
332 335
 def valid_thing(v, karma, *a, **kw):
333 336
     return not v._thing1._spam
334 337
 
1  r2/r2/templates/newlink.html
@@ -72,6 +72,7 @@

1 note on commit 44ebdeb

sixcorners

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.
Something went wrong with that request. Please try again.