From 5ea7b2e3efb300b93e6ac02b37e39063aeaa31c2 Mon Sep 17 00:00:00 2001 From: KeyserSosa Date: Wed, 8 Jul 2009 11:24:49 -0700 Subject: [PATCH] * add nofollow to comment titles on low point (or banned) comments or links. * have submissions to banned reddits generate an error message on /submit. * make unicode user name pages 404 rather than 500 --- r2/r2/controllers/api.py | 4 +++- r2/r2/controllers/errors.py | 1 + r2/r2/controllers/validator/validator.py | 5 ++++- r2/r2/models/link.py | 9 +++++++-- r2/r2/public/static/css/reddit.css | 3 +++ r2/r2/templates/comment.html | 6 +++++- r2/r2/templates/newlink.html | 1 + 7 files changed, 24 insertions(+), 5 deletions(-) diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index ffd57f878..7184dfd07 100644 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -169,6 +169,7 @@ class ApiController(RedditController): return if form.has_errors('sr', errors.SUBREDDIT_NOEXIST, + errors.SUBREDDIT_NOTALLOWED, errors.SUBREDDIT_REQUIRED): # checking to get the error set in the form, but we can't # check for rate-limiting if there's no subreddit @@ -1344,7 +1345,8 @@ class ApiController(RedditController): form.has_errors('url', errors.NO_URL, errors.ALREADY_SUB) ): #if url == l.url, we're just editting something else pass - elif form.has_errors('sr', errors.SUBREDDIT_NOEXIST): + elif form.has_errors('sr', errors.SUBREDDIT_NOEXIST, + errors.SUBREDDIT_NOTALLOWED): pass elif (expire == 'expirein' and form.has_errors('timelimitlength', errors.BAD_NUMBER)): diff --git a/r2/r2/controllers/errors.py b/r2/r2/controllers/errors.py index d46972504..aa730268b 100644 --- a/r2/r2/controllers/errors.py +++ b/r2/r2/controllers/errors.py @@ -49,6 +49,7 @@ error_list = dict(( ('ALREADY_SUB', _("that link has already been submitted")), ('SUBREDDIT_EXISTS', _('that reddit already exists')), ('SUBREDDIT_NOEXIST', _('that reddit doesn\'t exist')), + ('SUBREDDIT_NOTALLOWED', _("you aren't allowed to post there.")), ('SUBREDDIT_REQUIRED', _('you must specify a reddit')), ('BAD_SR_NAME', _('that name isn\'t going to work')), ('RATELIMIT', _('you are trying to submit too fast. try again in %(time)s.')), diff --git a/r2/r2/controllers/validator/validator.py b/r2/r2/controllers/validator/validator.py index 451b025e3..b213d5e9d 100644 --- a/r2/r2/controllers/validator/validator.py +++ b/r2/r2/controllers/validator/validator.py @@ -500,7 +500,7 @@ class VSubmitSR(Validator): return None if sr and not (c.user_is_loggedin and sr.can_submit(c.user)): - abort(403, "forbidden") + self.set_error(errors.SUBREDDIT_NOTALLOWED) else: return sr @@ -599,6 +599,9 @@ class VExistingUname(VRequired): VRequired.__init__(self, item, errors.NO_USER, *a, **kw) def run(self, name): + # make sure the name satisfies our user name regexp before + # bothering to look it up. + name = chkuser(name) if name: try: return Account._by_name(name) diff --git a/r2/r2/models/link.py b/r2/r2/models/link.py index 210f601e1..0646f1a44 100644 --- a/r2/r2/models/link.py +++ b/r2/r2/models/link.py @@ -529,6 +529,13 @@ class Comment(Thing, Printable): item.profilepage = c.profilepage item.link = links.get(item.link_id) + if (item.link._score <= 1 or item.score < 3 or + item.link._spam or item._spam or item.author._spam): + + item.nofollow = True + else: + item.nofollow = False + if not hasattr(item, 'subreddit'): item.subreddit = item.subreddit_slow if not hasattr(item, 'target'): @@ -573,8 +580,6 @@ class Comment(Thing, Printable): item.editted = getattr(item, "editted", False) - #score less than 3, nofollow the links - item.nofollow = item._score < 3 #will get updated in builder item.num_children = 0 diff --git a/r2/r2/public/static/css/reddit.css b/r2/r2/public/static/css/reddit.css index f11165c77..6a45fc757 100644 --- a/r2/r2/public/static/css/reddit.css +++ b/r2/r2/public/static/css/reddit.css @@ -1456,6 +1456,9 @@ textarea.gray { color: gray; } -moz-outline: none; } +.toolbar .likes .score.likes {display: inline-block;} +.toolbar .dislikes .score.dislikes {display: inline-block;} + .toolbar a, .toolbar .clickable { cursor: pointer; color: #336699; diff --git a/r2/r2/templates/comment.html b/r2/r2/templates/comment.html index d50cf4649..50096384a 100644 --- a/r2/r2/templates/comment.html +++ b/r2/r2/templates/comment.html @@ -40,7 +40,11 @@ ${parent.midcol(not thing.collapsed, cls = cls)} %if c.profilepage: %if thing.link: %if thing.link.title: - + ${thing.link.title} %else: diff --git a/r2/r2/templates/newlink.html b/r2/r2/templates/newlink.html index 25e9b1272..c0ed709a2 100644 --- a/r2/r2/templates/newlink.html +++ b/r2/r2/templates/newlink.html @@ -93,6 +93,7 @@ ${thing.formtabs_menu} reddit.sr_cache = ${unsafe(thing.sr_searches)}; ${error_field("SUBREDDIT_NOEXIST", "sr", "div")} + ${error_field("SUBREDDIT_NOTALLOWED", "sr", "div")} ${error_field("SUBREDDIT_REQUIRED", "sr", "div")}