Skip to content

Commit

Permalink
GH-407: "obey_over18" parameter to enable filtering of NSFW posts via…
Browse files Browse the repository at this point in the history
… API
  • Loading branch information
talklittle authored and spladug committed Jun 26, 2012
1 parent 13feb89 commit 6f9f91e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions r2/r2/controllers/reddit_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ def over18():
if cookie == sha1(request.ip).hexdigest():
return True

def set_obey_over18():
"querystring parameter for API to obey over18 filtering rules"
c.obey_over18 = request.GET.get("obey_over18") == "true"

def set_subreddit():
#the r parameter gets added by javascript for POST requests so we
#can reference c.site in api.py
Expand Down Expand Up @@ -839,6 +843,7 @@ def pre(self):
c.user.update_last_visit(c.start_time)

c.over18 = over18()
set_obey_over18()

#set_browser_langs()
set_host_lang()
Expand Down
5 changes: 3 additions & 2 deletions r2/r2/models/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ def keep_item(self, wrapped):
if wrapped.hidden:
return False

# Don't hide from API users
if c.render_style in extensions.API_TYPES:
# Always show NSFW to API users unless obey_over18=true in querystring
is_api = c.render_style in extensions.API_TYPES
if is_api and not c.obey_over18:
return True

# hide NSFW links from non-logged users and under 18 logged users
Expand Down

0 comments on commit 6f9f91e

Please sign in to comment.