From 2a8876bfb6dd2700ab497411720360a2f215c08e Mon Sep 17 00:00:00 2001 From: bsimpson63 Date: Fri, 24 Feb 2012 10:52:40 -0800 Subject: [PATCH] Remove things as spam or not spam. --- r2/r2/controllers/api.py | 28 +++++++++++++++++---------- r2/r2/models/admintools.py | 4 +++- r2/r2/models/builder.py | 2 ++ r2/r2/models/modaction.py | 1 + r2/r2/templates/printablebuttons.html | 5 ++++- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 2dd0d62b2..e375a6033 100644 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -1426,19 +1426,27 @@ class ApiController(RedditController): @noresponse(VUser(), VModhash(), why = VSrCanBan('id'), - thing = VByName('id')) - def POST_remove(self, why, thing): + thing = VByName('id'), + spam = VBoolean('spam', default=True)) + def POST_remove(self, why, thing, spam): if getattr(thing, "promoted", None) is None: end_trial(thing, why + "-removed") - kw = {} - if thing._spam: + + kw = {'target': thing} + if thing._spam and spam: kw['details'] = 'confirm_spam' - admintools.spam(thing, False, not c.user_is_admin, c.user.name) - sr = thing.subreddit_slow - if isinstance(thing, Link): - ModAction.create(sr, c.user, 'removelink', target=thing, **kw) - elif isinstance(thing, Comment): - ModAction.create(sr, c.user, 'removecomment', target=thing, **kw) + + admintools.spam(thing, auto=False, + moderator_banned=not c.user_is_admin, + banner=c.user.name, + train_spam=spam) + + if isinstance(thing, (Link, Comment)): + if not spam: + kw['details'] = 'not_spam' + sr = thing.subreddit_slow + action = 'remove' + thing.__class__.__name__.lower() + ModAction.create(sr, c.user, action, **kw) @noresponse(VUser(), VModhash(), why = VSrCanBan('id'), diff --git a/r2/r2/models/admintools.py b/r2/r2/models/admintools.py index 6c94d8c32..627a2ff19 100644 --- a/r2/r2/models/admintools.py +++ b/r2/r2/models/admintools.py @@ -32,7 +32,7 @@ from copy import copy class AdminTools(object): def spam(self, things, auto=True, moderator_banned=False, - banner=None, date = None, **kw): + banner=None, date=None, train_spam=True, **kw): from r2.lib.db import queries all_things = tup(things) @@ -58,6 +58,8 @@ class AdminTools(object): else: ban_info['banner'] = banner + ban_info['not_spam'] = not train_spam + t.ban_info = ban_info t._commit() diff --git a/r2/r2/models/builder.py b/r2/r2/models/builder.py index 6a349f1ed..2cec194c8 100644 --- a/r2/r2/models/builder.py +++ b/r2/r2/models/builder.py @@ -238,6 +238,8 @@ class Builder(object): w.moderator_banned = ban_info.get('moderator_banned', False) w.autobanned = ban_info.get('auto', False) w.banner = ban_info.get('banner') + if ban_info.get('not_spam', False) and w.banner: + w.banner += ' (not spam)' w.use_big_modbuttons = True if getattr(w, "author", None) and w.author._spam: w.show_spam = "author" diff --git a/r2/r2/models/modaction.py b/r2/r2/models/modaction.py index b77dead0e..f0084c840 100644 --- a/r2/r2/models/modaction.py +++ b/r2/r2/models/modaction.py @@ -62,6 +62,7 @@ class ModAction(tdb_cassandra.UuidThing, Printable): 'unspam': _('unspam'), # remove comment/link 'confirm_spam': _('confirmed spam'), + 'not_spam': _('not spam'), # removemoderator 'remove_self': _('removed self'), # editsettings diff --git a/r2/r2/templates/printablebuttons.html b/r2/r2/templates/printablebuttons.html index 74ef5e2db..064d02932 100644 --- a/r2/r2/templates/printablebuttons.html +++ b/r2/r2/templates/printablebuttons.html @@ -41,7 +41,10 @@ %if not getattr(thing.thing, "use_big_modbuttons", False): %if not thing.show_spam:
  • - ${ynbutton(_("remove"), _("removed"), "remove")} + ${ynbutton(_("spam"), _("spammed"), "remove")} +
  • +
  • + ${ynbutton(_("remove"), _("removed"), "remove", hidden_data=dict(spam=False))}
  • %endif