config: remove is_unlimited_metatag? config option.
This commit is contained in:
@@ -53,6 +53,8 @@ class PostQueryBuilder
|
||||
COUNT_METATAG_SYNONYMS.flat_map { |str| [str, "#{str}_asc"] } +
|
||||
CATEGORY_COUNT_METATAGS.flat_map { |str| [str, "#{str}_asc"] }
|
||||
|
||||
UNLIMITED_METATAGS = %w[status rating limit]
|
||||
|
||||
attr_reader :query_string, :current_user, :safe_mode, :hide_deleted_posts
|
||||
alias_method :safe_mode?, :safe_mode
|
||||
alias_method :hide_deleted_posts?, :hide_deleted_posts
|
||||
@@ -450,9 +452,13 @@ class PostQueryBuilder
|
||||
relation
|
||||
end
|
||||
|
||||
def self.is_unlimited_tag?(term)
|
||||
term.type == :metatag && term.name.in?(UNLIMITED_METATAGS)
|
||||
end
|
||||
|
||||
def build
|
||||
tag_count = terms.count { |term| !Danbooru.config.is_unlimited_tag?(term) }
|
||||
if tag_count > Danbooru.config.tag_query_limit
|
||||
tag_count = terms.count { |term| !PostQueryBuilder.is_unlimited_tag?(term) }
|
||||
if tag_count > current_user.tag_query_limit
|
||||
raise ::Post::SearchError
|
||||
end
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ module PostSets
|
||||
attr_reader :page, :random, :post_count, :format, :tag_string, :query
|
||||
delegate :normalized_query, to: :query
|
||||
|
||||
def initialize(tags, page = 1, per_page = nil, random: false, format: "html")
|
||||
@query = PostQueryBuilder.new(tags, CurrentUser.user, safe_mode: CurrentUser.safe_mode?, hide_deleted_posts: CurrentUser.hide_deleted_posts?)
|
||||
def initialize(tags, page = 1, per_page = nil, user: CurrentUser.user, random: false, format: "html")
|
||||
@query = PostQueryBuilder.new(tags, user, safe_mode: CurrentUser.safe_mode?, hide_deleted_posts: user.hide_deleted_posts?)
|
||||
@tag_string = tags
|
||||
@page = page
|
||||
@per_page = per_page
|
||||
|
||||
@@ -100,19 +100,6 @@ module Danbooru
|
||||
6
|
||||
end
|
||||
|
||||
def tag_query_limit
|
||||
if CurrentUser.user.present?
|
||||
CurrentUser.user.tag_query_limit
|
||||
else
|
||||
base_tag_query_limit * 2
|
||||
end
|
||||
end
|
||||
|
||||
# Return true if the given tag shouldn't count against the user's tag search limit.
|
||||
def is_unlimited_tag?(term)
|
||||
term.type == :metatag && term.name.in?(%w[status rating limit])
|
||||
end
|
||||
|
||||
# After this many pages, the paginator will switch to sequential mode.
|
||||
def max_numbered_pages
|
||||
1_000
|
||||
|
||||
@@ -78,12 +78,10 @@ module PostSets
|
||||
end
|
||||
|
||||
context "a set for the 'a b c' tag query" do
|
||||
setup do
|
||||
@set = PostSets::Post.new("a b c")
|
||||
end
|
||||
|
||||
context "for a non-gold user" do
|
||||
should "fail" do
|
||||
@set = PostSets::Post.new("a b c", user: create(:user))
|
||||
|
||||
assert_raises(::Post::SearchError) do
|
||||
@set.posts
|
||||
end
|
||||
@@ -91,11 +89,9 @@ module PostSets
|
||||
end
|
||||
|
||||
context "for a gold user" do
|
||||
setup do
|
||||
CurrentUser.user = FactoryBot.create(:gold_user)
|
||||
end
|
||||
|
||||
should "pass" do
|
||||
@set = PostSets::Post.new("a b c", user: create(:gold_user))
|
||||
|
||||
assert_nothing_raised do
|
||||
@set.posts
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user