diff --git a/app/helpers/admin/domain_blocks_helper.rb b/app/helpers/admin/domain_blocks_helper.rb new file mode 100644 index 0000000000..cdd3467d7a --- /dev/null +++ b/app/helpers/admin/domain_blocks_helper.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Admin::DomainBlocksHelper + CONNECTOR = ' · ' + + def domain_block_policies(domain_block) + domain_block + .policies + .map { |policy| t("admin.instances.content_policies.policies.#{policy}") } + .join(CONNECTOR) + end +end diff --git a/app/views/admin/export_domain_blocks/_domain_block.html.haml b/app/views/admin/export_domain_blocks/_domain_block.html.haml index 79cc5595ca..b7ed1f555c 100644 --- a/app/views/admin/export_domain_blocks/_domain_block.html.haml +++ b/app/views/admin/export_domain_blocks/_domain_block.html.haml @@ -17,7 +17,7 @@ %br/ - = f.object.policies.map { |policy| t(policy, scope: 'admin.instances.content_policies.policies') }.join(' · ') + = domain_block_policies(f.object) - if f.object.public_comment.present? · = f.object.public_comment diff --git a/app/views/admin/instances/_instance.html.haml b/app/views/admin/instances/_instance.html.haml index 4cae3caf52..c5b5915a52 100644 --- a/app/views/admin/instances/_instance.html.haml +++ b/app/views/admin/instances/_instance.html.haml @@ -6,7 +6,7 @@ %small - if instance.domain_block - = instance.domain_block.policies.map { |policy| t(policy, scope: 'admin.instances.content_policies.policies') }.join(' · ') + = domain_block_policies(instance.domain_block) - if instance.domain_block.public_comment.present? %span.comment.public-comment #{t('admin.domain_blocks.public_comment')}: #{instance.domain_block.public_comment} - if instance.domain_block.private_comment.present? diff --git a/app/views/admin/instances/show.html.haml b/app/views/admin/instances/show.html.haml index 812a9c8870..17fa05986e 100644 --- a/app/views/admin/instances/show.html.haml +++ b/app/views/admin/instances/show.html.haml @@ -37,7 +37,7 @@ %td= @instance.domain_block.public_comment %tr %th= t('admin.instances.content_policies.policy') - %td= @instance.domain_block.policies.map { |policy| t(policy, scope: 'admin.instances.content_policies.policies') }.join(' · ') + %td= domain_block_policies(@instance.domain_block) = link_to t('admin.domain_blocks.edit'), edit_admin_domain_block_path(@instance.domain_block), class: 'button' = link_to t('admin.domain_blocks.undo'), admin_domain_block_path(@instance.domain_block), class: 'button', data: { confirm: t('admin.accounts.are_you_sure'), method: :delete } diff --git a/spec/helpers/admin/domain_blocks_helper_spec.rb b/spec/helpers/admin/domain_blocks_helper_spec.rb new file mode 100644 index 0000000000..1ee05863c7 --- /dev/null +++ b/spec/helpers/admin/domain_blocks_helper_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Admin::DomainBlocksHelper do + describe '#domain_block_policies' do + subject { helper.domain_block_policies(domain_block) } + + context 'with a suspend domain block' do + let(:domain_block) { Fabricate.build :domain_block, severity: :suspend } + + it { is_expected.to eq('Suspend') } + end + + context 'with a multi policy domain block' do + let(:domain_block) { Fabricate.build :domain_block, severity: :silence, reject_media: true, reject_reports: true } + + it { is_expected.to eq('Limit · Reject media · Reject reports') } + end + end +end