diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 2288708f7..9c103d52c 100644 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -716,6 +716,28 @@ class ApiController(RedditController): 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): diff --git a/r2/r2/controllers/validator/validator.py b/r2/r2/controllers/validator/validator.py index 8504e6ae4..3c6692d93 100644 --- a/r2/r2/controllers/validator/validator.py +++ b/r2/r2/controllers/validator/validator.py @@ -657,6 +657,23 @@ class VSrCanDistinguish(VByName): 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: diff --git a/r2/r2/lib/pages/things.py b/r2/r2/lib/pages/things.py index c8c133867..f02655a4d 100644 --- a/r2/r2/lib/pages/things.py +++ b/r2/r2/lib/pages/things.py @@ -33,8 +33,8 @@ from pylons.i18n import _, ungettext 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 @@ class PrintableButtons(Styled): 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 @@ class LinkButtons(PrintableButtons): 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 @@ class LinkButtons(PrintableButtons): 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, diff --git a/r2/r2/models/link.py b/r2/r2/models/link.py index cc7e45348..fae465780 100755 --- a/r2/r2/models/link.py +++ b/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 @@ class Link(Thing, Printable): 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) diff --git a/r2/r2/templates/printablebuttons.html b/r2/r2/templates/printablebuttons.html index 7b63abab2..76b0a577d 100644 --- a/r2/r2/templates/printablebuttons.html +++ b/r2/r2/templates/printablebuttons.html @@ -59,6 +59,12 @@ ${ynbutton(_("report"), _("reported"), "report", "hide_thing")} %endif + %if thing.show_marknsfw: +
  • ${ynbutton(_("nsfw"), _("marked"), "marknsfw")}
  • + %endif + %if thing.show_unmarknsfw: +
  • ${ynbutton(_("un-nsfw"), _("unmarked"), "unmarknsfw")}
  • + %endif <%def name="distinguish_setter(value)">