Fix #4149: Add missing post search options on applicable models.

This commit is contained in:
evazion
2019-09-01 13:10:37 -05:00
parent 1bb1b147ea
commit 67100f26eb
26 changed files with 27 additions and 54 deletions

View File

@@ -29,7 +29,7 @@ class ArtistCommentary < ApplicationRecord
def search(params)
q = super
q = q.search_post_id_attribute(params)
q = q.search_attributes(params, :post, :original_title, :original_description, :translated_title, :translated_description)
if params[:text_matches].present?
q = q.text_matches(params[:text_matches])

View File

@@ -4,12 +4,7 @@ class ArtistCommentaryVersion < ApplicationRecord
def self.search(params)
q = super
q = q.search_user_attribute(:updater, params)
if params[:post_id]
q = q.where("post_id = ?", params[:post_id].to_i)
end
q = q.search_attributes(params, :post, :updater, :original_title, :original_description, :translated_title, :translated_description)
q.apply_default_order(params)
end
end

View File

@@ -10,11 +10,7 @@ class ArtistVersion < ApplicationRecord
def search(params)
q = super
if params[:name].present?
q = q.where("name like ? escape E'\\\\'", params[:name].to_escaped_for_sql_like)
end
q = q.search_attributes(params, :updater, :is_active, :is_banned, :artist_id)
q = q.search_attributes(params, :updater, :is_active, :is_banned, :artist_id, :name, :group_name)
params[:order] ||= params.delete(:sort)
if params[:order] == "name"

View File

@@ -28,7 +28,7 @@ class Ban < ApplicationRecord
def self.search(params)
q = super
q = q.search_attributes(params, :banner, :user)
q = q.search_attributes(params, :banner, :user, :expires_at, :reason)
q = q.text_attribute_matches(:reason, params[:reason_matches])
q = q.expired if params[:expired].to_s.truthy?

View File

@@ -30,7 +30,7 @@ class BulkUpdateRequest < ApplicationRecord
def search(params = {})
q = super
q = q.search_attributes(params, :user, :approver, :forum_topic_id, :forum_post_id)
q = q.search_attributes(params, :user, :approver, :forum_topic_id, :forum_post_id, :title, :script)
q = q.text_attribute_matches(:title, params[:title_matches])
q = q.text_attribute_matches(:script, params[:script_matches])

View File

@@ -34,7 +34,7 @@ class Comment < ApplicationRecord
def search(params)
q = super
q = q.search_attributes(params, :post, :creator, :is_deleted, :is_sticky, :do_not_bump_post)
q = q.search_attributes(params, :post, :creator, :updater, :is_deleted, :is_sticky, :do_not_bump_post, :body, :score)
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index)
case params[:order]

View File

@@ -10,17 +10,6 @@ class CommentVote < ApplicationRecord
validate :validate_comment_can_be_down_voted
validates_inclusion_of :score, :in => [-1, 1], :message => "must be 1 or -1"
def self.search(params)
q = where("true")
return q if params.blank?
if params[:comment_id]
q = q.where("comment_id = ?", params[:comment_id].to_i)
end
q
end
def validate_user_can_vote
if !user.can_comment_vote?
errors.add :base, "You cannot vote on more than 10 comments per hour"

View File

@@ -141,7 +141,7 @@ class Dmail < ApplicationRecord
def search(params)
q = super
q = q.search_attributes(params, :to, :from, :is_spam, :is_read, :is_deleted)
q = q.search_attributes(params, :to, :from, :is_spam, :is_read, :is_deleted, :title, :body)
q = q.text_attribute_matches(:title, params[:title_matches])
q = q.text_attribute_matches(:body, params[:message_matches], index_column: :message_index)

View File

@@ -47,7 +47,7 @@ class FavoriteGroup < ApplicationRecord
def search(params)
q = super
q = q.search_attributes(params, :is_public)
q = q.search_attributes(params, :name, :is_public, :post_count)
if params[:creator_id].present?
user = User.find(params[:creator_id])

View File

@@ -47,7 +47,7 @@ class ForumPost < ApplicationRecord
def search(params)
q = super
q = q.permitted
q = q.search_attributes(params, :creator, :topic_id, :is_deleted)
q = q.search_attributes(params, :creator, :updater, :topic_id, :is_deleted, :body)
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :text_index)
if params[:topic_title_matches].present?

View File

@@ -66,7 +66,7 @@ class ForumTopic < ApplicationRecord
def search(params)
q = super
q = q.permitted
q = q.search_attributes(params, :is_sticky, :is_locked, :is_deleted, :category_id, :title)
q = q.search_attributes(params, :creator, :updater, :is_sticky, :is_locked, :is_deleted, :category_id, :title, :response_count)
q = q.text_attribute_matches(:title, params[:title_matches], index_column: :text_index)
if params[:mod_only].present?

View File

@@ -12,6 +12,7 @@ class IpBan < ApplicationRecord
def self.search(params)
q = super
q = q.search_attributes(params, :creator, :reason)
if params[:ip_addr].present?
q = q.where("ip_addr = ?", params[:ip_addr])

View File

