search: refactor to pass in the current user explicitly.
This commit is contained in:
@@ -22,8 +22,8 @@ class AITag < ApplicationRecord
|
||||
where(tag: Tag.find_by_name_or_alias(name))
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :media_asset, :tag, :post, :score)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:media_asset, :tag, :post, :score], current_user: current_user)
|
||||
|
||||
if params[:tag_name].present?
|
||||
q = q.named(params[:tag_name])
|
||||
|
||||
@@ -23,8 +23,8 @@ class ApiKey < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :key, :user)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :key, :user], current_user: current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
|
||||
@@ -27,12 +27,13 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
# of results; assume there are too many pages to count.
|
||||
# @param count [Integer] the precalculated number of search results, or nil to calculate it
|
||||
# @param defaults [Hash] The default params for the search
|
||||
def paginated_search(params, page: params[:page], limit: params[:limit], count_pages: params[:search].present?, count: nil, defaults: {})
|
||||
# @param current_user [User] The user performing the search
|
||||
def paginated_search(params, page: params[:page], limit: params[:limit], count_pages: params[:search].present?, count: nil, defaults: {}, current_user: CurrentUser.user)
|
||||
search_params = params.fetch(:search, {}).permit!
|
||||
search_params = defaults.merge(search_params).with_indifferent_access
|
||||
|
||||
max_limit = (params[:format] == "sitemap") ? 10_000 : 1_000
|
||||
search(search_params).paginate(page, limit: limit, max_limit: max_limit, count: count, search_count: count_pages)
|
||||
search(search_params, current_user).paginate(page, limit: limit, max_limit: max_limit, count: count, search_count: count_pages)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -277,8 +277,8 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_deleted, :is_banned, :name, :group_name, :other_names, :urls, :wiki_page, :tag_alias, :tag)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :is_deleted, :is_banned, :name, :group_name, :other_names, :urls, :wiki_page, :tag_alias, :tag], current_user: current_user)
|
||||
|
||||
if params[:any_other_name_like]
|
||||
q = q.any_other_name_like(params[:any_other_name_like])
|
||||
|
||||
@@ -32,8 +32,8 @@ class ArtistCommentary < ApplicationRecord
|
||||
where_text_matches(%i[original_title original_description translated_title translated_description], query)
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :original_title, :original_description, :translated_title, :translated_description, :post)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :original_title, :original_description, :translated_title, :translated_description, :post], current_user: current_user)
|
||||
|
||||
if params[:text_matches].present?
|
||||
q = q.text_matches(params[:text_matches])
|
||||
|
||||
@@ -4,8 +4,8 @@ class ArtistCommentaryVersion < ApplicationRecord
|
||||
belongs_to :post
|
||||
belongs_to_updater
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :original_title, :original_description, :translated_title, :translated_description, :post, :updater)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :original_title, :original_description, :translated_title, :translated_description, :post, :updater], current_user: current_user)
|
||||
q = q.where_text_matches(%i[original_title original_description translated_title translated_description], params[:text_matches])
|
||||
|
||||
q.apply_default_order(params)
|
||||
|
||||
@@ -17,8 +17,8 @@ class ArtistURL < ApplicationRecord
|
||||
[is_active, url]
|
||||
end
|
||||
|
||||
def self.search(params = {})
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :url, :is_active, :artist)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :url, :is_active, :artist], current_user: current_user)
|
||||
q = q.urls_match(params[:url_matches])
|
||||
|
||||
case params[:order]
|
||||
|
||||
@@ -16,8 +16,8 @@ class ArtistVersion < ApplicationRecord
|
||||
end
|
||||
|
||||
module SearchMethods
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_deleted, :is_banned, :name, :group_name, :urls, :other_names, :updater, :artist)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :is_deleted, :is_banned, :name, :group_name, :urls, :other_names, :updater, :artist], current_user: current_user)
|
||||
|
||||
if params[:order] == "name"
|
||||
q = q.order("artist_versions.name").default_order
|
||||
|
||||
@@ -31,8 +31,8 @@ class BackgroundJob < GoodJob::Job
|
||||
where_json_contains(:serialized_params, { job_class: class_name })
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :queue_name, :priority, :serialized_params, :scheduled_at, :performed_at, :finished_at, :error, :active_job_id, :concurrency_key, :cron_key, :retried_good_job_id, :cron_at)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :queue_name, :priority, :serialized_params, :scheduled_at, :performed_at, :finished_at, :error, :active_job_id, :concurrency_key, :cron_key, :retried_good_job_id, :cron_at], current_user: current_user)
|
||||
|
||||
if params[:name].present?
|
||||
q = q.name_matches(params[:name])
|
||||
|
||||
@@ -18,8 +18,8 @@ class Ban < ApplicationRecord
|
||||
scope :expired, -> { where("bans.created_at + bans.duration <= ?", Time.zone.now) }
|
||||
scope :active, -> { unexpired }
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :duration, :reason, :user, :banner)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :duration, :reason, :user, :banner], current_user: current_user)
|
||||
|
||||
q = q.expired if params[:expired].to_s.truthy?
|
||||
q = q.unexpired if params[:expired].to_s.falsy?
|
||||
|
||||
@@ -29,8 +29,8 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
scope :has_topic, -> { where.not(forum_topic: nil) }
|
||||
|
||||
module SearchMethods
|
||||
def search(params = {})
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :script, :tags, :user, :forum_topic, :forum_post, :approver)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :script, :tags, :user, :forum_topic, :forum_post, :approver], current_user: current_user)
|
||||
|
||||
if params[:status].present?
|
||||
q = q.where(status: params[:status].split(","))
|
||||
|
||||
@@ -32,8 +32,8 @@ class Comment < ApplicationRecord
|
||||
)
|
||||
|
||||
module SearchMethods
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_deleted, :is_sticky, :do_not_bump_post, :body, :score, :post, :creator, :updater)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :is_deleted, :is_sticky, :do_not_bump_post, :body, :score, :post, :creator, :updater], current_user: current_user)
|
||||
|
||||
case params[:order]
|
||||
when "post_id", "post_id_desc"
|
||||
|
||||
@@ -24,8 +24,8 @@ class CommentVote < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :score, :is_deleted, :comment, :user)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :score, :is_deleted, :comment, :user], current_user: current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
|
||||
@@ -104,8 +104,8 @@ class Dmail < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_read, :is_deleted, :title, :body, :to, :from)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :is_read, :is_deleted, :title, :body, :to, :from], current_user: current_user)
|
||||
q = q.where_text_matches([:title, :body], params[:message_matches])
|
||||
|
||||
q = q.folder_matches(params[:folder])
|
||||
|
||||
@@ -38,8 +38,8 @@ class DtextLink < ApplicationRecord
|
||||
links
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :link_type, :link_target, :model, :linked_wiki, :linked_tag)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :link_type, :link_target, :model, :linked_wiki, :linked_tag], current_user: current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
|
||||
@@ -46,8 +46,8 @@ class EmailAddress < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :user, :address, :normalized_address, :is_verified, :is_deliverable)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :user, :address, :normalized_address, :is_verified, :is_deliverable], current_user: current_user)
|
||||
|
||||
q = q.restricted(params[:is_restricted])
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ class Favorite < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :post, :user)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :post, :user], current_user: current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ class FavoriteGroup < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :name, :is_public, :post_ids, :creator)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :name, :is_public, :post_ids, :creator], current_user: current_user)
|
||||
|
||||
if params[:name_contains].present?
|
||||
q = q.name_contains(params[:name_contains])
|
||||
|
||||
@@ -56,8 +56,8 @@ class ForumPost < ApplicationRecord
|
||||
where(id: dtext_links).or(where(id: bur_links))
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_deleted, :body, :creator, :updater, :topic, :dtext_links, :votes, :tag_alias, :tag_implication, :bulk_update_request)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :is_deleted, :body, :creator, :updater, :topic, :dtext_links, :votes, :tag_alias, :tag_implication, :bulk_update_request], current_user: current_user)
|
||||
|
||||
if params[:linked_to].present?
|
||||
q = q.wiki_link_matches(params[:linked_to])
|
||||
|
||||
@@ -17,14 +17,14 @@ class ForumPostVote < ApplicationRecord
|
||||
all
|
||||
end
|
||||
|
||||
def self.forum_post_matches(params)
|
||||
def self.forum_post_matches(params, current_user)
|
||||
return all if params.blank?
|
||||
where(forum_post_id: ForumPost.search(params).reorder(nil).select(:id))
|
||||
where(forum_post_id: ForumPost.search(params, current_user).reorder(nil).select(:id))
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :score, :creator, :forum_post)
|
||||
q = q.forum_post_matches(params[:forum_post])
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :score, :creator, :forum_post], current_user: current_user)
|
||||
q = q.forum_post_matches(params[:forum_post], current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
|
||||
@@ -87,8 +87,8 @@ class ForumTopic < ApplicationRecord
|
||||
order(updated_at: :desc)
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_sticky, :is_locked, :is_deleted, :category_id, :title, :response_count, :creator, :updater, :forum_posts, :bulk_update_requests, :tag_aliases, :tag_implications)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :is_sticky, :is_locked, :is_deleted, :category_id, :title, :response_count, :creator, :updater, :forum_posts, :bulk_update_requests, :tag_aliases, :tag_implications], current_user: current_user)
|
||||
|
||||
if params[:is_private].to_s.truthy?
|
||||
q = q.private_only
|
||||
|
||||
@@ -16,8 +16,8 @@ class ForumTopicVisit < ApplicationRecord
|
||||
where("user_id = ? and last_read_at < ?", user.id, user.last_forum_read_at).delete_all
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :user, :forum_topic, :last_read_at)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :user, :forum_topic, :last_read_at], current_user: current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ class IpBan < ApplicationRecord
|
||||
true
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :ip_addr, :reason, :is_deleted, :category, :hit_count, :last_hit_at, :creator)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :ip_addr, :reason, :is_deleted, :category, :hit_count, :last_hit_at, :creator], current_user: current_user)
|
||||
|
||||
case params[:order]
|
||||
when /\A(created_at|updated_at|last_hit_at)(?:_(asc|desc))?\z/i
|
||||
|
||||
@@ -16,8 +16,8 @@ class IpGeolocation < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :ip_addr, :network, :asn, :is_proxy, :latitude, :longitude, :organization, :time_zone, :continent, :country, :region, :city, :carrier)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :ip_addr, :network, :asn, :is_proxy, :latitude, :longitude, :organization, :time_zone, :continent, :country, :region, :city, :carrier], current_user: current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
|
||||
@@ -197,11 +197,11 @@ class MediaAsset < ApplicationRecord
|
||||
AITagQuery.search(tag_string, relation: self, score_range: score_range)
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :status, :md5, :file_ext, :file_size, :image_width, :image_height, :file_key, :is_public)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :status, :md5, :file_ext, :file_size, :image_width, :image_height, :file_key, :is_public], current_user: current_user)
|
||||
|
||||
if params[:metadata].present?
|
||||
q = q.joins(:media_metadata).merge(MediaMetadata.search(metadata: params[:metadata]))
|
||||
q = q.joins(:media_metadata).merge(MediaMetadata.search({ metadata: params[:metadata] }, current_user))
|
||||
end
|
||||
|
||||
if params[:ai_tags_match].present?
|
||||
|
||||
@@ -16,8 +16,8 @@ class MediaMetadata < ApplicationRecord
|
||||
attribute :metadata
|
||||
belongs_to :media_asset
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :media_asset, :metadata)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :media_asset, :metadata], current_user: current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
|
||||
@@ -78,8 +78,8 @@ class ModAction < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :category, :description, :creator)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :category, :description, :creator], current_user: current_user)
|
||||
|
||||
case params[:order]
|
||||
when "created_at_asc"
|
||||
|
||||
@@ -82,8 +82,8 @@ class ModerationReport < ApplicationRecord
|
||||
where(model: Comment.where(creator: user)).or(where(model: ForumPost.where(creator: user))).or(where(model: Dmail.received.where(from: user)))
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :reason, :creator, :model, :status)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :reason, :creator, :model, :status], current_user: current_user)
|
||||
|
||||
if params[:recipient_id].present?
|
||||
q = q.received_by(User.search(id: params[:recipient_id]))
|
||||
|
||||
@@ -13,8 +13,8 @@ class NewsUpdate < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :message, :creator, :updater)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :message, :creator, :updater], current_user: current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,8 +19,8 @@ class Note < ApplicationRecord
|
||||
scope :active, -> { where(is_active: true) }
|
||||
|
||||
module SearchMethods
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_active, :x, :y, :width, :height, :body, :version, :post)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :is_active, :x, :y, :width, :height, :body, :version, :post], current_user: current_user)
|
||||
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
@@ -5,8 +5,8 @@ class NoteVersion < ApplicationRecord
|
||||
belongs_to :note
|
||||
belongs_to_updater :counter_cache => "note_update_count"
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_active, :x, :y, :width, :height, :body, :version, :updater, :note, :post)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :is_active, :x, :y, :width, :height, :body, :version, :updater, :note, :post], current_user: current_user)
|
||||
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
@@ -11,8 +11,8 @@ class PixivUgoiraFrameData < ApplicationRecord
|
||||
[:post]
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :data, :content_type, :post, :md5)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :data, :content_type, :post, :md5], current_user: current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ class Pool < ApplicationRecord
|
||||
order(updated_at: :desc)
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_deleted, :name, :description, :post_ids, :dtext_links)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :is_deleted, :name, :description, :post_ids, :dtext_links], current_user: current_user)
|
||||
|
||||
if params[:post_tags_match]
|
||||
q = q.post_tags_match(params[:post_tags_match])
|
||||
|
||||
@@ -33,8 +33,8 @@ class PoolVersion < ApplicationRecord
|
||||
where_ilike(:name, name)
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :pool_id, :post_ids, :added_post_ids, :removed_post_ids, :updater_id, :description, :description_changed, :name, :name_changed, :version, :is_active, :is_deleted, :category)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :pool_id, :post_ids, :added_post_ids, :removed_post_ids, :updater_id, :description, :description_changed, :name, :name_changed, :version, :is_active, :is_deleted, :category], current_user: current_user)
|
||||
|
||||
if params[:post_id]
|
||||
q = q.for_post_id(params[:post_id].to_i)
|
||||
|
||||
@@ -533,14 +533,14 @@ class Post < ApplicationRecord
|
||||
in "-child", ids
|
||||
next if ids.blank?
|
||||
|
||||
children.search(id: ids).each do |post|
|
||||
children.where_numeric_matches(:id, ids).each do |post|
|
||||
post.update!(parent_id: nil)
|
||||
end
|
||||
|
||||
in "child", ids
|
||||
next if ids.blank?
|
||||
|
||||
Post.search(id: ids).where.not(id: id).limit(10).each do |post|
|
||||
Post.where_numeric_matches(:id, ids).where.not(id: id).limit(10).each do |post|
|
||||
post.update!(parent_id: id)
|
||||
end
|
||||
|
||||
@@ -1214,11 +1214,11 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def note_matches(query)
|
||||
where(notes: Note.search(body_matches: query).reorder(nil))
|
||||
where(notes: Note.where_text_matches(:body, query))
|
||||
end
|
||||
|
||||
def comment_matches(query)
|
||||
where(comments: Comment.search(body_matches: query).reorder(nil))
|
||||
where(comments: Comment.where_text_matches(:body, query))
|
||||
end
|
||||
|
||||
def saved_search_matches(label, current_user = User.anonymous)
|
||||
@@ -1411,17 +1411,18 @@ class Post < ApplicationRecord
|
||||
post_query.with_implicit_metatags.posts
|
||||
end
|
||||
|
||||
def search(params)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(
|
||||
params,
|
||||
:id, :created_at, :updated_at, :rating, :source, :pixiv_id, :fav_count,
|
||||
[:id, :created_at, :updated_at, :rating, :source, :pixiv_id, :fav_count,
|
||||
:score, :up_score, :down_score, :md5, :file_ext, :file_size, :image_width,
|
||||
:image_height, :tag_count, :has_children, :has_active_children,
|
||||
:is_pending, :is_flagged, :is_deleted, :is_banned,
|
||||
:last_comment_bumped_at, :last_commented_at, :last_noted_at,
|
||||
:uploader, :approver, :parent,
|
||||
:artist_commentary, :flags, :appeals, :notes, :comments, :children,
|
||||
:approvals, :replacements, :pixiv_ugoira_frame_data
|
||||
:approvals, :replacements, :pixiv_ugoira_frame_data],
|
||||
current_user: current_user
|
||||
)
|
||||
|
||||
if params[:tags].present?
|
||||
|
||||
@@ -23,8 +23,8 @@ class PostAppeal < ApplicationRecord
|
||||
end
|
||||
|
||||
module SearchMethods
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :reason, :status, :creator, :post)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :reason, :status, :creator, :post], current_user: current_user)
|
||||
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
@@ -36,8 +36,8 @@ class PostApproval < ApplicationRecord
|
||||
post.uploader.upload_limit.update_limit!(is_pending, true)
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :user, :post)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :user, :post], current_user: current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ class PostDisapproval < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :message, :reason, :post)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :message, :reason, :post], current_user: current_user)
|
||||
|
||||
q = q.with_message if params[:has_message].to_s.truthy?
|
||||
q = q.without_message if params[:has_message].to_s.falsy?
|
||||
|
||||
@@ -58,8 +58,8 @@ class PostFlag < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :reason, :status, :post, :creator)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :reason, :status, :post, :creator], current_user: current_user)
|
||||
|
||||
if params[:category]
|
||||
q = q.category_matches(params[:category])
|
||||
|
||||
@@ -21,8 +21,8 @@ class PostReplacement < ApplicationRecord
|
||||
|
||||
concerning :Search do
|
||||
class_methods do
|
||||
def search(params = {})
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :md5, :old_md5, :file_ext, :old_file_ext, :original_url, :replacement_url, :creator, :post)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :md5, :old_md5, :file_ext, :old_file_ext, :original_url, :replacement_url, :creator, :post], current_user: current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,8 +39,8 @@ class PostVersion < ApplicationRecord
|
||||
where_ilike(:tags, tag)
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :updated_at, :updater_id, :post_id, :tags, :added_tags, :removed_tags, :rating, :rating_changed, :parent_id, :parent_changed, :source, :source_changed, :version)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :updated_at, :updater_id, :post_id, :tags, :added_tags, :removed_tags, :rating, :rating_changed, :parent_id, :parent_changed, :source, :source_changed, :version], current_user: current_user)
|
||||
|
||||
if params[:changed_tags]
|
||||
q = q.changed_tags_include_all(params[:changed_tags].scan(/[^[:space:]]+/))
|
||||
|
||||
@@ -31,8 +31,8 @@ class PostVote < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :score, :is_deleted, :user, :post)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :score, :is_deleted, :user, :post], current_user: current_user)
|
||||
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
@@ -17,8 +17,8 @@ class RateLimit < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :limited, :points, :action, :key)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :limited, :points, :action, :key], current_user: current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
|
||||
@@ -110,8 +110,8 @@ class SavedSearch < ApplicationRecord
|
||||
|
||||
concerning :Search do
|
||||
class_methods do
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :query)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :query], current_user: current_user)
|
||||
|
||||
if params[:label]
|
||||
q = q.labeled(params[:label])
|
||||
|
||||
@@ -319,8 +319,8 @@ class Tag < ApplicationRecord
|
||||
abbreviation_matches(abbrev.escape_wildcards).order(post_count: :desc).first
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_deprecated, :category, :post_count, :name, :wiki_page, :artist, :antecedent_alias, :consequent_aliases, :antecedent_implications, :consequent_implications, :dtext_links)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :is_deprecated, :category, :post_count, :name, :wiki_page, :artist, :antecedent_alias, :consequent_aliases, :antecedent_implications, :consequent_implications, :dtext_links], current_user: current_user)
|
||||
|
||||
if params[:fuzzy_name_matches].present?
|
||||
q = q.fuzzy_name_matches(params[:fuzzy_name_matches])
|
||||
|
||||
@@ -45,7 +45,7 @@ class TagImplication < TagRelationship
|
||||
|
||||
concerning :SearchMethods do
|
||||
class_methods do
|
||||
def search(params)
|
||||
def search(params, current_user)
|
||||
q = super
|
||||
|
||||
if params[:implied_from].present?
|
||||
|
||||
@@ -82,8 +82,8 @@ class TagRelationship < ApplicationRecord
|
||||
where(status: status.downcase)
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :antecedent_name, :consequent_name, :reason, :creator, :approver, :forum_post, :forum_topic, :antecedent_tag, :consequent_tag, :antecedent_wiki, :consequent_wiki)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :antecedent_name, :consequent_name, :reason, :creator, :approver, :forum_post, :forum_topic, :antecedent_tag, :consequent_tag, :antecedent_wiki, :consequent_wiki], current_user: current_user)
|
||||
|
||||
if params[:name_matches].present?
|
||||
q = q.name_matches(params[:name_matches])
|
||||
|
||||
@@ -9,8 +9,8 @@ class TagVersion < ApplicationRecord
|
||||
where_like(:name, Tag.normalize_name(name))
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :version, :name, :category, :is_deprecated, :tag, :updater, :previous_version)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :version, :name, :category, :is_deprecated, :tag, :updater, :previous_version], current_user: current_user)
|
||||
|
||||
if params[:name_matches].present?
|
||||
q = q.name_matches(params[:name_matches])
|
||||
|
||||
@@ -32,8 +32,8 @@ class UpgradeCode < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :code, :status, :creator, :redeemer, :user_upgrade)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :code, :status, :creator, :redeemer, :user_upgrade], current_user: current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
|
||||
@@ -92,8 +92,8 @@ class Upload < ApplicationRecord
|
||||
where(upload_media_assets.where("upload_media_assets.upload_id = uploads.id").arel.exists)
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :source, :referer_url, :status, :media_asset_count, :uploader, :upload_media_assets, :media_assets, :posts)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :source, :referer_url, :status, :media_asset_count, :uploader, :upload_media_assets, :media_assets, :posts], current_user: current_user)
|
||||
|
||||
if params[:ai_tags_match].present?
|
||||
min_score = params.fetch(:min_score, 50).to_i
|
||||
|
||||
@@ -36,8 +36,8 @@ class UploadMediaAsset < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :status, :source_url, :page_url, :error, :upload, :media_asset, :post)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :status, :source_url, :page_url, :error, :upload, :media_asset, :post], current_user: current_user)
|
||||
|
||||
if params[:is_posted].to_s.truthy?
|
||||
q = q.where.associated(:post)
|
||||
|
||||
@@ -612,18 +612,19 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
module SearchMethods
|
||||
def search(params)
|
||||
def search(params, current_user)
|
||||
params = params.dup
|
||||
params[:name_matches] = params.delete(:name) if params[:name].present?
|
||||
|
||||
q = search_attributes(
|
||||
params,
|
||||
:id, :created_at, :updated_at, :name, :level, :post_upload_count,
|
||||
[:id, :created_at, :updated_at, :name, :level, :post_upload_count,
|
||||
:post_update_count, :note_update_count, :favorite_count, :posts,
|
||||
:note_versions, :artist_commentary_versions, :post_appeals,
|
||||
:post_approvals, :artist_versions, :comments, :wiki_page_versions,
|
||||
:feedback, :forum_topics, :forum_posts, :forum_post_votes,
|
||||
:tag_aliases, :tag_implications, :bans, :inviter
|
||||
:tag_aliases, :tag_implications, :bans, :inviter],
|
||||
current_user: current_user
|
||||
)
|
||||
|
||||
if params[:name_matches].present?
|
||||
|
||||
@@ -95,8 +95,8 @@ class UserAction < ApplicationRecord
|
||||
all
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :event_type, :user, :model)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:event_type, :user, :model], current_user: current_user)
|
||||
|
||||
case params[:order]
|
||||
when "event_at_asc"
|
||||
|
||||
@@ -33,8 +33,8 @@ class UserEvent < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :category, :user, :user_session)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :category, :user, :user_session], current_user: current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ class UserFeedback < ApplicationRecord
|
||||
order(created_at: :desc)
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :category, :body, :is_deleted, :creator, :user)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :category, :body, :is_deleted, :creator, :user], current_user: current_user)
|
||||
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
@@ -20,8 +20,8 @@ class UserNameChangeRequest < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :user, :original_name, :desired_name)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :user, :original_name, :desired_name], current_user: current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ class UserSession < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :session_id, :user_agent, :ip_addr, :ip_geolocation)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :session_id, :user_agent, :ip_addr, :ip_geolocation], current_user: current_user)
|
||||
q = q.apply_default_order(params)
|
||||
q
|
||||
end
|
||||
|
||||
@@ -102,8 +102,8 @@ class UserUpgrade < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :upgrade_type, :status, :transaction_id, :payment_processor, :recipient, :purchaser)
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :upgrade_type, :status, :transaction_id, :payment_processor, :recipient, :purchaser], current_user: current_user)
|
||||
|
||||
if params[:is_gifted].to_s.truthy?
|
||||
q = q.gifted
|
||||
|
||||
@@ -61,8 +61,8 @@ class WikiPage < ApplicationRecord
|
||||
order(updated_at: :desc)
|
||||
end
|
||||
|
||||
def search(params = {})
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_locked, :is_deleted, :body, :title, :other_names, :tag, :artist, :dtext_links)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :is_locked, :is_deleted, :body, :title, :other_names, :tag, :artist, :dtext_links], current_user: current_user)
|
||||
q = q.where_text_matches([:title, :body], params[:title_or_body_matches])
|
||||
|
||||
if params[:title_normalize].present?
|
||||
|
||||
@@ -7,8 +7,8 @@ class WikiPageVersion < ApplicationRecord
|
||||
belongs_to :tag, primary_key: :name, foreign_key: :title, optional: true
|
||||
|
||||
module SearchMethods
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :title, :body, :other_names, :is_locked, :is_deleted, :updater, :wiki_page, :tag)
|
||||
def search(params, current_user)
|
||||
q = search_attributes(params, [:id, :created_at, :updated_at, :title, :body, :other_names, :is_locked, :is_deleted, :updater, :wiki_page, :tag], current_user: current_user)
|
||||
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user