Files
danbooru/app/models/ip_address.rb
evazion bf6bb94702 Add new IP address search page.
Add a new IP address search page at /ip_addresses. Replaces the old
search page at /moderator/ip_addrs.

On user profile pages, show the user's last known IP to mods. Also add
search links for finding other IPs or accounts associated with the user.

IP address search uses a big UNION ALL statement to merge IP addresses
across various tables into a single view. This makes searching easier,
but is known to timeout in certain cases.

Fixes #4207 (the new IP search page supports searching by subnet).
2019-11-11 21:03:07 -06:00

29 lines
782 B
Ruby

class IpAddress < ApplicationRecord
belongs_to :model, polymorphic: true
belongs_to :user
attribute :ip_addr, IpAddressType.new
def self.model_types
%w[Post User Comment Dmail ArtistVersion ArtistCommentaryVersion NoteVersion WikiPageVersion]
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
def self.group_by_ip_addr
group(:ip_addr).select("ip_addr, COUNT(*) AS count_all").reorder("count_all DESC, ip_addr")
end
def self.group_by_user
group(:user_id).select("user_id, COUNT(*) AS count_all").reorder("count_all DESC, user_id")
end
def readonly?
true
end
end