Skip to content

Commit

Permalink
Redesign admin instances area
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron committed Jan 5, 2019
1 parent fae3263 commit 8f6d6ca
Show file tree
Hide file tree
Showing 60 changed files with 159 additions and 531 deletions.
11 changes: 3 additions & 8 deletions app/controllers/admin/domain_blocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ module Admin
class DomainBlocksController < BaseController
before_action :set_domain_block, only: [:show, :destroy]

def index
authorize :domain_block, :index?
@domain_blocks = DomainBlock.page(params[:page])
end

def new
authorize :domain_block, :create?
@domain_block = DomainBlock.new
@domain_block = DomainBlock.new(domain: params[:_domain])
end

def create
Expand All @@ -22,7 +17,7 @@ def create
if @domain_block.save
DomainBlockWorker.perform_async(@domain_block.id)
log_action :create, @domain_block
redirect_to admin_domain_blocks_path, notice: I18n.t('admin.domain_blocks.created_msg')
redirect_to admin_instances_path(limited: '1'), notice: I18n.t('admin.domain_blocks.created_msg')
else
render :new
end
Expand All @@ -36,7 +31,7 @@ def destroy
authorize @domain_block, :destroy?
UnblockDomainService.new.call(@domain_block, retroactive_unblock?)
log_action :destroy, @domain_block
redirect_to admin_domain_blocks_path, notice: I18n.t('admin.domain_blocks.destroyed_msg')
redirect_to admin_instances_path(limited: '1'), notice: I18n.t('admin.domain_blocks.destroyed_msg')
end

private
Expand Down
27 changes: 14 additions & 13 deletions app/controllers/admin/instances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ module Admin
class InstancesController < BaseController
def index
authorize :instance, :index?

@instances = ordered_instances
end

def resubscribe
authorize :instance, :resubscribe?
params.require(:by_domain)
Pubsubhubbub::SubscribeWorker.push_bulk(subscribeable_accounts.pluck(:id))
redirect_to admin_instances_path
def show
authorize :instance, :show?

@instance = Instance.new(Account.by_domain_accounts.find_by(domain: params[:id]) || DomainBlock.find_by!(domain: params[:id]))
@following_count = Follow.where(account: Account.where(domain: params[:id])).count
@followers_count = Follow.where(target_account: Account.where(domain: params[:id])).count
@reports_count = Report.where(target_account: Account.where(domain: params[:id])).count
@blocks_count = Block.where(target_account: Account.where(domain: params[:id])).count
@available = DeliveryFailureTracker.available?(Account.select(:shared_inbox_url).where(domain: params[:id]).first&.shared_inbox_url)
@media_storage = MediaAttachment.where(account: Account.where(domain: params[:id])).sum(:file_file_size)
@domain_block = DomainBlock.find_by(domain: params[:id])
end

private
Expand All @@ -27,17 +34,11 @@ def paginated_instances
helper_method :paginated_instances

def ordered_instances
paginated_instances.map { |account| Instance.new(account) }
end

def subscribeable_accounts
Account.remote.where(protocol: :ostatus).where(domain: params[:by_domain])
paginated_instances.map { |resource| Instance.new(resource) }
end

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

FILTERS = ACCOUNT_FILTERS + REPORT_FILTERS + INVITE_FILTER + CUSTOM_EMOJI_FILTERS + TAGS_FILTERS
FILTERS = ACCOUNT_FILTERS + REPORT_FILTERS + INVITE_FILTER + CUSTOM_EMOJI_FILTERS + TAGS_FILTERS + INSTANCES_FILTERS

def filter_link_to(text, link_to_params, link_class_params = link_to_params)
new_url = filtered_url_for(link_to_params)
Expand Down
14 changes: 14 additions & 0 deletions app/javascript/styles/mastodon/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ $no-columns-breakpoint: 600px;
font-weight: 500;
}

.directory__tag a {
box-shadow: none;
}

.directory__tag h4 {
font-size: 18px;
font-weight: 700;
color: $primary-text-color;
text-transform: none;
padding-bottom: 0;
margin-bottom: 0;
border-bottom: none;
}

& > p {
font-size: 14px;
line-height: 18px;
Expand Down
1 change: 1 addition & 0 deletions app/javascript/styles/mastodon/dashboard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
color: $primary-text-color;
font-family: $font-display, sans-serif;
margin-bottom: 20px;
line-height: 30px;
}

