diff --git a/app/controllers/ip_addresses_controller.rb b/app/controllers/ip_addresses_controller.rb index 9ad8db88a..8c5da0cdc 100644 --- a/app/controllers/ip_addresses_controller.rb +++ b/app/controllers/ip_addresses_controller.rb @@ -4,8 +4,8 @@ class IpAddressesController < ApplicationController respond_to :html, :xml, :json def show - @ip_address = authorize IpAddress.new(ip_addr: params[:id]) - @ip_info = @ip_address.ip_addr.ip_info + @ip_address = authorize Danbooru::IpAddress.new(params[:id]), policy_class: IpAddressPolicy + @ip_info = @ip_address.ip_info respond_with(@ip_info) end end diff --git a/app/logical/bigquery_export_service.rb b/app/logical/bigquery_export_service.rb index 2140bfe0e..4f17b0b2f 100644 --- a/app/logical/bigquery_export_service.rb +++ b/app/logical/bigquery_export_service.rb @@ -41,7 +41,7 @@ class BigqueryExportService Rails.application.eager_load! models = ApplicationRecord.descendants.sort_by(&:name) - models -= [GoodJob::BaseRecord, GoodJob::Process, GoodJob::Execution, GoodJob::ActiveJobJob, GoodJob::Job, GoodJob::Setting, IpAddress, TagRelationship, ArtistVersion, ArtistCommentaryVersion, NoteVersion, PoolVersion, PostVersion, WikiPageVersion, Post, PostVote, MediaAsset, Favorite, AITag] + models -= [GoodJob::BaseRecord, GoodJob::Process, GoodJob::Execution, GoodJob::ActiveJobJob, GoodJob::Job, GoodJob::Setting, TagRelationship, ArtistVersion, ArtistCommentaryVersion, NoteVersion, PoolVersion, PostVersion, WikiPageVersion, Post, PostVote, MediaAsset, Favorite, AITag] models end diff --git a/app/models/ip_address.rb b/app/models/ip_address.rb deleted file mode 100644 index b25b7345e..000000000 --- a/app/models/ip_address.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -class IpAddress < ApplicationRecord - belongs_to :model, polymorphic: true - belongs_to :user - attribute :ip_addr, :ip_address - - def self.model_types - %w[Post User Comment Dmail ArtistVersion ArtistCommentaryVersion NoteVersion WikiPageVersion] - end - - def self.visible(user) - user.is_admin? ? all : where.not(model_type: "Dmail") - end - - def self.search(params) - q = search_attributes(params, :ip_addr, :user, :model) - q.order(created_at: :desc) - end - - def self.group_by_ip_addr(ipv4_masklen = nil, ipv6_masklen = nil) - ipv4_masklen ||= 32 - ipv6_masklen ||= 128 - - q = select(sanitize_sql([<<~SQL.squish, ipv4_masklen, ipv6_masklen])) - CASE - WHEN family(ip_addr) = 4 - THEN network(set_masklen(ip_addr, ?)) - ELSE network(set_masklen(ip_addr, ?)) - END AS ip_addr, - COUNT(*) AS count_all - SQL - - q.group("1").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 lookup - @lookup ||= ip_addr.ip_lookup - end - - def to_s - ip_addr.to_s - end - - def readonly? - true - end - - def self.available_includes - [:user, :model] - end -end diff --git a/app/views/ip_addresses/_info.html.erb b/app/views/ip_addresses/_info.html.erb index c72136d30..be1a10d7b 100644 --- a/app/views/ip_addresses/_info.html.erb +++ b/app/views/ip_addresses/_info.html.erb @@ -28,10 +28,10 @@ Proxy? - <%= ip_address.ip_addr.is_proxy? ? "Yes" : "No" %> + <%= ip_address.is_proxy? ? "Yes" : "No" %> - <% if ip_address.ip_addr.is_tor? %> + <% if ip_address.is_tor? %> Tor? Yes @@ -41,8 +41,8 @@ IP Banned? - <% if IpBan.ip_matches(ip_address.ip_addr.to_s).exists? %> - Yes (<%= link_to "info", ip_bans_path(search: { ip_addr: ip_address.ip_addr.to_s }) %>) + <% if IpBan.ip_matches(ip_address.to_s).exists? %> + Yes (<%= link_to "info", ip_bans_path(search: { ip_addr: ip_address.to_s }) %>) <% else %> No <% end %> @@ -78,7 +78,7 @@ Details
-
<%= JSON.pretty_generate(ip_address.lookup.response) %>
+
<%= JSON.pretty_generate(ip_address.ip_lookup.response) %>
diff --git a/app/views/ip_addresses/show.html.erb b/app/views/ip_addresses/show.html.erb index 8ce4fe3f6..2e1e9a46b 100644 --- a/app/views/ip_addresses/show.html.erb +++ b/app/views/ip_addresses/show.html.erb @@ -2,7 +2,7 @@
-

IP Address: <%= @ip_address.ip_addr %>

+

IP Address: <%= @ip_address %>

<%= render "info", ip_address: @ip_address, ip_info: @ip_info %>
diff --git a/app/views/users/_statistics.html.erb b/app/views/users/_statistics.html.erb index 2d4a6ec38..bfa7666d1 100644 --- a/app/views/users/_statistics.html.erb +++ b/app/views/users/_statistics.html.erb @@ -18,7 +18,7 @@ <% end %> - <% if policy(IpAddress).show? %> + <% if policy(:ip_address).show? %> Last IP diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index bafd1db0e..5be72fcaf 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -15,7 +15,7 @@ <% t.column "Name", td: { class: "col-expand" } do |user| %> <%= link_to_user user %> <% end %> - <% if policy(IpAddress).show? %> + <% if policy(:ip_address).show? %> <% t.column "IP" do |user| %> <% if user.last_ip_addr.present? %> <%= link_to user.last_ip_addr, ip_address_path(user.last_ip_addr) %> diff --git a/app/views/users/show.html+tooltip.erb b/app/views/users/show.html+tooltip.erb index e0d4e69c3..75c83966d 100644 --- a/app/views/users/show.html+tooltip.erb +++ b/app/views/users/show.html+tooltip.erb @@ -34,7 +34,7 @@
<%= time_tag @user.created_at.to_date.iso8601, @user.created_at, class: "user-tooltip-created-at" %> - <% if @user.last_ip_addr.present? && policy(IpAddress).show? %> + <% if @user.last_ip_addr.present? && policy(:ip_address).show? %> ยท <%= link_to_ip @user.last_ip_addr, shorten: true, class: "link-plain" %> <% end %>