Skip to content

Commit

Permalink
Add moderator-controllable NSFW marking to posts.
Browse files Browse the repository at this point in the history
  • Loading branch information
zeshinsei authored and chromakode committed Jun 21, 2011
1 parent 04be215 commit db20992
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
22 changes: 22 additions & 0 deletions r2/r2/controllers/api.py
Expand Up @@ -716,6 +716,28 @@ def POST_del(self, thing):
rels = filter(None, d.values()) or None
queries.new_comment(thing, rels)

@noresponse(VUser(),
VModhash(),
VSrCanAlter('id'),
thing = VByName('id'))
def POST_marknsfw(self, thing):
thing.over_18 = True
thing._commit()

# flag search indexer that something has changed
changed(thing)

@noresponse(VUser(),
VModhash(),
VSrCanAlter('id'),
thing = VByName('id'))
def POST_unmarknsfw(self, thing):
thing.over_18 = False
thing._commit()

# flag search indexer that something has changed
changed(thing)

@noresponse(VUser(), VModhash(),
thing = VByName('id'))
def POST_report(self, thing):
Expand Down
17 changes: 17 additions & 0 deletions r2/r2/controllers/validator/validator.py
Expand Up @@ -657,6 +657,23 @@ def run(self, thing_name):
return True
abort(403,'forbidden')

class VSrCanAlter(VByName):
def run(self, thing_name):
if c.user_is_admin:
return True
elif c.user_is_loggedin:
item = VByName.run(self, thing_name)
if item.author_id == c.user._id:
return True
else:
# will throw a legitimate 500 if this isn't a link or
# comment, because this should only be used on links and
# comments
subreddit = item.subreddit_slow
if subreddit.can_distinguish(c.user):
return True
abort(403,'forbidden')

class VSrCanBan(VByName):
def run(self, thing_name):
if c.user_is_admin:
Expand Down
18 changes: 16 additions & 2 deletions r2/r2/lib/pages/things.py
Expand Up @@ -33,8 +33,8 @@
class PrintableButtons(Styled):
def __init__(self, style, thing,
show_delete = False, show_report = True,
show_distinguish = False,
show_indict = False, is_link=False, **kw):
show_distinguish = False, show_marknsfw = False,
show_unmarknsfw = False, show_indict = False, is_link=False, **kw):
show_ignore = (thing.show_reports or
(thing.reveal_trial_info and not thing.show_spam))
approval_checkmark = getattr(thing, "approval_checkmark", None)
Expand All @@ -54,6 +54,8 @@ def __init__(self, style, thing,
show_report = show_report,
show_indict = show_indict,
show_distinguish = show_distinguish,
show_marknsfw = show_marknsfw,
show_unmarknsfw = show_unmarknsfw,
**kw)

class BanButtons(PrintableButtons):
Expand All @@ -77,6 +79,16 @@ def __init__(self, thing, comments = True, delete = True, report = True):
else:
show_indict = False

if (thing.can_ban or is_author) and not thing.nsfw:
show_marknsfw = True
else:
show_marknsfw = False

if (thing.can_ban or is_author) and thing.nsfw and not thing.nsfw_str:
show_unmarknsfw = True
else:
show_unmarknsfw = False

# do we show the delete button?
show_delete = is_author and delete and not thing._deleted
# disable the delete button for live sponsored links
Expand Down Expand Up @@ -114,6 +126,8 @@ def __init__(self, thing, comments = True, delete = True, report = True):
show_report = show_report and c.user_is_loggedin,
show_indict = show_indict,
show_distinguish = show_distinguish,
show_marknsfw = show_marknsfw,
show_unmarknsfw = show_unmarknsfw,
show_comments = comments,
# promotion
promoted = thing.promoted,
Expand Down
4 changes: 3 additions & 1 deletion r2/r2/models/link.py
Expand Up @@ -50,6 +50,7 @@ class Link(Thing, Printable):
_data_int_props = Thing._data_int_props + ('num_comments', 'reported')
_defaults = dict(is_self = False,
over_18 = False,
nsfw_str = False,
reported = 0, num_comments = 0,
moderator_banned = False,
banned_before_moderator = False,
Expand Down Expand Up @@ -358,8 +359,9 @@ def add_props(cls, user, wrapped):
elif pref_media != 'off' and not user.pref_compress:
show_media = True

item.nsfw_str = item._nsfw.findall(item.title)
item.over_18 = bool(item.over_18 or item.subreddit.over_18 or
item._nsfw.findall(item.title))
item.nsfw_str)
item.nsfw = item.over_18 and user.pref_label_nsfw

item.is_author = (user == item.author)
Expand Down
6 changes: 6 additions & 0 deletions r2/r2/templates/printablebuttons.html
Expand Up @@ -59,6 +59,12 @@
${ynbutton(_("report"), _("reported"), "report", "hide_thing")}
</li>
%endif
%if thing.show_marknsfw:
<li>${ynbutton(_("nsfw"), _("marked"), "marknsfw")}</li>
%endif
%if thing.show_unmarknsfw:
<li>${ynbutton(_("un-nsfw"), _("unmarked"), "unmarknsfw")}</li>
%endif
</%def>

<%def name="distinguish_setter(value)">
Expand Down

0 comments on commit db20992

Please sign in to comment.