[Admin] Expose and improve ip ban search

This commit is contained in:
Earlopain 2023-03-01 19:25:19 +01:00
parent 1a22b62cbe
commit fd28503e03
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
3 changed files with 19 additions and 6 deletions

View File

@ -8,11 +8,11 @@ class IpBansController < ApplicationController
def create
@ip_ban = IpBan.create(ip_ban_params)
respond_with(@ip_ban, :location => ip_bans_path)
respond_with(@ip_ban, location: ip_bans_path)
end
def index
@ip_bans = IpBan.includes(:creator).search(search_params).paginate(params[:page], :limit => params[:limit])
@ip_bans = IpBan.includes(:creator).search(search_params).paginate(params[:page], limit: params[:limit])
respond_with(@ip_bans)
end
@ -29,6 +29,6 @@ class IpBansController < ApplicationController
end
def search_params
permit_search_params %i[ip_addr order]
permit_search_params %i[ip_addr banner_name reason]
end
end

View File

@ -18,9 +18,15 @@ class IpBan < ApplicationRecord
q = super
if params[:ip_addr].present?
q = q.where("ip_addr = ?", params[:ip_addr])
q = q.where("ip_addr >>= ?", params[:ip_addr])
end
if params[:banner_name].present?
q = q.where(creator_id: User.name_to_id(params[:banner_name]))
end
q = q.attribute_matches(:reason, params[:reason])
q.apply_default_order(params)
end
@ -42,7 +48,7 @@ class IpBan < ApplicationRecord
def subnetted_ip
str = ip_addr.to_s
str += "/" + ip_addr.prefix.to_s if has_subnet?
str += "/#{ip_addr.prefix}" if has_subnet?
str
end
end

View File

@ -2,6 +2,13 @@
<div id="a-index">
<h1>IP Bans</h1>
<%= form_search(path: ip_bans_path) do |f| %>
<%= f.input :ip_addr, label: "IP Address" %>
<%= f.input :banner_name, label: "Banner" %>
<%= f.input :reason %>
<%= f.submit "Search" %>
<% end %>
<table class="striped">
<thead>
<tr>
@ -19,7 +26,7 @@
<td><%= link_to_user ip_ban.creator %></td>
<td><%= ip_ban.reason %></td>
<td><%= compact_time ip_ban.created_at %></td>
<td><%= link_to "Unban", ip_ban_path(ip_ban), :method => :delete, :data => {:confirm => "Do your really want to unban #{ip_ban.ip_addr}?"} %></td>
<td><%= link_to "Unban", ip_ban_path(ip_ban), method: :delete, data: { confirm: "Do your really want to unban #{ip_ban.ip_addr}?" } %></td>
</tr>
<% end %>
</tbody>