forked from fedi/mastodon
Add option to block reports from domain (#8830)
This commit is contained in:
parent
d5bfba3262
commit
fd5285658f
|
@ -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?
|
||||
|
|
|
@ -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);
|
||||
|
@ -41,8 +30,14 @@ 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 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';
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,12 +3,13 @@
|
|||
#
|
||||
# Table name: domain_blocks
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# domain :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# severity :integer default("silence")
|
||||
# reject_media :boolean default(FALSE), not null
|
||||
# id :bigint(8) not null, primary key
|
||||
# domain :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
# 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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
%tr
|
||||
%td.domain
|
||||
%td
|
||||
= link_to instance.domain, admin_accounts_path(by_domain: instance.domain)
|
||||
%td.count
|
||||
= instance.accounts_count
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue