mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-27 15:58:06 -05:00
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.
This commit is contained in:
committed by
Neil Williams
parent
de2102e975
commit
3735033907
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -348,56 +348,59 @@ def panel_size(state):
|
||||
# Appends to the list "attrs" a tuple of:
|
||||
# <priority (higher trumps lower), letter,
|
||||
# css class, i18n'ed mouseover label, hyperlink (opt), img (opt)>
|
||||
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) )
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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]:
|
||||
|
||||
@@ -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 }
|
||||
|
||||
|
||||
@@ -66,9 +66,9 @@
|
||||
%endif
|
||||
</%def>
|
||||
|
||||
<%def name="distinguish_setter(value)">
|
||||
<%def name="distinguish_setter(name, value=None)">
|
||||
<a href="javascript:void(0)"
|
||||
onclick="return set_distinguish(this, '${value}')">${_(value)}</a>
|
||||
onclick="return set_distinguish(this, '${value or name}')">${_(name)}</a>
|
||||
</%def>
|
||||
|
||||
<%def name="distinguish()">
|
||||
@@ -81,9 +81,14 @@
|
||||
<span class="option error">
|
||||
${_("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
|
||||
|
||||
/ 
|
||||
<a class="nonbutton" href="/help/moderation#Distinguishing">
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
<% (src, alt, width, height) = img %>
|
||||
<img src="${src}" alt="${alt}" width="${width}" height="${height}"/>
|
||||
%else:
|
||||
${abbv}
|
||||
${unsafe(abbv)}
|
||||
%endif
|
||||
</a>
|
||||
%else:
|
||||
|
||||
Reference in New Issue
Block a user