search: split tag_match into user_tag_match / system_tag_match.
When doing a tag search, we have to be careful about which user we're running the search as because the results depend on the current user. Specifically, things like private favorites, private favorite groups, post votes, saved searches, and flagger names depend on the user's permissions, and whether non-safe or deleted posts are filtered out depend on whether the user has safe mode on or the hide deleted posts setting enabled. * Refactor internal searches to explicitly state whether they're running as the system user (DanbooruBot) or as the current user. * Explicitly pass in the current user to PostQueryBuilder instead of implicitly relying on the CurrentUser global. * Get rid of CurrentUser.admin_mode? (used to ignore the hide deleted post setting) and CurrentUser.without_safe_mode (used to ignore safe mode). * Change the /counts/posts.json endpoint to ignore safe mode and the hide deleted posts settings when counting posts. * Fix searches not correctly overriding the hide deleted posts setting when multiple status: metatags were used (e.g. `status:banned status:active`) * Fix fast_count not respecting the hide deleted posts setting when the status:banned metatag was used.
This commit is contained in:
@@ -40,7 +40,7 @@ module PostSetPresenters
|
||||
end
|
||||
|
||||
def similar_tags
|
||||
RelatedTagCalculator.cached_similar_tags_for_search(post_set.tag_string, MAX_TAGS)
|
||||
RelatedTagCalculator.cached_similar_tags_for_search(post_set.tag_string, MAX_TAGS, CurrentUser.user)
|
||||
end
|
||||
|
||||
def frequent_tags
|
||||
|
||||
@@ -36,11 +36,11 @@ class UserPresenter
|
||||
end
|
||||
|
||||
def posts_for_saved_search_category(category)
|
||||
Post.tag_match("search:#{category}").limit(10)
|
||||
Post.user_tag_match("search:#{category}").limit(10)
|
||||
end
|
||||
|
||||
def uploads
|
||||
Post.tag_match("user:#{user.name}").limit(6)
|
||||
Post.user_tag_match("user:#{user.name}").limit(6)
|
||||
end
|
||||
|
||||
def has_uploads?
|
||||
@@ -48,7 +48,7 @@ class UserPresenter
|
||||
end
|
||||
|
||||
def favorites
|
||||
Post.tag_match("ordfav:#{user.name}").limit(6)
|
||||
Post.user_tag_match("ordfav:#{user.name}").limit(6)
|
||||
end
|
||||
|
||||
def has_favorites?
|
||||
@@ -76,7 +76,7 @@ class UserPresenter
|
||||
end
|
||||
|
||||
def commented_posts_count(template)
|
||||
count = CurrentUser.without_safe_mode { PostQueryBuilder.new("commenter:#{user.name}").fast_count }
|
||||
count = PostQueryBuilder.new("commenter:#{user.name}", User.system).fast_count
|
||||
count = "?" if count.nil?
|
||||
template.link_to(count, template.posts_path(:tags => "commenter:#{user.name} order:comment_bumped"))
|
||||
end
|
||||
@@ -90,7 +90,7 @@ class UserPresenter
|
||||
end
|
||||
|
||||
def noted_posts_count(template)
|
||||
count = CurrentUser.without_safe_mode { PostQueryBuilder.new("noteupdater:#{user.name}").fast_count }
|
||||
count = PostQueryBuilder.new("noteupdater:#{user.name}", User.system).fast_count
|
||||
count = "?" if count.nil?
|
||||
template.link_to(count, template.posts_path(:tags => "noteupdater:#{user.name} order:note"))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user