0
0

Add option to block reports from domain (#8830)

This commit is contained in:
Eugen Rochko 2018-10-20 08:02:44 +02:00 committed by GitHub
parent d5bfba3262
commit fd5285658f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 54 additions and 23 deletions

View File

@ -46,7 +46,7 @@ module Admin
end
def resource_params
params.require(:domain_block).permit(:domain, :severity, :reject_media, :retroactive)
params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_reports, :retroactive)
end
def retroactive_unblock?

View File

@ -1,17 +1,5 @@
import { delegate } from 'rails-ujs';
function handleDeleteStatus(event) {
const [data] = event.detail;
const element = document.querySelector(`[data-id="${data.id}"]`);
if (element) {
element.parentNode.removeChild(element);
}
}
[].forEach.call(document.querySelectorAll('.trash-button'), (content) => {
content.addEventListener('ajax:success', handleDeleteStatus);
});
const batchCheckboxClassName = '.batch-checkbox input[type="checkbox"]';
delegate(document, '#batch_checkbox_all', 'change', ({ target }) => {
@ -22,6 +10,7 @@ delegate(document, '#batch_checkbox_all', 'change', ({ target }) => {
delegate(document, batchCheckboxClassName, 'change', () => {
const checkAllElement = document.querySelector('#batch_checkbox_all');
if (checkAllElement) {
checkAllElement.checked = [].every.call(document.querySelectorAll(batchCheckboxClassName), (content) => content.checked);
checkAllElement.indeterminate = !checkAllElement.checked && [].some.call(document.querySelectorAll(batchCheckboxClassName), (content) => content.checked);
@ -42,7 +31,13 @@ delegate(document, '.media-spoiler-hide-button', 'click', () => {
delegate(document, '#domain_block_severity', 'change', ({ target }) => {
const rejectMediaDiv = document.querySelector('.input.with_label.domain_block_reject_media');
const rejectReportsDiv = document.querySelector('.input.with_label.domain_block_reject_reports');
if (rejectMediaDiv) {
rejectMediaDiv.style.display = (target.value === 'suspend') ? 'none' : 'block';
}
if (rejectReportsDiv) {
rejectReportsDiv.style.display = (target.value === 'suspend') ? 'none' : 'block';
}
});

View File

@ -2,6 +2,8 @@
class ActivityPub::Activity::Flag < ActivityPub::Activity
def perform
return if skip_reports?
target_accounts = object_uris.map { |uri| account_from_uri(uri) }.compact.select(&:local?)
target_statuses_by_account = object_uris.map { |uri| status_from_uri(uri) }.compact.select(&:local?).group_by(&:account_id)
@ -19,6 +21,12 @@ class ActivityPub::Activity::Flag < ActivityPub::Activity
end
end
private
def skip_reports?
DomainBlock.find_by(domain: @account.domain)&.reject_reports?
end
def object_uris
@object_uris ||= Array(@object.is_a?(Array) ? @object.map { |item| value_or_id(item) } : value_or_id(@object))
end

View File

@ -9,6 +9,7 @@
# updated_at :datetime not null
# severity :integer default("silence")
# reject_media :boolean default(FALSE), not null
# reject_reports :boolean default(FALSE), not null
#
class DomainBlock < ApplicationRecord

View File

@ -1,10 +1,13 @@
%tr
%td.domain
%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)

View File

@ -8,6 +8,7 @@
%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

View File

@ -17,5 +17,8 @@
.fields-group
= f.input :reject_media, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_media'), hint: I18n.t('admin.domain_blocks.reject_media_hint')
.fields-group
= f.input :reject_reports, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reports'), hint: I18n.t('admin.domain_blocks.reject_reports_hint')
.actions
= f.button :button, t('.create'), type: :submit

View File

@ -1,5 +1,5 @@
%tr
%td.domain
%td
%samp= email_domain_block.domain
%td
= table_link_to 'trash', t('admin.email_domain_blocks.delete'), admin_email_domain_block_path(email_domain_block), method: :delete

View File

@ -1,5 +1,5 @@
%tr
%td.domain
%td
= link_to instance.domain, admin_accounts_path(by_domain: instance.domain)
%td.count
= instance.accounts_count

View File

@ -263,6 +263,8 @@ en:
title: New domain block
reject_media: Reject media files
reject_media_hint: Removes locally stored media files and refuses to download any in the future. Irrelevant for suspensions
reject_reports: Reject reports
reject_reports_hint: Ignore all reports coming from this domain. Irrelevant for suspensions
severities:
noop: None
silence: Silence

View File

@ -0,0 +1,17 @@
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
class AddRejectReportsToDomainBlocks < ActiveRecord::Migration[5.2]
include Mastodon::MigrationHelpers
disable_ddl_transaction!
def up
safety_assured do
add_column_with_default :domain_blocks, :reject_reports, :boolean, default: false, allow_null: false
end
end
def down
remove_column :domain_blocks, :reject_reports
end
end

View File

@ -186,6 +186,7 @@ ActiveRecord::Schema.define(version: 2018_10_18_205649) do
t.datetime "updated_at", null: false
t.integer "severity", default: 0
t.boolean "reject_media", default: false, null: false
t.boolean "reject_reports", default: false, null: false
t.index ["domain"], name: "index_domain_blocks_on_domain", unique: true
end