GH-407: obey_over18=true to enable regular NSFW filtering for API clients #452

Closed
wants to merge 2 commits into
from
@@ -246,6 +246,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
@@ -842,6 +846,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
@@ -219,8 +219,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