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:
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -1,7 +1,3 @@
|
|||||||
<div id="ip-addr-search">
|
|
||||||
<%= render "search_ip_addr" %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="activity-search">
|
<div id="activity-search">
|
||||||
<%= render "search_activity" %>
|
<%= render "search_activity" %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -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 %>
|
|
||||||
@@ -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>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<%= raw @results.map {|ip_addr, count| {ip_addr: ip_addr.to_s, count: count}}.to_json %>
|
|
||||||
@@ -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>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<%= raw @results.map {|user, count| {user_id: user.id, count: count}}.to_json %>
|
|
||||||
@@ -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>
|
|
||||||
@@ -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 %>
|
|
||||||
@@ -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>
|
|
||||||
@@ -23,11 +23,6 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
namespace :moderator do
|
namespace :moderator do
|
||||||
resource :dashboard, :only => [:show]
|
resource :dashboard, :only => [:show]
|
||||||
resources :ip_addrs, :only => [:index] do
|
|
||||||
collection do
|
|
||||||
get :search
|
|
||||||
end
|
|
||||||
end
|
|
||||||
namespace :post do
|
namespace :post do
|
||||||
resources :posts, :only => [:delete, :expunge, :confirm_delete] do
|
resources :posts, :only => [:delete, :expunge, :confirm_delete] do
|
||||||
member do
|
member do
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
require 'test_helper'
|
|
||||||
|
|
||||||
module Moderator
|
|
||||||
class IpAddrsControllerTest < ActionDispatch::IntegrationTest
|
|
||||||
context "The ip addrs controller" do
|
|
||||||
setup do
|
|
||||||
@user = create(:moderator_user, created_at: 1.month.ago)
|
|
||||||
as(@user) { create(:comment, creator: @user) }
|
|
||||||
end
|
|
||||||
|
|
||||||
should "find by ip addr" do
|
|
||||||
get_auth moderator_ip_addrs_path, @user, params: {:search => {:ip_addr => "127.0.0.1"}}
|
|
||||||
assert_response :success
|
|
||||||
end
|
|
||||||
|
|
||||||
should "find by user id" do
|
|
||||||
get_auth moderator_ip_addrs_path, @user, params: {:search => {:user_id => @user.id.to_s}}
|
|
||||||
assert_response :success
|
|
||||||
end
|
|
||||||
|
|
||||||
should "find by user name" do
|
|
||||||
get_auth moderator_ip_addrs_path, @user, params: {:search => {:user_name => @user.name}}
|
|
||||||
assert_response :success
|
|
||||||
end
|
|
||||||
|
|
||||||
should "render the search page" do
|
|
||||||
get_auth search_moderator_ip_addrs_path, @user
|
|
||||||
assert_response :success
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
require "test_helper"
|
|
||||||
|
|
||||||
module Moderator
|
|
||||||
class IpAddrSearchTest < ActiveSupport::TestCase
|
|
||||||
context "an ip addr search" do
|
|
||||||
setup do
|
|
||||||
@user = create(:user, last_ip_addr: "127.0.0.1")
|
|
||||||
end
|
|
||||||
|
|
||||||
should "find by ip addr" do
|
|
||||||
@search = IpAddrSearch.new(:ip_addr => "127.0.0.1")
|
|
||||||
assert_equal({@user => 1}, @search.execute)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "find by user id" do
|
|
||||||
@search = IpAddrSearch.new(:user_id => @user.id.to_s)
|
|
||||||
assert_equal({IPAddr.new("127.0.0.1") => 1}, @search.execute)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "find by user name" do
|
|
||||||
@search = IpAddrSearch.new(:user_name => @user.name)
|
|
||||||
assert_equal({IPAddr.new("127.0.0.1") => 1}, @search.execute)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Reference in New Issue
Block a user