Compare commits
1 commit
main
...
feature-ab
Author | SHA1 | Date | |
---|---|---|---|
|
7f4db65217 |
7 changed files with 77 additions and 0 deletions
9
app/controllers/admin/abuse_metrics_controller.rb
Normal file
9
app/controllers/admin/abuse_metrics_controller.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Admin
|
||||
class AbuseMetricsController < BaseController
|
||||
def index
|
||||
authorize :dashboard, :index?
|
||||
end
|
||||
end
|
||||
end
|
|
@ -11,6 +11,8 @@ class Admin::Metrics::Dimension
|
|||
tag_languages: Admin::Metrics::Dimension::TagLanguagesDimension,
|
||||
instance_accounts: Admin::Metrics::Dimension::InstanceAccountsDimension,
|
||||
instance_languages: Admin::Metrics::Dimension::InstanceLanguagesDimension,
|
||||
ips: Admin::Metrics::Dimension::IPsDimension,
|
||||
email_domains: Admin::Metrics::Dimension::EmailDomainsDimension,
|
||||
}.freeze
|
||||
|
||||
def self.retrieve(dimension_keys, start_at, end_at, limit, params)
|
||||
|
|
24
app/lib/admin/metrics/dimension/email_domains_dimension.rb
Normal file
24
app/lib/admin/metrics/dimension/email_domains_dimension.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Admin::Metrics::Dimension::EmailDomainsDimension < Admin::Metrics::Dimension::BaseDimension
|
||||
def key
|
||||
'email_domains'
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def perform_query
|
||||
sql = <<-SQL.squish
|
||||
SELECT split_part(email, '@', 2) AS domain, count(*) AS value
|
||||
FROM users
|
||||
WHERE created_at BETWEEN $1 AND $2
|
||||
GROUP BY split_part(email, '@', 2)
|
||||
ORDER BY count(*) DESC
|
||||
LIMIT $3
|
||||
SQL
|
||||
|
||||
rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, @start_at], [nil, @end_at], [nil, @limit]])
|
||||
|
||||
rows.map { |row| { key: row['domain'], human_key: row['domain'], value: row['value'].to_s } }
|
||||
end
|
||||
end
|
24
app/lib/admin/metrics/dimension/ips_dimension.rb
Normal file
24
app/lib/admin/metrics/dimension/ips_dimension.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Admin::Metrics::Dimension::IPsDimension < Admin::Metrics::Dimension::BaseDimension
|
||||
def key
|
||||
'ips'
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def perform_query
|
||||
sql = <<-SQL.squish
|
||||
SELECT sign_up_ip, count(*) AS value
|
||||
FROM users
|
||||
WHERE created_at BETWEEN $1 AND $2
|
||||
GROUP BY sign_up_ip
|
||||
ORDER BY count(*) DESC
|
||||
LIMIT $3
|
||||
SQL
|
||||
|
||||
rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, @start_at], [nil, @end_at], [nil, @limit]])
|
||||
|
||||
rows.map { |row| { key: row['sign_up_ip'], human_key: row['sign_up_ip'], value: row['value'].to_s } }
|
||||
end
|
||||
end
|
16
app/views/admin/abuse_metrics/index.html.haml
Normal file
16
app/views/admin/abuse_metrics/index.html.haml
Normal file
|
@ -0,0 +1,16 @@
|
|||
- content_for :header_tags do
|
||||
= javascript_pack_tag 'admin', async: true, crossorigin: 'anonymous'
|
||||
|
||||
.dashboard
|
||||
.dashboard__item
|
||||
= react_admin_component :dimension, dimension: 'ips', start_at: 1.hour.ago, end_at: Time.now.utc, limit: 8, label: 'New accounts by IP last hour'
|
||||
.dashboard__item
|
||||
= react_admin_component :dimension, dimension: 'ips', start_at: 1.day.ago, end_at: Time.now.utc, limit: 8, label: 'New accounts by IP last day'
|
||||
.dashboard__item
|
||||
= react_admin_component :dimension, dimension: 'ips', start_at: 7.days.ago, end_at: Time.now.utc, limit: 8, label: 'New accounts by IP last week'
|
||||
.dashboard__item
|
||||
= react_admin_component :dimension, dimension: 'email_domains', start_at: 1.hour.ago, end_at: Time.now.utc, limit: 8, label: 'New accounts by e-mail domain last hour'
|
||||
.dashboard__item
|
||||
= react_admin_component :dimension, dimension: 'email_domains', start_at: 1.day.ago, end_at: Time.now.utc, limit: 8, label: 'New accounts by e-mail domain last day'
|
||||
.dashboard__item
|
||||
= react_admin_component :dimension, dimension: 'email_domains', start_at: 7.days.ago, end_at: Time.now.utc, limit: 8, label: 'New accounts by e-mail domain last week'
|
|
@ -25,6 +25,7 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
|
|||
inflect.acronym 'REST'
|
||||
inflect.acronym 'URL'
|
||||
inflect.acronym 'ASCII'
|
||||
inflect.acronym 'IPs'
|
||||
|
||||
inflect.singular 'data', 'data'
|
||||
end
|
||||
|
|
|
@ -189,6 +189,7 @@ Rails.application.routes.draw do
|
|||
|
||||
namespace :admin do
|
||||
get '/dashboard', to: 'dashboard#index'
|
||||
get '/abuse_metrics', to: 'abuse_metrics#index'
|
||||
|
||||
resources :domain_allows, only: [:new, :create, :show, :destroy]
|
||||
resources :domain_blocks, only: [:new, :create, :destroy, :update, :edit]
|
||||
|
|
Loading…
Reference in a new issue