Remove IpAddress model.

This commit is contained in:
evazion
2022-09-17 23:29:57 -05:00
parent 075199cd1e
commit 553d35178c
8 changed files with 12 additions and 68 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -28,10 +28,10 @@
<tr>
<th>Proxy?</th>
<td><%= ip_address.ip_addr.is_proxy? ? "Yes" : "No" %></td>
<td><%= ip_address.is_proxy? ? "Yes" : "No" %></td>
</tr>
<% if ip_address.ip_addr.is_tor? %>
<% if ip_address.is_tor? %>
<tr>
<th>Tor?</th>
<td>Yes</td>
@@ -41,8 +41,8 @@
<tr>
<th>IP Banned?</th>
<td>
<% 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 @@
<th>Details</th>
<td>
<details>
<pre><%= JSON.pretty_generate(ip_address.lookup.response) %></pre>
<pre><%= JSON.pretty_generate(ip_address.ip_lookup.response) %></pre>
</details>
</td>
</tr>

View File

@@ -2,7 +2,7 @@
<div id="c-ip-addresses">
<div id="a-show">
<h1>IP Address: <%= @ip_address.ip_addr %></h1>
<h1>IP Address: <%= @ip_address %></h1>
<%= render "info", ip_address: @ip_address, ip_info: @ip_info %>
</div>

View File

@@ -18,7 +18,7 @@
</tr>
<% end %>
<% if policy(IpAddress).show? %>
<% if policy(:ip_address).show? %>
<tr>
<th>Last IP</th>
<td>

View File

@@ -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) %>

View File

@@ -34,7 +34,7 @@
<div class="user-tooltip-header-bottom">
<%= 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 %>