&__text {
Expand Down
21 changes: 17 additions & 4 deletions app/models/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,23 @@
class Instance
include ActiveModel::Model

attr_accessor :domain, :accounts_count
attr_accessor :domain, :accounts_count, :domain_block

def initialize(account)
@domain = account.domain
@accounts_count = account.accounts_count
def initialize(resource)
@domain = resource.domain
@accounts_count = resource.accounts_count
@domain_block = resource.is_a?(DomainBlock) ? resource : DomainBlock.find_by(domain: domain)
end

def cached_sample_accounts
Rails.cache.fetch("#{cache_key}/sample_accounts", expires_in: 12.hours) { Account.where(domain: domain).searchable.joins(:account_stat).popular.limit(3) }
end

def to_param
domain
end

def cache_key
domain
end
end
17 changes: 3 additions & 14 deletions app/models/instance_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,10 @@ def initialize(params)
end

def results
scope = Account.remote.by_domain_accounts
params.each do |key, value|
scope.merge!(scope_for(key, value)) if value.present?
end
scope
end

private

def scope_for(key, value)
case key.to_s
when 'domain_name'
Account.matches_domain(value)
if params[:limited].present?
DomainBlock.order(id: :desc)
else
raise "Unknown filter: #{key}"
Account.remote.by_domain_accounts
end
end
end
2 changes: 1 addition & 1 deletion app/policies/instance_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def index?
admin?
end

def resubscribe?
def show?
admin?
end
end
13 changes: 0 additions & 13 deletions app/views/admin/domain_blocks/_domain_block.html.haml

This file was deleted.

17 changes: 0 additions & 17 deletions app/views/admin/domain_blocks/index.html.haml

This file was deleted.

4 changes: 1 addition & 3 deletions app/views/admin/instances/_instance.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
%tr
%td
= link_to instance.domain, admin_accounts_path(by_domain: instance.domain)
= link_to instance.domain, admin_instance_path(instance)
%td.count
= instance.accounts_count
%td
= table_link_to 'paper-plane-o', t('admin.accounts.resubscribe'), resubscribe_admin_instances_url(by_domain: instance.domain), method: :post, data: { confirm: t('admin.accounts.are_you_sure') }
48 changes: 32 additions & 16 deletions app/views/admin/instances/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
- content_for :page_title do
= t('admin.instances.title')

= form_tag admin_instances_url, method: 'GET', class: 'simple_form' do
.fields-group
- %i(domain_name).each do |key|
.input.string.optional
= text_field_tag key, params[key], class: 'string optional', placeholder: I18n.t("admin.instances.#{key}")
.filters
.filter-subset
%strong= t('admin.instances.moderation.title')
%ul
%li= filter_link_to t('admin.instances.moderation.all'), limited: nil
%li= filter_link_to t('admin.instances.moderation.limited'), limited: '1'

.actions
%button= t('admin.instances.search')
= link_to t('admin.instances.reset'), admin_instances_path, class: 'button negative'
%div{ style: 'flex: 1 1 auto; text-align: right' }
= link_to t('admin.domain_blocks.add_new'), new_admin_domain_block_path, class: 'button'

.table-wrapper
%table.table
%thead
%tr
%th= t('admin.instances.domain_name')
%th= t('admin.instances.account_count')
%tbody
= render @instances
%hr.spacer/

- @instances.each do |instance|
.directory__tag
= link_to admin_instance_path(instance) do
%h4
= instance.domain
%small
= t('admin.instances.known_accounts', count: instance.accounts_count)

- if instance.domain_block
- if !instance.domain_block.noop?
&bull;
= t("admin.domain_blocks.severity.#{instance.domain_block.severity}")
- if instance.domain_block.reject_media?
&bull;
= t('admin.domain_blocks.rejecting_media')
- if instance.domain_block.reject_reports?
&bull;
= t('admin.domain_blocks.rejecting_reports')

.avatar-stack
- instance.cached_sample_accounts.each do |account|
= image_tag current_account&.user&.setting_auto_play_gif ? account.avatar_original_url : account.avatar_static_url, width: 48, height: 48, alt: '', class: 'account__avatar'

= paginate paginated_instances
44 changes: 44 additions & 0 deletions app/views/admin/instances/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
- content_for :page_title do
= @instance.domain

.dashboard__counters
%div
%div
.dashboard__counters__num= number_with_delimiter @following_count
.dashboard__counters__label= t 'admin.instances.total_followed_by_them'
%div
%div
.dashboard__counters__num= number_with_delimiter @followers_count
.dashboard__counters__label= t 'admin.instances.total_followed_by_us'
%div
%div
.dashboard__counters__num= number_to_human_size @media_storage
.dashboard__counters__label= t 'admin.instances.total_storage'
%div
%div
.dashboard__counters__num= number_with_delimiter @blocks_count
.dashboard__counters__label= t 'admin.instances.total_blocked_by_us'
%div
%div
.dashboard__counters__num= number_with_delimiter @reports_count
.dashboard__counters__label= t 'admin.instances.total_reported'
%div
%div
.dashboard__counters__num
- if @available
= fa_icon 'check'
- else
= fa_icon 'times'
.dashboard__counters__label= t 'admin.instances.delivery_available'

%hr.spacer/

%div{ style: 'overflow: hidden' }
%div{ style: 'float: left' }
= link_to t('admin.accounts.title'), admin_accounts_path(remote: '1', by_domain: @instance.domain), class: 'button'

%div{ style: 'float: right' }
- if @domain_block
= link_to t('admin.domain_blocks.undo'), admin_domain_block_path(@domain_block), class: 'button'
- else
= link_to t('admin.domain_blocks.add_new'), new_admin_domain_block_path(_domain: @instance.domain), class: 'button'
10 changes: 0 additions & 10 deletions config/locales/ar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,6 @@ ar:
reject_media: رفض ملفات الوسائط
reject_media_hint: يزيل ملفات الوسائط المخزنة محليًا ويرفض تنزيل أي ملفات في المستقبل. غير ذي صلة للتعليق
reject_reports: رفض التقارير
severities:
noop: لا شيء
silence: إخفاء أو كتم
suspend: تعليق
severity: الشدة
show:
affected_accounts:
few: "%{count} حسابات معنية في قاعدة البيانات"
Expand All @@ -298,7 +293,6 @@ ar:
suspend: إلغاء التعليق المفروض على كافة حسابات هذا النطاق
title: رفع حظر النطاق عن %{domain}
undo: إلغاء
title: حظر النطاقات
undo: إلغاء
email_domain_blocks:
add_new: إضافة
Expand All @@ -311,10 +305,6 @@ ar:
title: إضافة نطاق بريد جديد إلى اللائحة السوداء
title: القائمة السوداء للبريد الإلكتروني
instances:
account_count: الحسابات المعروفة
domain_name: النطاق
reset: إعادة تعيين
search: البحث
title: مثيلات الخوادم المعروفة
invites:
deactivate_all: تعطيلها كافة
Expand Down
2 changes: 0 additions & 2 deletions config/locales/ast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ ast:
email_domain_blocks:
domain: Dominiu
instances:
account_count: Cuentes conocíes
domain_name: Dominiu
title: Instancies conocíes
invites:
filter:
Expand Down
10 changes: 0 additions & 10 deletions config/locales/ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,6 @@ ca:
reject_media_hint: Elimina els fitxers multimèdia emmagatzemats localment i impedeix baixar-ne cap en el futur. Irrellevant en les suspensions
reject_reports: Rebutja informes
reject_reports_hint: Ignora tots els informes procedents d'aquest domini. No és rellevant per a les suspensions
severities:
noop: Cap
silence: Silenci
suspend: Suspensió
severity: Severitat
show:
affected_accounts:
one: Un compte afectat en la base de dades
Expand All @@ -277,7 +272,6 @@ ca:
suspend: Desfés la suspensió de tots els comptes d'aquest domini
title: Desfés el bloqueig de domini de %{domain}
undo: Desfés
title: Bloquejos de domini
undo: Desfés
email_domain_blocks:
add_new: Afegeix
Expand All @@ -290,10 +284,6 @@ ca:
title: Nova adreça de correu en la llista negra
title: Llista negra de correus electrònics
instances:
account_count: Comptes coneguts
domain_name: Domini
reset: Restableix
search: Cerca
title: Instàncies conegudes
invites:
deactivate_all: Desactiva-ho tot
Expand Down
Loading

0 comments on commit 8f6d6ca

Please sign in to comment.