mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-24 06:18:08 -05:00
Add subreddit query for unmoderated links.
This commit is contained in:
@@ -461,6 +461,8 @@ class FrontController(RedditController):
|
||||
num = 1000
|
||||
elif location == 'modqueue':
|
||||
query = c.site.get_modqueue()
|
||||
elif location == 'unmoderated':
|
||||
query = c.site.get_unmoderated()
|
||||
else:
|
||||
raise ValueError
|
||||
|
||||
@@ -491,6 +493,8 @@ class FrontController(RedditController):
|
||||
if x._spam and verdict != 'mod-removed':
|
||||
return True # spam, unless banned by a moderator
|
||||
return False
|
||||
elif location == "unmoderated":
|
||||
return True
|
||||
else:
|
||||
raise ValueError
|
||||
|
||||
@@ -525,7 +529,7 @@ class FrontController(RedditController):
|
||||
raise ValueError
|
||||
|
||||
if ((level == 'mod' and
|
||||
location in ('reports', 'spam', 'trials', 'modqueue'))
|
||||
location in ('reports', 'spam', 'trials', 'modqueue', 'unmoderated'))
|
||||
or
|
||||
(level == 'all' and
|
||||
location == 'trials')):
|
||||
@@ -574,7 +578,8 @@ class FrontController(RedditController):
|
||||
c.allow_styles = True
|
||||
pane = SubredditStylesheet(site = c.site,
|
||||
stylesheet_contents = stylesheet_contents)
|
||||
elif location in ('reports', 'spam', 'trials', 'modqueue') and is_moderator:
|
||||
elif (location in ('reports', 'spam', 'trials', 'modqueue', 'unmoderated')
|
||||
and is_moderator):
|
||||
c.allow_styles = True
|
||||
pane = self._make_spamlisting(location, num, after, reverse, count)
|
||||
if c.user.pref_private_feeds:
|
||||
|
||||
@@ -42,6 +42,7 @@ from datetime import datetime
|
||||
import itertools
|
||||
import collections
|
||||
from copy import deepcopy
|
||||
from r2.lib.db.operators import and_, or_
|
||||
|
||||
from pylons import g
|
||||
query_cache = g.permacache
|
||||
@@ -409,6 +410,17 @@ def get_reported(sr):
|
||||
return [get_reported_links(sr),
|
||||
get_reported_comments(sr)]
|
||||
|
||||
@cached_query(SubredditQueryCache)
|
||||
def get_unmoderated_links(sr_id):
|
||||
q = Link._query(Link.c.sr_id == sr_id,
|
||||
Link.c._spam == (True, False),
|
||||
sort = db_sort('new'))
|
||||
|
||||
# Doesn't really work because will not return Links with no verdict
|
||||
q._filter(or_(and_(Link.c._spam == True, Link.c.verdict != 'mod-removed'),
|
||||
and_(Link.c._spam == False, Link.c.verdict != 'mod-approved')))
|
||||
return q
|
||||
|
||||
# TODO: Wow, what a hack. I'm doing this in a hurry to make
|
||||
# /r/blah/about/trials and /r/blah/about/modqueue work. At some point
|
||||
# before the heat death of the universe, we should start precomputing
|
||||
@@ -473,6 +485,16 @@ def get_modqueue(sr):
|
||||
q.append(get_spam_filtered_comments(sr))
|
||||
return q
|
||||
|
||||
@merged_cached_query
|
||||
def get_unmoderated(sr):
|
||||
q = []
|
||||
if isinstance(sr, MultiReddit):
|
||||
srs = Subreddit._byID(sr.sr_ids, return_dict=False)
|
||||
q.extend(get_unmoderated_links(sr) for sr in srs)
|
||||
else:
|
||||
q.append(get_unmoderated_links(sr))
|
||||
return q
|
||||
|
||||
def get_domain_links(domain, sort, time):
|
||||
from r2.lib.db import operators
|
||||
q = Link._query(operators.domain(Link.c.url) == filters._force_utf8(domain),
|
||||
@@ -687,9 +709,10 @@ def new_link(link):
|
||||
for domain in utils.UrlParser(link.url).domain_permutations():
|
||||
results.append(get_domain_links(domain, 'new', "all"))
|
||||
|
||||
if link._spam:
|
||||
with CachedQueryMutator() as m:
|
||||
with CachedQueryMutator() as m:
|
||||
if link._spam:
|
||||
m.insert(get_spam_links(sr), [link])
|
||||
m.insert(get_unmoderated_links(sr), [link])
|
||||
|
||||
add_queries(results, insert_items = link)
|
||||
amqp.add_item('new_link', link._fullname)
|
||||
@@ -1079,6 +1102,14 @@ def clear_reports(things):
|
||||
for q, deletes in query_cache_deletes:
|
||||
m.delete(q, deletes)
|
||||
|
||||
def mark_moderated(links):
|
||||
by_srid, srs = _by_srid(links)
|
||||
|
||||
with CachedQueryMutator() as m:
|
||||
for sr_id, sr_links in by_srid.iteritems():
|
||||
sr = srs[sr_id]
|
||||
m.delete(get_unmoderated_links(sr), sr_links)
|
||||
|
||||
def add_all_srs():
|
||||
"""Recalculates every listing query for every subreddit. Very,
|
||||
very slow."""
|
||||
|
||||
@@ -135,6 +135,7 @@ menu = MenuHandler(hot = _('hot'),
|
||||
flair = _("edit flair"),
|
||||
log = _("moderation log"),
|
||||
modqueue = _("moderation queue"),
|
||||
unmoderated = _("unmoderated links"),
|
||||
|
||||
popular = _("popular"),
|
||||
create = _("create"),
|
||||
|
||||
@@ -226,7 +226,8 @@ class Reddit(Templated):
|
||||
buttons += [NamedButton("banned", css_class="reddit-ban"),
|
||||
NamedButton("flair", css_class="reddit-flair")]
|
||||
|
||||
buttons.append(NamedButton("log", css_class="reddit-moderationlog"))
|
||||
buttons += [NamedButton("log", css_class="reddit-moderationlog"),
|
||||
NamedButton("unmoderated", css_class="reddit-unmoderated")]
|
||||
|
||||
return SideContentBox(_('moderation tools'),
|
||||
[NavMenu(buttons,
|
||||
|
||||
@@ -76,6 +76,7 @@ class AdminTools(object):
|
||||
if not auto:
|
||||
self.author_spammer(new_things, True)
|
||||
self.set_last_sr_ban(new_things)
|
||||
queries.mark_moderated(things)
|
||||
|
||||
queries.ban(new_things)
|
||||
|
||||
@@ -113,6 +114,7 @@ class AdminTools(object):
|
||||
self.set_last_sr_ban(things)
|
||||
|
||||
queries.unban(things, insert)
|
||||
queries.mark_moderated(things)
|
||||
|
||||
def author_spammer(self, things, spam):
|
||||
"""incr/decr the 'spammer' field for the author of every
|
||||
|
||||
@@ -349,6 +349,10 @@ class Subreddit(Thing, Printable):
|
||||
from r2.lib.db import queries
|
||||
return queries.get_modqueue(self)
|
||||
|
||||
def get_unmoderated(self):
|
||||
from r2.lib.db import queries
|
||||
return queries.get_unmoderated(self)
|
||||
|
||||
def get_all_comments(self):
|
||||
from r2.lib.db import queries
|
||||
return queries.get_sr_comments(self)
|
||||
|
||||
@@ -4410,6 +4410,7 @@ dd { margin-left: 20px; }
|
||||
.icon-menu .reddit-ban:before,
|
||||
.icon-menu .reddit-flair:before,
|
||||
.icon-menu .reddit-moderationlog:before,
|
||||
.icon-menu .reddit-unmoderated:before,
|
||||
.icon-menu .reddit-moderators:before,
|
||||
.icon-menu .moderator-mail:before,
|
||||
.icon-menu .reddit-contributors:before,
|
||||
@@ -4469,6 +4470,10 @@ dd { margin-left: 20px; }
|
||||
background-image: url(../reddit_moderationlog.png); /* SPRITE */
|
||||
margin-left: 1px;
|
||||
}
|
||||
.icon-menu .reddit-unmoderated:before {
|
||||
background-image: url(../reddit_unmoderated.png); /* SPRITE */
|
||||
margin-left: 1px;
|
||||
}
|
||||
.icon-menu .reddit-moderators:before {
|
||||
background-image: url(../shield.png); /* SPRITE */
|
||||
}
|
||||
|
||||
1
r2/r2/public/static/reddit_unmoderated.png
Symbolic link
1
r2/r2/public/static/reddit_unmoderated.png
Symbolic link
@@ -0,0 +1 @@
|
||||
eye.png
|
||||
Reference in New Issue
Block a user