Add `domain_block_policies` helper method

pull/32941/head
Matt Jankowski 2024-11-16 10:16:27 -05:00
parent a1ac2a73ff
commit 5fb8c95b3a
5 changed files with 36 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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?

View File

@ -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 }

View File

@ -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