Commit 2d0e0769 authored by evazion's avatar evazion

/ip_addresses: add paginator to group_by=(user|ip_addr) pages.

parent 089c3049
......@@ -3,12 +3,14 @@ class IpAddressesController < ApplicationController
before_action :moderator_only
def index
@ip_addresses = IpAddress.visible(CurrentUser.user).paginated_search(params)
if search_params[:group_by] == "ip_addr"
@ip_addresses = IpAddress.search(search_params).group_by_ip_addr(search_params[:ipv4_masklen], search_params[:ipv6_masklen]).paginate(params[:page], limit: params[:limit] || 1000)
@ip_addresses = @ip_addresses.group_by_ip_addr(search_params[:ipv4_masklen], search_params[:ipv6_masklen])
elsif search_params[:group_by] == "user"
@ip_addresses = IpAddress.includes(:user).search(search_params).group_by_user.paginate(params[:page], limit: params[:limit] || 1000)
@ip_addresses = @ip_addresses.group_by_user.includes(:user)
else
@ip_addresses = IpAddress.includes(:user, :model).paginated_search(params)
@ip_addresses = @ip_addresses.includes(:user, :model)
end
respond_with(@ip_addresses)
......
......@@ -7,9 +7,12 @@ class IpAddress < ApplicationRecord
%w[Post User Comment Dmail ArtistVersion ArtistCommentaryVersion NoteVersion WikiPageVersion]
end
def self.visible(user)
CurrentUser.is_admin? ? all : where.not(model_type: "Dmail")
end
def self.search(params)
q = super
q = q.where.not(model_type: "Dmail") unless CurrentUser.is_admin?
q = q.search_attributes(params, :user, :model_type, :model_id, :ip_addr)
q.order(created_at: :desc)
end
......
......@@ -20,5 +20,3 @@
<%= link_to "IP info", "https://ipinfo.io/#{ip.ip_addr}" %>
<% end %>
<% end %>
<%= numbered_paginator(@ip_addresses) %>
......@@ -21,5 +21,7 @@
<% elsif @ip_addresses.present? %>
<%= render "index" %>
<% end %>
<%= numbered_paginator(@ip_addresses) %>
</div>
</div>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment