This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

GH-407: "obey_over18" parameter to enable filtering of NSFW posts via…

… API
  • Loading branch information...
1 parent 13feb89 commit 6f9f91e7534db713d2bdd199ededd00598adccc1 @talklittle talklittle committed with spladug May 23, 2012
Showing with 8 additions and 2 deletions.
  1. +5 −0 r2/r2/controllers/reddit_base.py
  2. +3 −2 r2/r2/models/link.py
@@ -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
@@ -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()
View
@@ -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

0 comments on commit 6f9f91e

Please sign in to comment.