Skip to content

Commit

Permalink
Add domain search/filter to the "Federation" (/admin/instances) page (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and hiyuki2578 committed Oct 2, 2019
1 parent bcd7fba commit 11d6904
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/instances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def ordered_instances
end

def filter_params
params.permit(:limited)
params.permit(:limited, :by_domain)
end
end
end
2 changes: 1 addition & 1 deletion app/helpers/admin/filter_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions app/models/domain_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions app/models/instance_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ def initialize(params)

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
14 changes: 14 additions & 0 deletions app/views/admin/instances/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 11d6904

Please sign in to comment.