Skip to content

Commit

Permalink
More functional spam and remove buttons on all items.
Browse files Browse the repository at this point in the history
  • Loading branch information
bsimpson63 committed Mar 13, 2012
1 parent d2c3d23 commit 8814f6a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 46 deletions.
66 changes: 43 additions & 23 deletions r2/r2/controllers/api.py
Expand Up @@ -1432,24 +1432,39 @@ def POST_searchfeedback(self, q, sort, t, approval):
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 = {'target': thing}
if thing._spam:
kw['details'] = 'dismiss'
elif not spam:
kw['details'] = 'not_spam'

admintools.spam(thing, auto=False,
moderator_banned=not c.user_is_admin,
banner=c.user.name,
train_spam=spam)
# Don't remove a promoted link
if getattr(thing, "promoted", None):
return

if isinstance(thing, (Link, Comment)):
sr = thing.subreddit_slow
action = 'remove' + thing.__class__.__name__.lower()
ModAction.create(sr, c.user, action, **kw)
end_trial(thing, why + "-removed")

filtered = thing._spam
kw = {'target': thing}

if filtered and spam:
kw['details'] = 'confirm_spam'
train_spam = False
elif filtered and not spam:
kw['details'] = 'remove'
admintools.unspam(thing, unbanner=c.user.name, insert=False)
train_spam = False
elif not filtered and spam:
kw['details'] = 'spam'
train_spam = True
elif not filtered and not spam:
kw['details'] = 'remove'
train_spam = False

admintools.spam(thing, auto=False,
moderator_banned=not c.user_is_admin,
banner=c.user.name,
train_spam=train_spam)

if isinstance(thing, (Link, Comment)):
sr = thing.subreddit_slow
action = 'remove' + thing.__class__.__name__.lower()
ModAction.create(sr, c.user, action, **kw)

@noresponse(VUser(), VModhash(),
why = VSrCanBan('id'),
Expand All @@ -1458,15 +1473,20 @@ def POST_approve(self, why, thing):
if not thing: return
if thing._deleted: return
end_trial(thing, why + "-approved")
kw = {}
kw = {'target': thing}
if thing._spam:
kw['details'] = 'unspam'
admintools.unspam(thing, c.user.name)
sr = thing.subreddit_slow
if isinstance(thing, Link):
ModAction.create(sr, c.user, 'approvelink', target=thing, **kw)
elif isinstance(thing, Comment):
ModAction.create(sr, c.user, 'approvecomment', target=thing, **kw)
train_spam = True
else:
kw['details'] = 'confirm_ham'
train_spam = False

admintools.unspam(thing, c.user.name, train_spam=train_spam)

if isinstance(thing, (Link, Comment)):
sr = thing.subreddit_slow
action = 'approve' + thing.__class__.__name__.lower()
ModAction.create(sr, c.user, action, **kw)

@validatedForm(VUser(), VModhash(),
VCanDistinguish(('id', 'how')),
Expand Down
29 changes: 19 additions & 10 deletions r2/r2/models/admintools.py
Expand Up @@ -46,19 +46,28 @@ def spam(self, things, auto=True, moderator_banned=False,
if getattr(t, "promoted", None) is not None:
g.log.debug("Refusing to mark promotion %r as spam" % t)
continue

if not t._spam and train_spam:
note = 'spam'
elif not t._spam and not train_spam:
note = 'remove not spam'
elif t._spam and not train_spam:
note = 'confirm spam'
elif t._spam and train_spam:
note = 'reinforce spam'

t._spam = True
ban_info = copy(getattr(t, 'ban_info', {}))
ban_info.update(auto = auto,
moderator_banned = moderator_banned,
banned_at = date or datetime.now(g.tz),
**kw)

ban_info = copy(getattr(t, 'ban_info', {}))
if isinstance(banner, dict):
ban_info['banner'] = banner[t._fullname]
else:
ban_info['banner'] = banner

ban_info['not_spam'] = not train_spam
ban_info.update(auto=auto,
moderator_banned=moderator_banned,
banned_at=date or datetime.now(g.tz),
**kw)
ban_info['note'] = note

t.ban_info = ban_info
t._commit()
Expand All @@ -69,7 +78,7 @@ def spam(self, things, auto=True, moderator_banned=False,

queries.ban(new_things)

def unspam(self, things, unbanner = None):
def unspam(self, things, unbanner=None, train_spam=True, insert=True):
from r2.lib.db import queries

things = tup(things)
Expand All @@ -95,11 +104,11 @@ def unspam(self, things, unbanner = None):
t._spam = False
t._commit()

# auto is always False for unbans
self.author_spammer(things, False)
self.set_last_sr_ban(things)

queries.unban(things)
if insert:
queries.unban(things)

def author_spammer(self, things, spam):
"""incr/decr the 'spammer' field for the author of every
Expand Down
4 changes: 2 additions & 2 deletions r2/r2/models/builder.py
Expand Up @@ -238,8 +238,8 @@ def wrap_items(self, items):
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)'
if ban_info.get('note', None) and w.banner:
w.banner += ' (%s)' % ban_info['note']
w.use_big_modbuttons = True
if getattr(w, "author", None) and w.author._spam:
w.show_spam = "author"
Expand Down
7 changes: 4 additions & 3 deletions r2/r2/models/modaction.py
Expand Up @@ -60,10 +60,11 @@ class ModAction(tdb_cassandra.UuidThing, Printable):

_details_text = {# approve comment/link
'unspam': _('unspam'),
'confirm_ham': _('confirmed ham'),
# remove comment/link
'confirm_spam': _('confirmed spam'), # vestigal
'not_spam': _('not spam'),
'dismiss': _('dismissed'),
'confirm_spam': _('confirmed spam'),
'remove': _('removed not spam'),
'spam': _('removed spam'),
# removemoderator
'remove_self': _('removed self'),
# editsettings
Expand Down
13 changes: 5 additions & 8 deletions r2/r2/templates/printablebuttons.html
Expand Up @@ -119,17 +119,14 @@

<%def name="big_modbuttons(thing, kind)">
<span class="big-mod-buttons">
<% remove_text = _('removed') %>
%if getattr(thing, "moderator_banned", None):
<!-- pass -->
%elif thing._spam:
${pretty_button(_("dismiss"), "big_mod_action", -1, "neutral")}
<% remove_text = _('dismissed') %>
${pretty_button(_("confirm spam"), "big_mod_action", -2, "negative")}
${pretty_button(_("remove ham"), "big_mod_action", -1, "neutral")}
%else:
${pretty_button(_("spam %(obj)s") % dict(obj=kind),
"big_mod_action", -2, "negative")}
${pretty_button(_("remove %(obj)s") % dict(obj=kind),
"big_mod_action", -1, "neutral")}
${pretty_button(_("spam"), "big_mod_action", -2, "negative")}
${pretty_button(_("remove"), "big_mod_action", -1, "neutral")}
%endif

%if getattr(thing, "approval_checkmark", None):
Expand All @@ -145,7 +142,7 @@
${_("spammed")}
</span>
<span class="status-msg removed">
${remove_text}
${_("removed")}
</span>
<span class="status-msg approved">
${_("approved")}
Expand Down

0 comments on commit 8814f6a

Please sign in to comment.