ip bans: add search form.

* Add IP ban search form to /ip_bans page.
* Make some attributes searchable that weren't previously searchable.
This commit is contained in:
evazion
2020-12-17 20:21:40 -06:00
parent 3d1ff9dff9
commit 25069865b7
2 changed files with 18 additions and 4 deletions

View File

@@ -25,14 +25,18 @@ class IpBan < ApplicationRecord
end
def self.search(params)
q = search_attributes(params, :id, :created_at, :updated_at, :reason, :creator)
q = search_attributes(params, :id, :created_at, :updated_at, :ip_addr, :reason, :is_deleted, :category, :hit_count, :last_hit_at, :creator)
q = q.text_attribute_matches(:reason, params[:reason_matches])
if params[:ip_addr].present?
q = q.where("ip_addr = ?", params[:ip_addr])
case params[:order]
when /\A(created_at|updated_at|last_hit_at)(?:_(asc|desc))?\z/i
dir = $2 || :desc
q = q.order($1 => dir).order(id: :desc)
else
q = q.apply_default_order(params)
end
q.apply_default_order(params)
q
end
def create_mod_action