Model#search: factor out username search.

This commit is contained in:
evazion
2019-08-19 17:58:23 -05:00
parent 9a3e9747d8
commit c3ad7f6112
26 changed files with 41 additions and 189 deletions

View File

@@ -28,22 +28,8 @@ class Ban < ApplicationRecord
def self.search(params)
q = super
if params[:banner_name]
q = q.where("banner_id = (select _.id from users _ where lower(_.name) = ?)", params[:banner_name].mb_chars.downcase)
end
if params[:banner_id]
q = q.where("banner_id = ?", params[:banner_id].to_i)
end
if params[:user_name]
q = q.where("user_id = (select _.id from users _ where lower(_.name) = ?)", params[:user_name].mb_chars.downcase)
end
if params[:user_id]
q = q.where("user_id = ?", params[:user_id].to_i)
end
q = q.search_user_attribute(:banner, params)
q = q.search_user_attribute(:user, params)
q = q.attribute_matches(:reason, params[:reason_matches])
q = q.expired if params[:expired].to_s.truthy?