Fix #4582: Safebooru should not block "censored" tag

* Remove the default list of blocked tags in safe mode.
* Change it so that tags that are blocked in safe mode are filtered out
  at the database level rather than at the html level.
This commit is contained in:
evazion
2022-05-17 02:16:58 -05:00
parent 8239a1b551
commit ce18c866d9
4 changed files with 17 additions and 17 deletions

View File

@@ -38,7 +38,9 @@ class PostQuery
# Perform a search and return the resulting posts
def self.search(search, ...)
PostQuery.normalize(search, ...).with_implicit_metatags.posts
post_query = PostQuery.normalize(search, ...)
post_query.validate_tag_limit!
post_query.with_implicit_metatags.posts
end
def initialize(search_or_ast, current_user: User.anonymous, tag_limit: nil, safe_mode: false)
@@ -71,12 +73,12 @@ class PostQuery
end
def posts
validate!
validate_metatags!
builder.posts(to_cnf)
end
def paginated_posts(...)
validate!
validate_metatags!
builder.paginated_posts(to_cnf, ...)
end
@@ -189,9 +191,10 @@ class PostQuery
# Implicit metatags are metatags added by the user's account settings. rating:s is implicit under safe mode.
def implicit_metatags
metatags = []
metatags << AST.metatag("rating", "s") if safe_mode?
metatags
return [] unless safe_mode?
tags = Danbooru.config.safe_mode_restricted_tags.map { |tag| -AST.tag(tag) }
[AST.metatag("rating", "s"), *tags]
end
# XXX unify with PostSets::Post#show_deleted?
@@ -272,18 +275,13 @@ class PostQuery
end
concerning :ValidationMethods do
def validate!
return if is_empty_search? || is_simple_tag?
validate_tag_limit!
validate_metatags!
end
def validate_tag_limit!
return if is_empty_search? || is_simple_tag?
raise TagLimitError if tag_limit.present? && term_count > tag_limit
end
def validate_metatags!
return if is_empty_search? || is_simple_tag?
return if metatags.empty?
order_metatags = select_metatags(*ORDER_METATAGS)

View File

@@ -36,7 +36,7 @@ module PostSets
# The description of the page for the <meta name="description"> tag.
def meta_description
# XXX post_count may be nil if the search times out because of safe mode
if normalized_query.is_simple_tag? && post_count.present?
if post_query.is_simple_tag? && post_count.present?
humanized_count = ApplicationController.helpers.humanized_number(post_count, million: " million", thousand: " thousand")
humanized_count = "over #{humanized_count}" if post_count >= 1_000
@@ -106,7 +106,8 @@ module PostSets
end
def posts
@posts ||= normalized_query.paginated_posts(page, includes: includes, count: post_count, search_count: !post_count.nil?, limit: per_page, max_limit: max_per_page).load
post_query.validate_tag_limit!
normalized_query.paginated_posts(page, includes: includes, count: post_count, search_count: !post_count.nil?, limit: per_page, max_limit: max_per_page).load
end
# @return [Integer, nil] The number of posts returned by the search, or nil if unknown.
@@ -197,6 +198,6 @@ module PostSets
end
end
memoize :page_title
memoize :page_title, :posts
end
end

View File

@@ -1336,6 +1336,7 @@ class Post < ApplicationRecord
# @return [ActiveRecord::Relation<Post>] the set of resulting posts
def user_tag_match(query, user = CurrentUser.user, tag_limit: user.tag_query_limit, safe_mode: CurrentUser.safe_mode?)
post_query = PostQuery.normalize(query, current_user: user, tag_limit: tag_limit, safe_mode: safe_mode)
post_query.validate_tag_limit!
post_query.with_implicit_metatags.posts
end

View File

@@ -253,7 +253,7 @@ module Danbooru
# Tags that are not visible in safe mode.
def safe_mode_restricted_tags
restricted_tags + %w[censored condom nipples nude penis pussy sexually_suggestive]
[]
end
# If present, the 404 page will show a random post from this pool.