Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add moderator-controllable NSFW marking to posts.

  • Loading branch information...
commit db209928a3b108dd69178dd30dac658dd9223aed 1 parent 04be215
@rtnielson rtnielson authored Max Goodman committed
View
22 r2/r2/controllers/api.py
@@ -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):
View
17 r2/r2/controllers/validator/validator.py
@@ -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:
View
18 r2/r2/lib/pages/things.py
@@ -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)
@@ -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):
@@ -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
@@ -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,
View
4 r2/r2/models/link.py
@@ -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,
@@ -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)
View
6 r2/r2/templates/printablebuttons.html
@@ -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)">
Please sign in to comment.
Something went wrong with that request. Please try again.