Add moderator-controllable NSFW marking to posts.

This commit is contained in:
Zeno
2010-10-27 12:52:15 -07:00
committed by Max Goodman
parent 04be215974
commit db209928a3
5 changed files with 64 additions and 3 deletions

View File

@@ -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):

View File

@@ -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:

View File

@@ -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,

View File

@@ -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)

View File

@@ -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)">