From 3735033907f25ce02be6506b7aa0dd09944297b4 Mon Sep 17 00:00:00 2001 From: Max Goodman Date: Tue, 20 Sep 2011 14:32:42 -0700 Subject: [PATCH] Add support for special user distingushes. Special distinguishes are granted by setting "special_distinguish_*" properties on an Account. A post can only be a single type of [admin, special, mod] distinguished. Admins can be granted a special distinguish. --- r2/r2/controllers/api.py | 4 ++-- r2/r2/controllers/reddit_base.py | 1 + r2/r2/controllers/validator/validator.py | 9 +++++--- r2/r2/lib/pages/things.py | 4 ++-- r2/r2/lib/template_helpers.py | 27 +++++++++++++----------- r2/r2/models/account.py | 7 ++++++ r2/r2/models/builder.py | 11 ++++++++-- r2/r2/public/static/css/reddit.css | 1 + r2/r2/templates/printablebuttons.html | 17 ++++++++++++--- r2/r2/templates/wrappeduser.html | 2 +- 10 files changed, 58 insertions(+), 25 deletions(-) diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 5760edeb0..b96031acc 100644 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -1409,9 +1409,9 @@ class ApiController(RedditController): admintools.unspam(thing, c.user.name) @validatedForm(VUser(), VModhash(), - VSrCanDistinguish('id'), + VCanDistinguish(('id', 'how')), thing = VByName('id'), - how = VOneOf('how', ('yes','no','admin'))) + how = VOneOf('how', ('yes','no','admin','special'))) def POST_distinguish(self, form, jquery, thing, how): if not thing:return thing.distinguished = how diff --git a/r2/r2/controllers/reddit_base.py b/r2/r2/controllers/reddit_base.py index bf3ee942d..4a940d4a1 100644 --- a/r2/r2/controllers/reddit_base.py +++ b/r2/r2/controllers/reddit_base.py @@ -733,6 +733,7 @@ class RedditController(MinimalController): else: c.show_mod_mail = Subreddit.reverse_moderator_ids(c.user) c.user_is_admin = maybe_admin and c.user.name in g.admins + c.user_special_distinguish = c.user.special_distinguish() c.user_is_sponsor = c.user_is_admin or c.user.name in g.sponsors if request.path != '/validuser' and not g.disallow_db_writes: c.user.update_last_visit(c.start_time) diff --git a/r2/r2/controllers/validator/validator.py b/r2/r2/controllers/validator/validator.py index 5f5aac1cc..ad4e86016 100644 --- a/r2/r2/controllers/validator/validator.py +++ b/r2/r2/controllers/validator/validator.py @@ -659,8 +659,8 @@ class VFlairManager(VSrModerator): subreddit administration.""" pass -class VSrCanDistinguish(VByName): - def run(self, thing_name): +class VCanDistinguish(VByName): + def run(self, thing_name, how): if c.user_is_admin: return True elif c.user_is_loggedin: @@ -670,8 +670,11 @@ class VSrCanDistinguish(VByName): # comment, because this should only be used on links and # comments subreddit = item.subreddit_slow - if subreddit.can_distinguish(c.user): + if how in ("yes", "no") and subreddit.can_distinguish(c.user): return True + elif how in ("special", "no") and c.user_special_distinguish: + return True + abort(403,'forbidden') class VSrCanAlter(VByName): diff --git a/r2/r2/lib/pages/things.py b/r2/r2/lib/pages/things.py index 48352629b..5c92b58e9 100644 --- a/r2/r2/lib/pages/things.py +++ b/r2/r2/lib/pages/things.py @@ -98,7 +98,7 @@ class LinkButtons(PrintableButtons): # do we show the distinguish button? among other things, # we never want it to appear on link listings -- only # comments pages - show_distinguish = (is_author and thing.can_ban + show_distinguish = (is_author and (thing.can_ban or c.user_special_distinguish) and getattr(thing, "expand_children", False)) kw = {} @@ -143,7 +143,7 @@ class CommentButtons(PrintableButtons): # do we show the delete button? show_delete = is_author and delete and not thing._deleted - show_distinguish = is_author and thing.can_ban + show_distinguish = is_author and (thing.can_ban or c.user_special_distinguish) PrintableButtons.__init__(self, "commentbuttons", thing, is_author = is_author, diff --git a/r2/r2/lib/template_helpers.py b/r2/r2/lib/template_helpers.py index d6fea7ab5..7c87f03e8 100644 --- a/r2/r2/lib/template_helpers.py +++ b/r2/r2/lib/template_helpers.py @@ -348,56 +348,59 @@ def panel_size(state): # Appends to the list "attrs" a tuple of: # -def add_attr(attrs, code, label=None, link=None): +def add_attr(attrs, kind, label=None, link=None, cssclass=None, symbol=None): from r2.lib.template_helpers import static img = None + symbol = symbol or kind - if code == 'F': + if kind == 'F': priority = 1 cssclass = 'friend' if not label: label = _('friend') if not link: link = '/prefs/friends' - elif code == 'S': + elif kind == 'S': priority = 2 cssclass = 'submitter' if not label: label = _('submitter') if not link: raise ValueError ("Need a link") - elif code == 'M': + elif kind == 'M': priority = 3 cssclass = 'moderator' if not label: raise ValueError ("Need a label") if not link: raise ValueError ("Need a link") - elif code == 'A': + elif kind == 'A': priority = 4 cssclass = 'admin' if not label: label = _('reddit admin, speaking officially') if not link: link = '/help/faq#Whorunsreddit' - elif code in ('X', '@'): + elif kind in ('X', '@'): priority = 5 cssclass = 'gray' if not label: raise ValueError ("Need a label") - elif code == 'V': + elif kind == 'V': priority = 6 cssclass = 'green' if not label: raise ValueError ("Need a label") - elif code == 'B': + elif kind == 'B': priority = 7 cssclass = 'wrong' if not label: raise ValueError ("Need a label") - elif code.startswith ('trophy:'): - img = (code[7:], '!', 11, 8) + elif kind == 'special': + priority = 98 + elif kind.startswith ('trophy:'): + img = (kind[7:], '!', 11, 8) priority = 99 cssclass = 'recent-trophywinner' if not label: @@ -405,6 +408,6 @@ def add_attr(attrs, code, label=None, link=None): if not link: raise ValueError ("Need a link") else: - raise ValueError ("Got weird code [%s]" % code) + raise ValueError ("Got weird kind [%s]" % kind) - attrs.append( (priority, code, cssclass, label, link, img) ) + attrs.append( (priority, symbol, cssclass, label, link, img) ) diff --git a/r2/r2/models/account.py b/r2/r2/models/account.py index ad6c7e977..214e25008 100644 --- a/r2/r2/models/account.py +++ b/r2/r2/models/account.py @@ -388,6 +388,13 @@ class Account(Thing): def cup_info(self): return g.hardcache.get("cup_info-%d" % self._id) + def special_distinguish(self): + if self._t.get("special_distinguish_name"): + return dict((k, self._t.get("special_distinguish_"+k, None)) + for k in ("name", "kind", "symbol", "cssclass", "label", "link")) + else: + return None + def quota_key(self, kind): return "user_%s_quotas-%s" % (kind, self.name) diff --git a/r2/r2/models/builder.py b/r2/r2/models/builder.py index a25789075..fc7132095 100644 --- a/r2/r2/models/builder.py +++ b/r2/r2/models/builder.py @@ -124,8 +124,8 @@ class Builder(object): if hasattr(item, "distinguished"): if item.distinguished == 'yes': w.distinguished = 'moderator' - elif item.distinguished == 'admin': - w.distinguished = 'admin' + elif item.distinguished in ('admin', 'special'): + w.distinguished = item.distinguished try: w.author = authors.get(item.author_id) @@ -152,6 +152,13 @@ class Builder(object): if w.distinguished == 'moderator': add_attr(w.attribs, 'M', label=modlabel[item.sr_id], link=modlink[item.sr_id]) + + if w.distinguished == 'special': + args = w.author.special_distinguish() + args.pop('name') + if not args.get('kind'): + args['kind'] = 'special' + add_attr(w.attribs, **args) if False and w.author and c.user_is_admin: for attr in email_attrses[w.author._id]: diff --git a/r2/r2/public/static/css/reddit.css b/r2/r2/public/static/css/reddit.css index 68e473ea2..d205b9398 100644 --- a/r2/r2/public/static/css/reddit.css +++ b/r2/r2/public/static/css/reddit.css @@ -586,6 +586,7 @@ ul.flat-vert {text-align: left;} .tagline .submitter { color: #0055df } .tagline .moderator, .green { color: #228822 } .tagline .admin { color: #ff0011; } +.tagline .alum { color: #BE1337; } .tagline a.author.admin { font-weight: bold } .tagline a:hover { text-decoration: underline } diff --git a/r2/r2/templates/printablebuttons.html b/r2/r2/templates/printablebuttons.html index 4b8a183c4..1a1387892 100644 --- a/r2/r2/templates/printablebuttons.html +++ b/r2/r2/templates/printablebuttons.html @@ -66,9 +66,9 @@ %endif -<%def name="distinguish_setter(value)"> +<%def name="distinguish_setter(name, value=None)"> ${_(value)} + onclick="return set_distinguish(this, '${value or name}')">${_(name)} <%def name="distinguish()"> @@ -81,9 +81,14 @@ ${_("distinguish this?")} + ## Note: can_ban is logically equivalent to can_distinguish at this time. + %if thing.can_ban: ${distinguish_setter('yes')} - / + / + %endif + + ${distinguish_setter('no')} @@ -92,6 +97,12 @@ ${distinguish_setter('admin')} %endif + + %if c.user_special_distinguish: + / + ${distinguish_setter(c.user_special_distinguish['name'], 'special')} + + %endif / diff --git a/r2/r2/templates/wrappeduser.html b/r2/r2/templates/wrappeduser.html index 882363bac..a1664564c 100644 --- a/r2/r2/templates/wrappeduser.html +++ b/r2/r2/templates/wrappeduser.html @@ -62,7 +62,7 @@ <% (src, alt, width, height) = img %> ${alt} %else: - ${abbv} + ${unsafe(abbv)} %endif %else: