Skip to content

Commit

Permalink
Ads: Require targets to be nsfw if the creative is nsfw.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwick committed Dec 9, 2015
1 parent 0c6262b commit e20c4be
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions r2/r2/controllers/promotecontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,11 @@ def POST_edit_campaign(self, form, jquery, link, campaign_id36,
is_frontpage = (not target.is_collection and
target.subreddit_name == Frontpage.name)

if link.over_18 and not target.over_18:
c.errors.add(errors.INVALID_NSFW_TARGET, field='targeting')
form.has_errors('targeting', errors.INVALID_NSFW_TARGET)
return

if not target.is_collection and not is_frontpage:
# targeted to a single subreddit, check roadblock
sr = target.subreddits_slow[0]
Expand Down
1 change: 1 addition & 0 deletions r2/r2/lib/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
('BAD_SR_NAME', _('that name isn\'t going to work')),
('COLLECTION_NOEXIST', _('that collection doesn\'t exist')),
('INVALID_TARGET', _('that target type is not valid')),
('INVALID_NSFW_TARGET', _('nsfw ads must target nsfw content')),
('INVALID_OS_VERSION', _('that version range is not valid')),
('RATELIMIT', _('you are doing that too much. try again in %(time)s.')),
('SUBREDDIT_RATELIMIT', _("you are doing that too much. try again later.")),
Expand Down
8 changes: 8 additions & 0 deletions r2/r2/models/promo.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ def __init__(self, target):
# defer looking up subreddits, we might only need their names
self._subreddits = None

@property
def over_18(self):
if self.is_collection:
return self.collection.over_18
else:
subreddits = self.subreddits_slow
return subreddits and subreddits[0].over_18

@property
def subreddit_names(self):
if self.is_collection:
Expand Down
1 change: 1 addition & 0 deletions r2/r2/templates/promotelinkbase.html
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@
${error_field("OVERSOLD", "sr", "div")}
${thing.subreddit_selector}
</div>
${error_field("INVALID_NSFW_TARGET", "targeting", "div")}
</div>
<div class="select-group geotargeting-group">
<span class="label">location</span>
Expand Down

0 comments on commit e20c4be

Please sign in to comment.