From 1c6588accca23599ea1537ec527a5be04408b2af Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 8 Jan 2019 13:39:49 +0100 Subject: [PATCH] Redesign admin instances area (#9645) --- .../admin/domain_blocks_controller.rb | 11 ++--- app/controllers/admin/instances_controller.rb | 27 ++++++----- app/helpers/admin/filter_helper.rb | 3 +- app/javascript/styles/mastodon/admin.scss | 14 ++++++ app/javascript/styles/mastodon/dashboard.scss | 1 + app/models/instance.rb | 21 ++++++-- app/models/instance_filter.rb | 17 ++----- app/policies/instance_policy.rb | 2 +- .../domain_blocks/_domain_block.html.haml | 13 ----- app/views/admin/domain_blocks/index.html.haml | 17 ------- app/views/admin/instances/_instance.html.haml | 4 +- app/views/admin/instances/index.html.haml | 48 ++++++++++++------- app/views/admin/instances/show.html.haml | 44 +++++++++++++++++ config/locales/ar.yml | 10 ---- config/locales/ast.yml | 2 - config/locales/ca.yml | 10 ---- config/locales/co.yml | 10 ---- config/locales/cs.yml | 10 ---- config/locales/cy.yml | 10 ---- config/locales/da.yml | 10 ---- config/locales/de.yml | 10 ---- config/locales/el.yml | 10 ---- config/locales/en.yml | 34 ++++++++----- config/locales/eo.yml | 10 ---- config/locales/es.yml | 10 ---- config/locales/eu.yml | 10 ---- config/locales/fa.yml | 10 ---- config/locales/fi.yml | 10 ---- config/locales/fr.yml | 10 ---- config/locales/gl.yml | 10 ---- config/locales/he.yml | 7 --- config/locales/hu.yml | 10 ---- config/locales/id.yml | 7 --- config/locales/io.yml | 7 --- config/locales/it.yml | 10 ---- config/locales/ja.yml | 10 ---- config/locales/ka.yml | 10 ---- config/locales/ko.yml | 10 ---- config/locales/ms.yml | 10 ---- config/locales/nl.yml | 10 ---- config/locales/no.yml | 10 ---- config/locales/oc.yml | 10 ---- config/locales/pl.yml | 10 ---- config/locales/pt-BR.yml | 10 ---- config/locales/pt.yml | 10 ---- config/locales/ru.yml | 10 ---- config/locales/sk.yml | 10 ---- config/locales/sr-Latn.yml | 10 ---- config/locales/sr.yml | 10 ---- config/locales/sv.yml | 10 ---- config/locales/th.yml | 7 --- config/locales/tr.yml | 7 --- config/locales/uk.yml | 10 ---- config/locales/zh-CN.yml | 10 ---- config/locales/zh-HK.yml | 10 ---- config/locales/zh-TW.yml | 10 ---- config/navigation.rb | 3 +- config/routes.rb | 8 +--- .../admin/domain_blocks_controller_spec.rb | 24 +--------- spec/policies/instance_policy_spec.rb | 2 +- 60 files changed, 159 insertions(+), 531 deletions(-) delete mode 100644 app/views/admin/domain_blocks/_domain_block.html.haml delete mode 100644 app/views/admin/domain_blocks/index.html.haml create mode 100644 app/views/admin/instances/show.html.haml diff --git a/app/controllers/admin/domain_blocks_controller.rb b/app/controllers/admin/domain_blocks_controller.rb index 90c70275a..5f307ddee 100644 --- a/app/controllers/admin/domain_blocks_controller.rb +++ b/app/controllers/admin/domain_blocks_controller.rb @@ -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 @@ -22,7 +17,7 @@ module Admin 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 @@ -36,7 +31,7 @@ module Admin 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 diff --git a/app/controllers/admin/instances_controller.rb b/app/controllers/admin/instances_controller.rb index 6f8eaf65c..431ce6f4d 100644 --- a/app/controllers/admin/instances_controller.rb +++ b/app/controllers/admin/instances_controller.rb @@ -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 @@ -27,17 +34,11 @@ module Admin 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 diff --git a/app/helpers/admin/filter_helper.rb b/app/helpers/admin/filter_helper.rb index 8807cc784..97beb587f 100644 --- a/app/helpers/admin/filter_helper.rb +++ b/app/helpers/admin/filter_helper.rb @@ -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) diff --git a/app/javascript/styles/mastodon/admin.scss b/app/javascript/styles/mastodon/admin.scss index e8f331932..375c655f5 100644 --- a/app/javascript/styles/mastodon/admin.scss +++ b/app/javascript/styles/mastodon/admin.scss @@ -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; diff --git a/app/javascript/styles/mastodon/dashboard.scss b/app/javascript/styles/mastodon/dashboard.scss index 1f96e7368..e4564f062 100644 --- a/app/javascript/styles/mastodon/dashboard.scss +++ b/app/javascript/styles/mastodon/dashboard.scss @@ -39,6 +39,7 @@ color: $primary-text-color; font-family: $font-display, sans-serif; margin-bottom: 20px; + line-height: 30px; } &__text { diff --git a/app/models/instance.rb b/app/models/instance.rb index 6d5c9c2ab..7448d465c 100644 --- a/app/models/instance.rb +++ b/app/models/instance.rb @@ -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 diff --git a/app/models/instance_filter.rb b/app/models/instance_filter.rb index 5073cf1fa..3483d8cd6 100644 --- a/app/models/instance_filter.rb +++ b/app/models/instance_filter.rb @@ -8,21 +8,10 @@ class InstanceFilter 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 diff --git a/app/policies/instance_policy.rb b/app/policies/instance_policy.rb index d1956e2de..a73823556 100644 --- a/app/policies/instance_policy.rb +++ b/app/policies/instance_policy.rb @@ -5,7 +5,7 @@ class InstancePolicy < ApplicationPolicy admin? end - def resubscribe? + def show? admin? end end diff --git a/app/views/admin/domain_blocks/_domain_block.html.haml b/app/views/admin/domain_blocks/_domain_block.html.haml deleted file mode 100644 index 7bfea3574..000000000 --- a/app/views/admin/domain_blocks/_domain_block.html.haml +++ /dev/null @@ -1,13 +0,0 @@ -%tr - %td - %samp= domain_block.domain - %td.severity - = t("admin.domain_blocks.severities.#{domain_block.severity}") - %td.reject_media - - if domain_block.reject_media? || domain_block.suspend? - %i.fa.fa-check - %td.reject_reports - - if domain_block.reject_reports? || domain_block.suspend? - %i.fa.fa-check - %td - = table_link_to 'undo', t('admin.domain_blocks.undo'), admin_domain_block_path(domain_block) diff --git a/app/views/admin/domain_blocks/index.html.haml b/app/views/admin/domain_blocks/index.html.haml deleted file mode 100644 index 4c5221c42..000000000 --- a/app/views/admin/domain_blocks/index.html.haml +++ /dev/null @@ -1,17 +0,0 @@ -- content_for :page_title do - = t('admin.domain_blocks.title') - -.table-wrapper - %table.table - %thead - %tr - %th= t('admin.domain_blocks.domain') - %th= t('admin.domain_blocks.severity') - %th= t('admin.domain_blocks.reject_media') - %th= t('admin.domain_blocks.reject_reports') - %th - %tbody - = render @domain_blocks - -= paginate @domain_blocks -= link_to t('admin.domain_blocks.add_new'), new_admin_domain_block_path, class: 'button' diff --git a/app/views/admin/instances/_instance.html.haml b/app/views/admin/instances/_instance.html.haml index e36ebae47..57d3e0b06 100644 --- a/app/views/admin/instances/_instance.html.haml +++ b/app/views/admin/instances/_instance.html.haml @@ -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') } diff --git a/app/views/admin/instances/index.html.haml b/app/views/admin/instances/index.html.haml index 3314ce077..ce35b5db4 100644 --- a/app/views/admin/instances/index.html.haml +++ b/app/views/admin/instances/index.html.haml @@ -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? + • + = t("admin.domain_blocks.severity.#{instance.domain_block.severity}") + - if instance.domain_block.reject_media? + • + = t('admin.domain_blocks.rejecting_media') + - if instance.domain_block.reject_reports? + • + = 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 diff --git a/app/views/admin/instances/show.html.haml b/app/views/admin/instances/show.html.haml new file mode 100644 index 000000000..c7992a490 --- /dev/null +++ b/app/views/admin/instances/show.html.haml @@ -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' diff --git a/config/locales/ar.yml b/config/locales/ar.yml index 8766190e3..abbfa38aa 100644 --- a/config/locales/ar.yml +++ b/config/locales/ar.yml @@ -280,11 +280,6 @@ ar: reject_media: رفض ملفات الوسائط reject_media_hint: يزيل ملفات الوسائط المخزنة محليًا ويرفض تنزيل أي ملفات في المستقبل. غير ذي صلة للتعليق reject_reports: رفض التقارير - severities: - noop: لا شيء - silence: إخفاء أو كتم - suspend: تعليق - severity: الشدة show: affected_accounts: few: "%{count} حسابات معنية في قاعدة البيانات" @@ -298,7 +293,6 @@ ar: suspend: إلغاء التعليق المفروض على كافة حسابات هذا النطاق title: رفع حظر النطاق عن %{domain} undo: إلغاء - title: حظر النطاقات undo: إلغاء email_domain_blocks: add_new: إضافة @@ -311,10 +305,6 @@ ar: title: إضافة نطاق بريد جديد إلى اللائحة السوداء title: القائمة السوداء للبريد الإلكتروني instances: - account_count: الحسابات المعروفة - domain_name: النطاق - reset: إعادة تعيين - search: البحث title: مثيلات الخوادم المعروفة invites: deactivate_all: تعطيلها كافة diff --git a/config/locales/ast.yml b/config/locales/ast.yml index 6c7ffc9bd..78ad796a0 100644 --- a/config/locales/ast.yml +++ b/config/locales/ast.yml @@ -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: diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 9cb9722c1..271fc3581 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -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 @@ -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 @@ -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 diff --git a/config/locales/co.yml b/config/locales/co.yml index 1529c4fa3..7a87219ab 100644 --- a/config/locales/co.yml +++ b/config/locales/co.yml @@ -265,11 +265,6 @@ co: reject_media_hint: Sguassa tutti i media caricati è ricusa caricamenti futuri. Inutile per una suspensione reject_reports: Righjittà i rapporti reject_reports_hint: Ignurà tutti i signalamenti chì venenu d'issu duminiu. Senz'oghjettu pè e suspensione - severities: - noop: Nisuna - silence: Silenzà - suspend: Suspende - severity: Severità show: affected_accounts: one: Un contu tuccatu indè a database @@ -279,7 +274,6 @@ co: suspend: Ùn suspende più i conti nant’à stu duminiu title: Ùn bluccà più u duminiu %{domain} undo: Annullà - title: Blucchimi di duminiu undo: Annullà email_domain_blocks: add_new: Aghjustà @@ -292,10 +286,6 @@ co: title: Nova iscrizzione nant’a lista nera e-mail title: Lista nera e-mail instances: - account_count: Conti cunnisciuti - domain_name: Duminiu - reset: Riinizializà - search: Cercà title: Istanze cunnisciute invites: deactivate_all: Disattivà tuttu diff --git a/config/locales/cs.yml b/config/locales/cs.yml index 0b666a23b..d2caeb999 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -269,11 +269,6 @@ cs: reject_media_hint: Odstraní lokálně uložené soubory a odmítne jejich stažení v budoucnosti. Irelevantní pro suspenzace reject_reports: Odmítnout nahlášení reject_reports_hint: Ignorovat všechna nahlášení pocházející z této domény. Nepodstatné pro suspenzace - severities: - noop: Žádné - silence: Utišit - suspend: Suspendovat - severity: Přísnost show: affected_accounts: few: "%{count} účty v databázi byly ovlivněny" @@ -284,7 +279,6 @@ cs: suspend: Zrušit suspenzaci všech existujících účtů z této domény title: Zrušit blokaci domény %{domain} undo: Odvolat - title: Doménové blokace undo: Odvolat email_domain_blocks: add_new: Přidat nový @@ -297,10 +291,6 @@ cs: title: Nový e-mail pro zablokování title: Černá listina e-mailů instances: - account_count: Známé účty - domain_name: Doména - reset: Resetovat - search: Hledat title: Známé instance invites: deactivate_all: Deaktivovat vše diff --git a/config/locales/cy.yml b/config/locales/cy.yml index 22b70d1fd..40cb1cac0 100644 --- a/config/locales/cy.yml +++ b/config/locales/cy.yml @@ -252,11 +252,6 @@ cy: reject_media_hint: Dileu dogfennau cyfryngau wedi eu cadw yn lleol ac yn gwrthod i lawrlwytho unrhyw rai yn y dyfodol. Amherthnasol i ataliadau reject_reports: Gwrthod adroddiadau reject_reports_hint: Anwybyddu'r holl adroddiadau sy'n dod o'r parth hwn. Amherthnasol i ataliadau - severities: - noop: Dim - silence: Tawelu - suspend: Atal - severity: Difrifoldeb show: affected_accounts: "%{count} o gyfrifoedd yn y bas data wedi eu hefeithio" retroactive: @@ -264,7 +259,6 @