mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
Use is_moderator_somewhere for moderatorship checks.
This should be a much lighter weight check than checking reverse_moderator_ids on every request.
This commit is contained in:
@@ -1072,8 +1072,7 @@ class RedditController(MinimalController):
|
||||
c.modhash = c.user.modhash()
|
||||
if hasattr(c.user, 'msgtime') and c.user.msgtime:
|
||||
c.have_messages = c.user.msgtime
|
||||
c.show_mod_mail = Subreddit.reverse_moderator_ids(c.user)
|
||||
c.have_mod_messages = getattr(c.user, "modmsgtime", False)
|
||||
c.have_mod_messages = bool(c.user.modmsgtime)
|
||||
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
|
||||
|
||||
@@ -348,10 +348,9 @@ class IdentityJsonTemplate(ThingJsonTemplate):
|
||||
)
|
||||
|
||||
def thing_attr(self, thing, attr):
|
||||
from r2.models import Subreddit
|
||||
if attr == "is_mod":
|
||||
t = thing.lookups[0] if isinstance(thing, Wrapped) else thing
|
||||
return bool(Subreddit.reverse_moderator_ids(t))
|
||||
return t.is_moderator_somewhere
|
||||
return ThingJsonTemplate.thing_attr(self, thing, attr)
|
||||
|
||||
class AccountJsonTemplate(IdentityJsonTemplate):
|
||||
|
||||
@@ -943,7 +943,7 @@ class MessagePage(Reddit):
|
||||
"/message/selfreply"],
|
||||
sr_path = False),
|
||||
NamedButton('sent', sr_path = False)]
|
||||
if c.show_mod_mail:
|
||||
if c.user_is_loggedin and c.user.is_moderator_somewhere:
|
||||
buttons.append(ModeratorMailButton(menu.modmail, "moderator",
|
||||
sr_path = False))
|
||||
if not c.default_sr:
|
||||
@@ -1976,7 +1976,7 @@ class SubredditTopBar(CachedTemplate):
|
||||
reddits.append(RandomSubscription)
|
||||
if c.user.friends:
|
||||
reddits.append(Friends)
|
||||
if c.show_mod_mail:
|
||||
if c.user.is_moderator_somewhere:
|
||||
reddits.append(Mod)
|
||||
return NavMenu([SubredditButton(sr, css_class=css_classes.get(sr))
|
||||
for sr in reddits],
|
||||
@@ -4297,7 +4297,7 @@ class ListingChooser(Templated):
|
||||
self.add_item("global", _("explore"), path="/explore")
|
||||
self.add_item("other", _("everything"), site=All,
|
||||
description=_("from all subreddits"))
|
||||
if c.show_mod_mail:
|
||||
if c.user_is_loggedin and c.user.is_moderator_somewhere:
|
||||
self.add_item("other", _("moderating"), site=Mod,
|
||||
description=_("subreddits you mod"))
|
||||
|
||||
|
||||
@@ -1851,7 +1851,7 @@ class ModeratorInbox(Relation(Subreddit, Message)):
|
||||
if perms.get('mail', False))
|
||||
moderators = Account._byID(mod_ids, data=True, return_dict=False)
|
||||
for m in moderators:
|
||||
if obj.author_id != m._id and not getattr(m, 'modmsgtime', None):
|
||||
if obj.author_id != m._id and not m.modmsgtime:
|
||||
m.modmsgtime = obj._date
|
||||
m._commit()
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ ${unsafe(safemarkdown(_("All feeds are invalidated if you change your password,
|
||||
% endif
|
||||
</td>
|
||||
</tr>
|
||||
%if c.show_mod_mail:
|
||||
%if c.user.is_moderator_somewhere:
|
||||
<tr>
|
||||
<th>your moderator inbox</th>
|
||||
<td class="prefright">
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
mail_path = '/message/inbox/'
|
||||
%>
|
||||
${plain_link('', mail_path, _sr_path=False, _class=mail_img_class, _id='mail')}
|
||||
%if c.show_mod_mail:
|
||||
%if c.user_is_loggedin and c.user.is_moderator_somewhere:
|
||||
<%
|
||||
mail_path = '/message/moderator/'
|
||||
if c.have_mod_messages:
|
||||
|
||||
@@ -97,7 +97,7 @@
|
||||
title = mail_img_title, _sr_path = False,
|
||||
_id = "mail", _class=mail_img_class)}
|
||||
${separator("|")}
|
||||
%if c.show_mod_mail:
|
||||
%if c.user_is_loggedin and c.user.is_moderator_somewhere:
|
||||
<%
|
||||
if c.have_mod_messages:
|
||||
mail_img_class = 'havemail'
|
||||
|
||||
Reference in New Issue
Block a user