diff --git a/app/controllers/moderator/ip_addrs_controller.rb b/app/controllers/moderator/ip_addrs_controller.rb deleted file mode 100644 index 83f92453b..000000000 --- a/app/controllers/moderator/ip_addrs_controller.rb +++ /dev/null @@ -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 diff --git a/app/logical/moderator/ip_addr_search.rb b/app/logical/moderator/ip_addr_search.rb deleted file mode 100644 index 26f3032c6..000000000 --- a/app/logical/moderator/ip_addr_search.rb +++ /dev/null @@ -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 diff --git a/app/views/moderator/dashboards/_search.html.erb b/app/views/moderator/dashboards/_search.html.erb index 5afb07120..481720808 100644 --- a/app/views/moderator/dashboards/_search.html.erb +++ b/app/views/moderator/dashboards/_search.html.erb @@ -1,7 +1,3 @@ - - diff --git a/app/views/moderator/dashboards/_search_ip_addr.html.erb b/app/views/moderator/dashboards/_search_ip_addr.html.erb deleted file mode 100644 index f11163713..000000000 --- a/app/views/moderator/dashboards/_search_ip_addr.html.erb +++ /dev/null @@ -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 %> diff --git a/app/views/moderator/ip_addrs/_ip_listing.html.erb b/app/views/moderator/ip_addrs/_ip_listing.html.erb deleted file mode 100644 index 4c9f00714..000000000 --- a/app/views/moderator/ip_addrs/_ip_listing.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -

<%= 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(",")}) %>

- - - - - - - - - - <% @results.each do |ip_address, count| %> - - - - - <% end %> - -
IP AddressNumber of Occurrences
<%= link_to_ip ip_address %><%= count %>
diff --git a/app/views/moderator/ip_addrs/_ip_listing.json.erb b/app/views/moderator/ip_addrs/_ip_listing.json.erb deleted file mode 100644 index 45801c1ba..000000000 --- a/app/views/moderator/ip_addrs/_ip_listing.json.erb +++ /dev/null @@ -1 +0,0 @@ -<%= raw @results.map {|ip_addr, count| {ip_addr: ip_addr.to_s, count: count}}.to_json %> diff --git a/app/views/moderator/ip_addrs/_user_listing.erb b/app/views/moderator/ip_addrs/_user_listing.erb deleted file mode 100644 index be9a7c988..000000000 --- a/app/views/moderator/ip_addrs/_user_listing.erb +++ /dev/null @@ -1,20 +0,0 @@ -

<%= link_to "Search for IP addresses with these users", moderator_ip_addrs_path(:search => {:user_id => @results.map{|user, count| user.id}.join(",")}) %>

- - - - - - - - - - - <% @results.each do |user, count| %> - - - - - - <% end %> - -
UserNumber of Occurrences
<%= link_to_user user %><%= count %><%= link_to "Show IP addresses", moderator_ip_addrs_path(:search => {:user_id => user.id}) %>
diff --git a/app/views/moderator/ip_addrs/_user_listing.json.erb b/app/views/moderator/ip_addrs/_user_listing.json.erb deleted file mode 100644 index a8df6882f..000000000 --- a/app/views/moderator/ip_addrs/_user_listing.json.erb +++ /dev/null @@ -1 +0,0 @@ -<%= raw @results.map {|user, count| {user_id: user.id, count: count}}.to_json %> diff --git a/app/views/moderator/ip_addrs/index.html.erb b/app/views/moderator/ip_addrs/index.html.erb deleted file mode 100644 index 9543dfc6a..000000000 --- a/app/views/moderator/ip_addrs/index.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -<% page_title "IP Addresses" %> - -
-
-

IP Addresses

- - <% if params[:search][:user_id].present? || params[:search][:user_name].present? %> -
- <%= render "ip_listing" %> -
- <% else %> -
- <%= render "user_listing" %> -
- <% end %> -
-
diff --git a/app/views/moderator/ip_addrs/index.json.erb b/app/views/moderator/ip_addrs/index.json.erb deleted file mode 100644 index 75017df8c..000000000 --- a/app/views/moderator/ip_addrs/index.json.erb +++ /dev/null @@ -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 %> diff --git a/app/views/moderator/ip_addrs/search.html.erb b/app/views/moderator/ip_addrs/search.html.erb deleted file mode 100644 index 58b567222..000000000 --- a/app/views/moderator/ip_addrs/search.html.erb +++ /dev/null @@ -1,13 +0,0 @@ -<% page_title "Search IP Addresses" %> - -
- -
diff --git a/config/routes.rb b/config/routes.rb index 8ddb8fa69..668bdf226 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -23,11 +23,6 @@ Rails.application.routes.draw do end namespace :moderator do resource :dashboard, :only => [:show] - resources :ip_addrs, :only => [:index] do - collection do - get :search - end - end namespace :post do resources :posts, :only => [:delete, :expunge, :confirm_delete] do member do diff --git a/test/functional/moderator/ip_addrs_controller_test.rb b/test/functional/moderator/ip_addrs_controller_test.rb deleted file mode 100644 index 135a8cf05..000000000 --- a/test/functional/moderator/ip_addrs_controller_test.rb +++ /dev/null @@ -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 diff --git a/test/unit/moderator/ip_addr_search_test.rb b/test/unit/moderator/ip_addr_search_test.rb deleted file mode 100644 index d74b1c0c5..000000000 --- a/test/unit/moderator/ip_addr_search_test.rb +++ /dev/null @@ -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