Allow subreddit spam queries to be limited to links or comments.

This commit is contained in:
bsimpson63
2013-04-22 14:28:27 -04:00
parent 77f2f12fc6
commit 75d5b709f2
3 changed files with 81 additions and 62 deletions

View File

@@ -499,13 +499,22 @@ class FrontController(RedditController, OAuth2ResourceController):
location="log",
extension_handling=False).render()
def _make_spamlisting(self, location, num, after, reverse, count):
def _make_spamlisting(self, location, only, num, after, reverse, count):
include_links, include_comments = True, True
if only == 'links':
include_comments = False
elif only == 'comments':
include_links = False
if location == 'reports':
query = c.site.get_reported()
query = c.site.get_reported(include_links=include_links,
include_comments=include_comments)
elif location == 'spam':
query = c.site.get_spam()
query = c.site.get_spam(include_links=include_links,
include_comments=include_comments)
elif location == 'modqueue':
query = c.site.get_modqueue()
query = c.site.get_modqueue(include_links=include_links,
include_comments=include_comments)
elif location == 'unmoderated':
query = c.site.get_unmoderated()
else:
@@ -637,14 +646,27 @@ class FrontController(RedditController, OAuth2ResourceController):
@base_listing
@prevent_framing_and_css(allow_cname_frame=True)
@validate(VSrModerator(perms='posts'),
location=nop('location'))
def GET_spamlisting(self, location, num, after, reverse, count):
location=nop('location'),
only=VOneOf('only', ('links', 'comments')))
def GET_spamlisting(self, location, only, num, after, reverse, count):
c.allow_styles = True
c.profilepage = True
pane = self._make_spamlisting(location, num, after, reverse, count)
pane = self._make_spamlisting(location, only, num, after, reverse,
count)
if c.user.pref_private_feeds:
extension_handling = "private"
return EditReddit(content=pane, location=location).render()
if location in ('reports', 'spam', 'modqueue'):
buttons = [NavButton(_('links and comments'), None, opt='only'),
NavButton(_('links'), 'links', opt='only'),
NavButton(_('comments'), 'comments', opt='only')]
menus = [NavMenu(buttons, base_path=request.path, title=_('show'),
type='lightdrop')]
else:
menus = None
return EditReddit(content=pane,
location=location,
nav_menus=menus).render()
@base_listing
@prevent_framing_and_css(allow_cname_frame=True)

View File

@@ -348,20 +348,29 @@ def get_spam_comments(sr_id):
return Comment._query(Comment.c.sr_id == sr_id,
Comment.c._spam == True,
sort = db_sort('new'))
@merged_cached_query
def get_spam(sr, user=None):
def moderated_srids(sr, user):
if isinstance(sr, (ModContribSR, MultiReddit)):
srs = Subreddit._byID(sr.sr_ids, return_dict=False)
if user:
srs = [sr for sr in srs
if sr.is_moderator_with_perms(user, 'posts')]
q = []
q.extend(get_spam_links(sr) for sr in srs)
q.extend(get_spam_comments(sr) for sr in srs)
return q
return [sr._id for sr in srs]
elif not user or sr.is_moderator_with_perms(user, 'posts'):
return [sr._id]
else:
return [get_spam_links(sr),
get_spam_comments(sr)]
return []
@merged_cached_query
def get_spam(sr, user=None, include_links=True, include_comments=True):
sr_ids = moderated_srids(sr, user)
queries = []
if include_links:
queries.append(get_spam_links)
if include_comments:
queries.append(get_spam_comments)
return [query(sr_id) for sr_id, query in itertools.product(sr_ids, queries)]
@cached_query(SubredditQueryCache)
def get_spam_filtered_links(sr_id):
@@ -399,19 +408,15 @@ def get_reported_comments(sr_id):
sort = db_sort('new'))
@merged_cached_query
def get_reported(sr, user=None):
if isinstance(sr, (ModContribSR, MultiReddit)):
srs = Subreddit._byID(sr.sr_ids, return_dict=False)
if user:
srs = [sr for sr in srs
if sr.is_moderator_with_perms(user, 'posts')]
q = []
q.extend(get_reported_links(sr) for sr in srs)
q.extend(get_reported_comments(sr) for sr in srs)
return q
else:
return [get_reported_links(sr),
get_reported_comments(sr)]
def get_reported(sr, user=None, include_links=True, include_comments=True):
sr_ids = moderated_srids(sr, user)
queries = []
if include_links:
queries.append(get_reported_links)
if include_comments:
queries.append(get_reported_comments)
return [query(sr_id) for sr_id, query in itertools.product(sr_ids, queries)]
@cached_query(SubredditQueryCache)
def get_unmoderated_links(sr_id):
@@ -425,36 +430,23 @@ def get_unmoderated_links(sr_id):
return q
@merged_cached_query
def get_modqueue(sr, user=None):
q = []
if isinstance(sr, (ModContribSR, MultiReddit)):
srs = Subreddit._byID(sr.sr_ids, return_dict=False)
if user:
srs = [sr for sr in srs
if sr.is_moderator_with_perms(user, 'posts')]
q.extend(get_reported_links(sr) for sr in srs)
q.extend(get_reported_comments(sr) for sr in srs)
q.extend(get_spam_filtered_links(sr) for sr in srs)
q.extend(get_spam_filtered_comments(sr) for sr in srs)
else:
q.append(get_reported_links(sr))
q.append(get_reported_comments(sr))
q.append(get_spam_filtered_links(sr))
q.append(get_spam_filtered_comments(sr))
return q
def get_modqueue(sr, user=None, include_links=True, include_comments=True):
sr_ids = moderated_srids(sr, user)
queries = []
if include_links:
queries.append(get_reported_links)
queries.append(get_spam_filtered_links)
if include_comments:
queries.append(get_reported_comments)
queries.append(get_spam_filtered_comments)
return [query(sr_id) for sr_id, query in itertools.product(sr_ids, queries)]
@merged_cached_query
def get_unmoderated(sr, user=None):
q = []
if isinstance(sr, MultiReddit):
srs = Subreddit._byID(sr.sr_ids, return_dict=False)
if user:
srs = [sr for sr in srs
if sr.is_moderator_with_perms(user, 'posts')]
q.extend(get_unmoderated_links(sr) for sr in srs)
else:
q.append(get_unmoderated_links(sr))
return q
sr_ids = moderated_srids(sr, user)
queries = [get_unmoderated_links]
return [query(sr_id) for sr_id, query in itertools.product(sr_ids, queries)]
def get_domain_links(domain, sort, time):
from r2.lib.db import operators

View File

@@ -497,17 +497,22 @@ class Subreddit(Thing, Printable):
from r2.lib.db import queries
return queries.get_links(self, sort, time)
def get_spam(self):
def get_spam(self, include_links=True, include_comments=True):
from r2.lib.db import queries
return queries.get_spam(self, user=c.user)
return queries.get_spam(self, user=c.user, include_links=include_links,
include_comments=include_comments)
def get_reported(self):
def get_reported(self, include_links=True, include_comments=True):
from r2.lib.db import queries
return queries.get_reported(self, user=c.user)
return queries.get_reported(self, user=c.user,
include_links=include_links,
include_comments=include_comments)
def get_modqueue(self):
def get_modqueue(self, include_links=True, include_comments=True):
from r2.lib.db import queries
return queries.get_modqueue(self, user=c.user)
return queries.get_modqueue(self, user=c.user,
include_links=include_links,
include_comments=include_comments)
def get_unmoderated(self):
from r2.lib.db import queries