summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-02-18 14:59:19 +0100
committerEugen Rochko <eugen@zeonfederated.com>2019-02-23 17:18:50 +0100
commit3dd663c45573f04d223acb0c8b98d9ab50c5f14d (patch)
tree7b4476831e8a85a01dfe4ccfb660001fec4c4ead
parent07fffd226db1b62bf7d76f83239b7082e2836373 (diff)
Add domain search/filter to the "Federation" (/admin/instances) page (#10071)
-rw-r--r--app/controllers/admin/instances_controller.rb2
-rw-r--r--app/helpers/admin/filter_helper.rb2
-rw-r--r--app/models/domain_block.rb2
-rw-r--r--app/models/instance_filter.rb8
-rw-r--r--app/views/admin/instances/index.html.haml14
-rw-r--r--config/locales/en.yml1
6 files changed, 25 insertions, 4 deletions
diff --git a/app/controllers/admin/instances_controller.rb b/app/controllers/admin/instances_controller.rb
index 431ce6f4de1..6dd659a304a 100644
--- a/app/controllers/admin/instances_controller.rb
+++ b/app/controllers/admin/instances_controller.rb
@@ -38,7 +38,7 @@ module Admin
end
def filter_params
- params.permit(:limited)
+ params.permit(:limited, :by_domain)
end
end
end
diff --git a/app/helpers/admin/filter_helper.rb b/app/helpers/admin/filter_helper.rb
index 97beb587fce..275b5f2fe0d 100644
--- a/app/helpers/admin/filter_helper.rb
+++ b/app/helpers/admin/filter_helper.rb
@@ -6,7 +6,7 @@ module Admin::FilterHelper
INVITE_FILTER = %i(available expired).freeze
CUSTOM_EMOJI_FILTERS = %i(local remote by_domain shortcode).freeze
TAGS_FILTERS = %i(hidden).freeze
- INSTANCES_FILTERS = %i(limited).freeze
+ INSTANCES_FILTERS = %i(limited by_domain).freeze
FILTERS = ACCOUNT_FILTERS + REPORT_FILTERS + INVITE_FILTER + CUSTOM_EMOJI_FILTERS + TAGS_FILTERS + INSTANCES_FILTERS
diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb
index 1064ea7c8f2..069cda3673e 100644
--- a/app/models/domain_block.rb
+++ b/app/models/domain_block.rb
@@ -24,6 +24,8 @@ class DomainBlock < ApplicationRecord
has_many :accounts, foreign_key: :domain, primary_key: :domain
delegate :count, to: :accounts, prefix: true
+ scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
+
def self.blocked?(domain)
where(domain: domain, severity: :suspend).exists?
end
diff --git a/app/models/instance_filter.rb b/app/models/instance_filter.rb
index 3483d8cd6e9..848fff53e15 100644
--- a/app/models/instance_filter.rb
+++ b/app/models/instance_filter.rb
@@ -9,9 +9,13 @@ class InstanceFilter
def results
if params[:limited].present?
- DomainBlock.order(id: :desc)
+ scope = DomainBlock
+ scope = scope.matches_domain(params[:by_domain]) if params[:by_domain].present?
+ scope.order(id: :desc)
else
- Account.remote.by_domain_accounts
+ scope = Account.remote
+ scope = scope.matches_domain(params[:by_domain]) if params[:by_domain].present?
+ scope.by_domain_accounts
end
end
end
diff --git a/app/views/admin/instances/index.html.haml b/app/views/admin/instances/index.html.haml
index ce35b5db475..2a5af3b5d61 100644
--- a/app/views/admin/instances/index.html.haml
+++ b/app/views/admin/instances/index.html.haml
@@ -11,6 +11,20 @@
%div{ style: 'flex: 1 1 auto; text-align: right' }
= link_to t('admin.domain_blocks.add_new'), new_admin_domain_block_path, class: 'button'
+= form_tag admin_instances_url, method: 'GET', class: 'simple_form' do
+ .fields-group
+ - Admin::FilterHelper::INSTANCES_FILTERS.each do |key|
+ - if params[key].present?
+ = hidden_field_tag key, params[key]
+
+ - %i(by_domain).each do |key|
+ .input.string.optional
+ = text_field_tag key, params[key], class: 'string optional', placeholder: I18n.t("admin.instances.#{key}")
+
+ .actions
+ %button= t('admin.accounts.search')
+ = link_to t('admin.accounts.reset'), admin_custom_emojis_path, class: 'button negative'
+
%hr.spacer/
- @instances.each do |instance|
diff --git a/config/locales/en.yml b/config/locales/en.yml
index ba413f8fc2e..a6e7e70a527 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -302,6 +302,7 @@ en:
back_to_account: Back To Account
title: "%{acct}'s Followers"
instances:
+ by_domain: Domain
delivery_available: Delivery is available
known_accounts:
one: "%{count} known account"