diff --git a/app/controllers/ip_addresses_controller.rb b/app/controllers/ip_addresses_controller.rb index 8689acc02..d111f7946 100644 --- a/app/controllers/ip_addresses_controller.rb +++ b/app/controllers/ip_addresses_controller.rb @@ -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) diff --git a/app/models/ip_address.rb b/app/models/ip_address.rb index ee8b2c1ad..e64226712 100644 --- a/app/models/ip_address.rb +++ b/app/models/ip_address.rb @@ -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 diff --git a/app/views/ip_addresses/_index.html.erb b/app/views/ip_addresses/_index.html.erb index 5896f56b5..2466a3885 100644 --- a/app/views/ip_addresses/_index.html.erb +++ b/app/views/ip_addresses/_index.html.erb @@ -20,5 +20,3 @@ <%= link_to "IP info", "https://ipinfo.io/#{ip.ip_addr}" %> <% end %> <% end %> - -<%= numbered_paginator(@ip_addresses) %> diff --git a/app/views/ip_addresses/index.html.erb b/app/views/ip_addresses/index.html.erb index 844889b80..e9a64b4b5 100644 --- a/app/views/ip_addresses/index.html.erb +++ b/app/views/ip_addresses/index.html.erb @@ -21,5 +21,7 @@ <% elsif @ip_addresses.present? %> <%= render "index" %> <% end %> + + <%= numbered_paginator(@ip_addresses) %>