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:
@@ -38,7 +38,9 @@ class PostQuery
|
|||||||
|
|
||||||
# Perform a search and return the resulting posts
|
# Perform a search and return the resulting posts
|
||||||
def self.search(search, ...)
|
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
|
end
|
||||||
|
|
||||||
def initialize(search_or_ast, current_user: User.anonymous, tag_limit: nil, safe_mode: false)
|
def initialize(search_or_ast, current_user: User.anonymous, tag_limit: nil, safe_mode: false)
|
||||||
@@ -71,12 +73,12 @@ class PostQuery
|
|||||||
end
|
end
|
||||||
|
|
||||||
def posts
|
def posts
|
||||||
validate!
|
validate_metatags!
|
||||||
builder.posts(to_cnf)
|
builder.posts(to_cnf)
|
||||||
end
|
end
|
||||||
|
|
||||||
def paginated_posts(...)
|
def paginated_posts(...)
|
||||||
validate!
|
validate_metatags!
|
||||||
builder.paginated_posts(to_cnf, ...)
|
builder.paginated_posts(to_cnf, ...)
|
||||||
end
|
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.
|
# Implicit metatags are metatags added by the user's account settings. rating:s is implicit under safe mode.
|
||||||
def implicit_metatags
|
def implicit_metatags
|
||||||
metatags = []
|
return [] unless safe_mode?
|
||||||
metatags << AST.metatag("rating", "s") if safe_mode?
|
|
||||||
metatags
|
tags = Danbooru.config.safe_mode_restricted_tags.map { |tag| -AST.tag(tag) }
|
||||||
|
[AST.metatag("rating", "s"), *tags]
|
||||||
end
|
end
|
||||||
|
|
||||||
# XXX unify with PostSets::Post#show_deleted?
|
# XXX unify with PostSets::Post#show_deleted?
|
||||||
@@ -272,18 +275,13 @@ class PostQuery
|
|||||||
end
|
end
|
||||||
|
|
||||||
concerning :ValidationMethods do
|
concerning :ValidationMethods do
|
||||||
def validate!
|
|
||||||
return if is_empty_search? || is_simple_tag?
|
|
||||||
|
|
||||||
validate_tag_limit!
|
|
||||||
validate_metatags!
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate_tag_limit!
|
def validate_tag_limit!
|
||||||
|
return if is_empty_search? || is_simple_tag?
|
||||||
raise TagLimitError if tag_limit.present? && term_count > tag_limit
|
raise TagLimitError if tag_limit.present? && term_count > tag_limit
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_metatags!
|
def validate_metatags!
|
||||||
|
return if is_empty_search? || is_simple_tag?
|
||||||
return if metatags.empty?
|
return if metatags.empty?
|
||||||
|
|
||||||
order_metatags = select_metatags(*ORDER_METATAGS)
|
order_metatags = select_metatags(*ORDER_METATAGS)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ module PostSets
|
|||||||
# The description of the page for the <meta name="description"> tag.
|
# The description of the page for the <meta name="description"> tag.
|
||||||
def meta_description
|
def meta_description
|
||||||
# XXX post_count may be nil if the search times out because of safe mode
|
# 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 = ApplicationController.helpers.humanized_number(post_count, million: " million", thousand: " thousand")
|
||||||
humanized_count = "over #{humanized_count}" if post_count >= 1_000
|
humanized_count = "over #{humanized_count}" if post_count >= 1_000
|
||||||
|
|
||||||
@@ -106,7 +106,8 @@ module PostSets
|
|||||||
end
|
end
|
||||||
|
|
||||||
def posts
|
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
|
end
|
||||||
|
|
||||||
# @return [Integer, nil] The number of posts returned by the search, or nil if unknown.
|
# @return [Integer, nil] The number of posts returned by the search, or nil if unknown.
|
||||||
@@ -197,6 +198,6 @@ module PostSets
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
memoize :page_title
|
memoize :page_title, :posts
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1336,6 +1336,7 @@ class Post < ApplicationRecord
|
|||||||
# @return [ActiveRecord::Relation<Post>] the set of resulting posts
|
# @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?)
|
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 = 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
|
post_query.with_implicit_metatags.posts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ module Danbooru
|
|||||||
|
|
||||||
# Tags that are not visible in safe mode.
|
# Tags that are not visible in safe mode.
|
||||||
def safe_mode_restricted_tags
|
def safe_mode_restricted_tags
|
||||||
restricted_tags + %w[censored condom nipples nude penis pussy sexually_suggestive]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
# If present, the 404 page will show a random post from this pool.
|
# If present, the 404 page will show a random post from this pool.
|
||||||
|
|||||||
Reference in New Issue
Block a user