@@ -9,7 +9,7 @@ class JanitorTrial < ApplicationRecord
def self.search(params)
q = super.where(status: "active")
q = q.search_user_attribute(:user, params)
q = q.search_attributes(params, :user, :creator, :original_level)
q.apply_default_order(params)
end

View File

@@ -55,7 +55,7 @@ class ModAction < ApplicationRecord
def self.search(params)
q = super
q = q.search_attributes(params, :creator, :category)
q = q.search_attributes(params, :creator, :category, :description)
q = q.text_attribute_matches(:description, params[:description_matches])
q.apply_default_order(params)

View File

@@ -19,7 +19,7 @@ class Note < ApplicationRecord
def search(params)
q = super
q = q.search_attributes(params, :creator, :post, :is_active)
q = q.search_attributes(params, :creator, :post, :is_active, :x, :y, :width, :height, :body, :version)
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index)
q.apply_default_order(params)

View File

@@ -6,7 +6,7 @@ class NoteVersion < ApplicationRecord
def self.search(params)
q = super
q = q.search_attributes(params, :updater, :is_active, :post, :note_id)
q = q.search_attributes(params, :updater, :is_active, :post, :note_id, :x, :y, :width, :height, :body, :version)
q = q.text_attribute_matches(:body, params[:body_matches])
q.apply_default_order(params)

View File

@@ -57,7 +57,7 @@ class Pool < ApplicationRecord
def search(params)
q = super
q = q.search_attributes(params, :creator, :is_active, :is_deleted)
q = q.search_attributes(params, :creator, :is_active, :is_deleted, :name, :description)
q = q.text_attribute_matches(:description, params[:description_matches])
if params[:name_matches].present?

View File

@@ -11,13 +11,7 @@ class PoolVersion < ApplicationRecord
def search(params)
q = super
q = q.search_user_attribute(:updater, params)
if params[:pool_id].present?
q = q.where("pool_id = ?", params[:pool_id].to_i)
end
q = q.search_attributes(params, :updater, :pool_id)
q.apply_default_order(params)
end
end

View File

@@ -24,7 +24,7 @@ class PostAppeal < ApplicationRecord
def search(params)
q = super
q = q.search_attributes(params, :creator, :post)
q = q.search_attributes(params, :creator, :post, :reason)
q = q.text_attribute_matches(:reason, params[:reason_matches])
q = q.resolved if params[:is_resolved].to_s.truthy?

View File

@@ -34,10 +34,7 @@ class PostApproval < ApplicationRecord
def self.search(params)
q = super
q = q.search_user_attribute(:user, params)
q = q.search_post_id_attribute(params)
q = q.search_attributes(params, :user, :post)
q.apply_default_order(params)
end
end

View File

@@ -51,7 +51,7 @@ class PostFlag < ApplicationRecord
def search(params)
q = super
q = q.search_attributes(params, :post, :is_resolved)
q = q.search_attributes(params, :post, :is_resolved, :reason)
q = q.text_attribute_matches(:reason, params[:reason_matches])
# XXX

View File

@@ -879,7 +879,7 @@ class Tag < ApplicationRecord
def search(params)
q = super
q = q.search_attributes(params, :is_locked, :category)
q = q.search_attributes(params, :is_locked, :category, :post_count)
if params[:fuzzy_name_matches].present?
q = q.fuzzy_name_matches(params[:fuzzy_name_matches])

View File

@@ -109,6 +109,7 @@ class TagRelationship < ApplicationRecord
def search(params)
q = super
q = q.search_attributes(params, :creator, :approver, :forum_topic_id, :forum_post_id)
if params[:name_matches].present?
q = q.name_matches(params[:name_matches])

View File

@@ -177,7 +177,7 @@ class Upload < ApplicationRecord
def search(params)
q = super
q = q.search_attributes(params, :uploader, :post, :source, :rating, :parent_id, :server)
q = q.search_attributes(params, :uploader, :post, :source, :rating, :parent_id, :server, :md5, :server, :file_ext, :file_size, :image_width, :image_height, :referer_url)
if params[:source_matches].present?
q = q.where("uploads.source LIKE ? ESCAPE E'\\\\'", params[:source_matches].to_escaped_for_sql_like)

View File

@@ -44,7 +44,7 @@ class UserFeedback < ApplicationRecord
def search(params)
q = super
q = q.search_attributes(params, :user, :creator, :category)
q = q.search_attributes(params, :user, :creator, :category, :body)
q = q.text_attribute_matches(:body, params[:body_matches])
q.apply_default_order(params)

View File

@@ -53,13 +53,13 @@ class WikiPage < ApplicationRecord
def search(params = {})
q = super
q = q.search_attributes(params, :creator, :updater, :is_locked, :is_deleted, :body)
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index, ts_config: "danbooru")
if params[:title].present?
q = q.where("title LIKE ? ESCAPE E'\\\\'", params[:title].mb_chars.downcase.strip.tr(" ", "_").to_escaped_for_sql_like)
end
q = q.search_attributes(params, :creator, :is_locked, :is_deleted)
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index, ts_config: "danbooru")
if params[:other_names_match].present?
q = q.other_names_match(params[:other_names_match])
end