mod dashboard: remove ip address search.

Remove the IP address search option from the /moderator/dashboard page.
This was an obsolete way of searching for sockpuppet accounts by IP.
The /user_events page should be used instead.
This commit is contained in:
evazion
2022-09-12 23:43:56 -05:00
parent fb980d4a16
commit e2a3265daf
14 changed files with 0 additions and 242 deletions

View File

@@ -1,17 +0,0 @@
# frozen_string_literal: true
module Moderator
class IpAddrsController < ApplicationController
respond_to :html, :json
def index
authorize IpAddress
@search = IpAddrSearch.new(params[:search])
@results = @search.execute
respond_with(@results)
end
def search
end
end
end

View File

@@ -1,78 +0,0 @@
# frozen_string_literal: true
module Moderator
class IpAddrSearch
attr_reader :params
def initialize(params)
@params = params
end
def execute
if params[:user_id].present?
search_by_user_id(params[:user_id].split)
elsif params[:user_name].present?
search_by_user_name(params[:user_name].split)
elsif params[:ip_addr].present?
search_by_ip_addr(params[:ip_addr].split)
else
[]
end
end
private
def search_by_ip_addr(ip_addrs)
sums = Hash.new {|h, k| h[k] = 0}
add_row(sums, ArtistCommentaryVersion.where(updater_ip_addr: ip_addrs).group(:updater).count)
add_row(sums, ArtistVersion.where(updater_ip_addr: ip_addrs).group(:updater).count)
add_row(sums, NoteVersion.where(updater_ip_addr: ip_addrs).group(:updater).count)
add_row(sums, WikiPageVersion.where(updater_ip_addr: ip_addrs).group(:updater).count)
add_row(sums, Comment.where(creator_ip_addr: ip_addrs).group(:creator).count)
add_row(sums, Dmail.where(creator_ip_addr: ip_addrs).group(:from).count)
add_row(sums, Upload.where(uploader_ip_addr: ip_addrs).group(:uploader).count)
add_row(sums, Hash[User.where(last_ip_addr: ip_addrs).collect { |user| [user, 1] }])
add_row_id(sums, PoolVersion.where(updater_ip_addr: ip_addrs).group(:updater_id).count) if PoolVersion.enabled?
add_row_id(sums, PostVersion.where(updater_ip_addr: ip_addrs).group(:updater_id).count) if PostVersion.enabled?
sums
end
def search_by_user_name(user_names)
user_ids = user_names.map { |name| User.name_to_id(name) }
search_by_user_id(user_ids)
end
def search_by_user_id(user_ids)
sums = Hash.new {|h, k| h[k] = 0}
users = User.find(user_ids)
add_row(sums, ArtistCommentaryVersion.where(updater: users).group(:updater_ip_addr).count)
add_row(sums, ArtistVersion.where(updater: users).group(:updater_ip_addr).count)
add_row(sums, NoteVersion.where(updater: users).group(:updater_ip_addr).count)
add_row(sums, PoolVersion.where(updater_id: users.map(&:id)).group(:updater_ip_addr).count) if PoolVersion.enabled?
add_row(sums, PostVersion.where(updater_id: users.map(&:id)).group(:updater_ip_addr).count) if PostVersion.enabled?
add_row(sums, WikiPageVersion.where(updater: users).group(:updater_ip_addr).count)
add_row(sums, Comment.where(creator: users).group(:creator_ip_addr).count)
add_row(sums, Dmail.where(from: users).group(:creator_ip_addr).count)
add_row(sums, Upload.where(uploader: users).group(:uploader_ip_addr).count)
add_row(sums, User.where(id: users).where.not(last_ip_addr: nil).group(:last_ip_addr).count)
sums
end
def add_row(sums, counts)
sums.merge!(counts) { |_key, oldcount, newcount| oldcount + newcount }
end
def add_row_id(sums, counts)
user_counts = {}
counts.each do |k, v|
user_counts[User.find(k)] = v
end
add_row(sums, user_counts)
end
end
end

View File

@@ -1,7 +1,3 @@
<div id="ip-addr-search">
<%= render "search_ip_addr" %>
</div>
<div id="activity-search">
<%= render "search_activity" %>
</div>

View File

@@ -1,5 +0,0 @@
<%= search_form_for(moderator_ip_addrs_path) do |f| %>
<%= f.input :ip_addr, label: "IPs ", hint: "Separate with spaces", input_html: { value: params.dig(:search, :ip_addr) } %>
<%= f.input :user_name, label: "Users", hint: "Separate with spaces", input_html: { value: params.dig(:search, :user_name), "data-autocomplete": "user" } %>
<%= f.submit "Search" %>
<% end %>

View File

@@ -1,18 +0,0 @@
<p><%= link_to "Search for users with these IP addresses", moderator_ip_addrs_path(:search => {:ip_addr => @results.keys.reject{|ip| ip == "127.0.0.1"}.join(",")}) %></p>
<table class="striped">
<thead>
<tr>
<th>IP Address</th>
<th>Number of Occurrences</th>
</tr>
</thead>
<tbody>
<% @results.each do |ip_address, count| %>
<tr>
<td><%= link_to_ip ip_address %></td>
<td><%= count %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -1 +0,0 @@
<%= raw @results.map {|ip_addr, count| {ip_addr: ip_addr.to_s, count: count}}.to_json %>

View File

@@ -1,20 +0,0 @@
<p><%= link_to "Search for IP addresses with these users", moderator_ip_addrs_path(:search => {:user_id => @results.map{|user, count| user.id}.join(",")}) %></p>
<table class="striped">
<thead>
<tr>
<th>User</th>
<th>Number of Occurrences</th>
<th></th>
</tr>
</thead>
<tbody>
<% @results.each do |user, count| %>
<tr>
<td><%= link_to_user user %></td>
<td><%= count %></td>
<td><%= link_to "Show IP addresses", moderator_ip_addrs_path(:search => {:user_id => user.id}) %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -1 +0,0 @@
<%= raw @results.map {|user, count| {user_id: user.id, count: count}}.to_json %>

View File

@@ -1,17 +0,0 @@
<% page_title "IP Addresses" %>
<div id="c-moderator-ip-addrs">
<div id="a-index">
<h1>IP Addresses</h1>
<% if params[:search][:user_id].present? || params[:search][:user_name].present? %>
<div id="p-ip-listing">
<%= render "ip_listing" %>
</div>
<% else %>
<div id="p-user-listing">
<%= render "user_listing" %>
</div>
<% end %>
</div>
</div>

View File

@@ -1,5 +0,0 @@
<% if params[:search][:user_id].present? || params[:search][:user_name].present? %>
<%= render "ip_listing.json" %>
<% else %>
<%= render "user_listing.json" %>
<% end %>

View File

@@ -1,13 +0,0 @@
<% page_title "Search IP Addresses" %>
<div id="c-moderator-ip-addrs">
<div id="a-search">
<h1>Search IP Addresses</h1>
<%= search_form_for(moderator_ip_addrs_path) do |f| %>
<%= f.input :ip_addr, label: "IPs ", hint: "Separate with spaces", input_html: { value: params.dig(:search, :ip_addr) } %>
<%= f.input :user_name, label: "Users", hint: "Separate with spaces", input_html: { value: params.dig(:search, :user_name), "data-autocomplete": "user" } %>
<%= f.submit "Search" %>
<% end %>
</div>
</div>