Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement mod pages on multireddits.

* modqueue
* spam
* reports
* trials
* modmail
  • Loading branch information...
commit 66124ef6c92913d542e009304588240829714bc8 1 parent d30b558
DEADB33F DEADB33F authored spladug committed
8 r2/r2/controllers/front.py
View
@@ -507,7 +507,7 @@ def _edit_modcontrib_reddit(self, location, num, after, reverse, count, created)
if not c.user_is_loggedin:
return self.abort404()
- if isinstance(c.site, ModSR):
+ if isinstance(c.site, (ModSR, MultiReddit)):
level = 'mod'
elif isinstance(c.site, ContribSR):
level = 'contrib'
@@ -602,6 +602,12 @@ def GET_editreddit(self, location, num, after, reverse, count, created,
if isinstance(c.site, ModContribSR):
return self._edit_modcontrib_reddit(location, num, after, reverse,
count, created)
+ elif isinstance(c.site, MultiReddit):
+ srs = Subreddit._byID(c.site.sr_ids, return_dict=False)
+ if not Subreddit.user_mods_all(c.user, srs) and not c.user_is_admin:
+ self.abort403()
+ return self._edit_modcontrib_reddit(location, num, after, reverse,
+ count, created)
elif isinstance(c.site, AllSR) and c.user_is_admin:
return self._edit_modcontrib_reddit(location, num, after, reverse,
count, created)
22 r2/r2/controllers/listingcontroller.py 100644 → 100755
View
@@ -658,7 +658,7 @@ def menus(self):
return [NavMenu(buttons, base_path = '/message/',
default = 'inbox', type = "flatlist")]
- elif not c.default_sr or self.where == 'moderator':
+ elif not c.default_sr or self.where in ('moderator', 'multi'):
buttons = (NavButton(_("all"), "inbox"),
NavButton(_("unread"), "unread"))
return [NavMenu(buttons, base_path = '/message/moderator/',
@@ -702,10 +702,14 @@ def builder_wrapper(thing):
def builder(self):
if (self.where == 'messages' or
- (self.where == "moderator" and self.subwhere != "unread")):
+ (self.where in ("moderator", "multi") and self.subwhere != "unread")):
root = c.user
message_cls = UserMessageBuilder
- if not c.default_sr:
+
+ if self.where == "multi":
+ root = c.site
+ message_cls = MultiredditMessageBuilder
+ elif not c.default_sr:
root = c.site
message_cls = SrMessageBuilder
elif self.where == 'moderator' and self.subwhere != 'unread':
@@ -758,6 +762,8 @@ def query(self):
q = queries.get_unread_inbox(c.user)
elif self.where == 'sent':
q = queries.get_sent(c.user)
+ elif self.where == 'multi' and self.subwhere == 'unread':
+ q = queries.merge_results(*[queries.get_unread_subreddit_messages(s) for s in self.srs])
elif self.where == 'moderator' and self.subwhere == 'unread':
if c.default_sr:
srids = Subreddit.reverse_moderator_ids(c.user)
@@ -766,7 +772,7 @@ def query(self):
*[queries.get_unread_subreddit_messages(s) for s in srs])
else:
q = queries.get_unread_subreddit_messages(c.site)
- elif self.where == 'moderator':
+ elif self.where in ('moderator', 'multi'):
if c.have_mod_messages and self.mark != 'false':
c.user.modmsgtime = False
c.user._commit()
@@ -791,7 +797,13 @@ def query(self):
def GET_listing(self, where, mark, message, subwhere = None, **env):
if not (c.default_sr or c.site.is_moderator(c.user) or c.user_is_admin):
abort(403, "forbidden")
- if not c.default_sr:
+ if isinstance(c.site, MultiReddit):
+ srs = Subreddit._byID(c.site.sr_ids, data=False, return_dict=False)
+ if not (c.user_is_admin or Subreddit.user_mods_all(c.user, srs)):
+ self.abort403()
+ self.where = "multi"
+ self.srs = srs
+ elif not c.default_sr:
self.where = "moderator"
else:
self.where = where
3  r2/r2/lib/comment_tree.py 100644 → 100755
View
@@ -479,9 +479,8 @@ def subreddit_messages(sr, update = False):
g.permacache.set(key, trees)
return trees
-def moderator_messages(user):
+def moderator_messages(sr_ids):
from r2.models import Subreddit
- sr_ids = Subreddit.reverse_moderator_ids(user)
def multi_load_tree(sr_ids):
srs = Subreddit._byID(sr_ids, return_dict = False)
10 r2/r2/lib/db/queries.py 100644 → 100755
View
@@ -1,5 +1,5 @@
from r2.models import Account, Link, Comment, Trial, Vote, SaveHide
-from r2.models import Message, Inbox, Subreddit, ModContribSR, ModeratorInbox
+from r2.models import Message, Inbox, Subreddit, ModContribSR, ModeratorInbox, MultiReddit
from r2.lib.db.thing import Thing, Merge
from r2.lib.db.operators import asc, desc, timeago
from r2.lib.db.sorts import epoch_seconds
@@ -335,7 +335,7 @@ def get_spam_comments(sr_id):
sort = db_sort('new'))
def get_spam(sr):
- if isinstance(sr, ModContribSR):
+ if isinstance(sr, (ModContribSR, MultiReddit)):
srs = Subreddit._byID(sr.sr_ids, return_dict=False)
results = []
results.extend(get_spam_links(sr) for sr in srs)
@@ -381,7 +381,7 @@ def get_reported_comments(sr_id):
sort = db_sort('new'))
def get_reported(sr):
- if isinstance(sr, ModContribSR):
+ if isinstance(sr, (ModContribSR, MultiReddit)):
srs = Subreddit._byID(sr.sr_ids, return_dict=False)
results = []
results.extend(get_reported_links(sr) for sr in srs)
@@ -433,7 +433,7 @@ def get_trials_links(sr):
return s
def get_trials(sr):
- if isinstance(sr, ModContribSR):
+ if isinstance(sr, (ModContribSR, MultiReddit)):
srs = Subreddit._byID(sr.sr_ids, return_dict=False)
return get_trials_links(srs)
else:
@@ -441,7 +441,7 @@ def get_trials(sr):
def get_modqueue(sr):
results = []
- if isinstance(sr, ModContribSR):
+ if isinstance(sr, (ModContribSR, MultiReddit)):
srs = Subreddit._byID(sr.sr_ids, return_dict=False)
for sr in srs:
12 r2/r2/models/builder.py 100644 → 100755
View
@@ -529,8 +529,18 @@ def __init__(self, user, **kw):
def get_tree(self):
if self.parent:
return conversation(self.user, self.parent)
- return moderator_messages(self.user)
+ sr_ids = Subreddit.reverse_moderator_ids(self.user)
+ return moderator_messages(sr_ids)
+class MultiredditMessageBuilder(MessageBuilder):
+ def __init__(self, user, **kw):
+ self.user = user
+ MessageBuilder.__init__(self, **kw)
+
+ def get_tree(self):
+ if self.parent:
+ return conversation(self.user, self.parent)
+ return moderator_messages(c.site.sr_ids)
class TopCommentBuilder(CommentBuilder):
"""A comment builder to fetch only the top-level, non-spam,
Please sign in to comment.
Something went wrong with that request. Please try again.