Search: Respect over 18 user preference

Hide NSFW links and subreddits in search based on the over18 user
preference, controlled by a feature flag.
This commit is contained in:
Florence Yeun
2015-04-02 18:02:56 -07:00
parent 56c08e11c0
commit 666116677f
2 changed files with 20 additions and 10 deletions

View File

@@ -917,8 +917,10 @@ class FrontController(RedditController):
# show NSFW to API and RSS users unless obey_over18=true
is_api_or_rss = (c.render_style in API_TYPES
or c.render_style in RSS_TYPES)
if is_api_or_rss and c.obey_over18 and not c.over18:
include_over18 = False
if is_api_or_rss:
include_over18 = not c.obey_over18 or c.over18
elif feature.is_enabled('safe_search'):
include_over18 = c.over18
else:
include_over18 = True
@@ -967,8 +969,10 @@ class FrontController(RedditController):
# show NSFW to API and RSS users unless obey_over18=true
is_api_or_rss = (c.render_style in API_TYPES
or c.render_style in RSS_TYPES)
if is_api_or_rss and c.obey_over18 and not c.over18:
include_over18 = False
if is_api_or_rss:
include_over18 = not c.obey_over18 or c.over18
elif feature.is_enabled('safe_search'):
include_over18 = c.over18
else:
include_over18 = True

View File

@@ -31,6 +31,7 @@ import time
from pylons import c, g, request
from pylons.i18n import _
from r2.config import feature
from r2.config.extensions import API_TYPES, RSS_TYPES
from r2.lib.comment_tree import (
conversation,
@@ -692,13 +693,18 @@ class SearchBuilder(IDBuilder):
# show NSFW to API and RSS users unless obey_over18=true
is_api_or_rss = (c.render_style in API_TYPES
or c.render_style in RSS_TYPES)
if is_api_or_rss and c.obey_over18 and not c.over18:
is_nsfw = (item.over_18 or
(hasattr(item, 'subreddit') and item.subreddit.over_18))
if is_nsfw:
return False
if is_api_or_rss:
include_over18 = not c.obey_over18 or c.over18
elif feature.is_enabled('safe_search'):
include_over18 = c.over18
else:
include_over18 = True
is_nsfw = (item.over_18 or
(hasattr(item, 'subreddit') and item.subreddit.over_18))
if is_nsfw and not include_over18:
return False
# currently showing NSFW content by default in search
return True
class WikiRevisionBuilder(QueryBuilder):