parent
96da1fcb00
commit
8793bc286e
13 changed files with 71 additions and 10 deletions
|
@ -89,17 +89,18 @@ module Admin
|
|||
|
||||
def update_params
|
||||
params.require(:domain_block).permit(:severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_send_sensitive, :reject_hashtag,
|
||||
:reject_straight_follow, :reject_new_follow, :reject_friend, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden)
|
||||
:reject_straight_follow, :reject_new_follow, :reject_friend, :block_trends, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden)
|
||||
end
|
||||
|
||||
def resource_params
|
||||
params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_send_sensitive, :reject_hashtag,
|
||||
:reject_straight_follow, :reject_new_follow, :reject_friend, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden)
|
||||
:reject_straight_follow, :reject_new_follow, :reject_friend, :block_trends, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden)
|
||||
end
|
||||
|
||||
def form_domain_block_batch_params
|
||||
params.require(:form_domain_block_batch).permit(domain_blocks_attributes: [:enabled, :domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers,
|
||||
:reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :reject_friend, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden])
|
||||
:reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :reject_friend, :block_trends, :detect_invalid_subscription,
|
||||
:reject_reports, :private_comment, :public_comment, :obfuscate, :hidden])
|
||||
end
|
||||
|
||||
def action_from_button
|
||||
|
|
|
@ -70,7 +70,7 @@ class Api::V1::Admin::DomainBlocksController < Api::BaseController
|
|||
|
||||
def domain_block_params
|
||||
params.permit(:severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_reports, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow,
|
||||
:reject_new_follow, :reject_friend, :detect_invalid_subscription, :private_comment, :public_comment, :obfuscate, :hidden)
|
||||
:reject_new_follow, :reject_friend, :block_trends, :detect_invalid_subscription, :private_comment, :public_comment, :obfuscate, :hidden)
|
||||
end
|
||||
|
||||
def insert_pagination_headers
|
||||
|
@ -103,6 +103,6 @@ class Api::V1::Admin::DomainBlocksController < Api::BaseController
|
|||
|
||||
def resource_params
|
||||
params.permit(:domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow,
|
||||
:reject_new_follow, :reject_friend, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden)
|
||||
:reject_new_follow, :reject_friend, :block_trends, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
# detect_invalid_subscription :boolean default(FALSE), not null
|
||||
# reject_reply_exclude_followers :boolean default(FALSE), not null
|
||||
# reject_friend :boolean default(FALSE), not null
|
||||
# block_trends :boolean default(FALSE), not null
|
||||
#
|
||||
|
||||
class DomainBlock < ApplicationRecord
|
||||
|
@ -49,6 +50,7 @@ class DomainBlock < ApplicationRecord
|
|||
.or(where(reject_new_follow: true))
|
||||
.or(where(reject_straight_follow: true))
|
||||
.or(where(reject_friend: true))
|
||||
.or(where(block_trends: true))
|
||||
}
|
||||
scope :by_severity, -> { in_order_of(:severity, %w(noop silence suspend)).order(:domain) }
|
||||
|
||||
|
@ -70,6 +72,7 @@ class DomainBlock < ApplicationRecord
|
|||
reject_straight_follow? ? :reject_straight_follow : nil,
|
||||
reject_new_follow? ? :reject_new_follow : nil,
|
||||
reject_friend? ? :reject_friend : nil,
|
||||
block_trends? ? :block_trends : nil,
|
||||
detect_invalid_subscription? ? :detect_invalid_subscription : nil,
|
||||
reject_reports? ? :reject_reports : nil].reject { |policy| policy == :noop || policy.nil? }
|
||||
end
|
||||
|
@ -116,6 +119,10 @@ class DomainBlock < ApplicationRecord
|
|||
!!rule_for(domain)&.reject_friend?
|
||||
end
|
||||
|
||||
def block_trends?(domain)
|
||||
!!rule_for(domain)&.block_trends?
|
||||
end
|
||||
|
||||
def detect_invalid_subscription?(domain)
|
||||
!!rule_for(domain)&.detect_invalid_subscription?
|
||||
end
|
||||
|
|
|
@ -110,7 +110,13 @@ class Trends::Statuses < Trends::Base
|
|||
(status.public_visibility? || status.public_unlisted_visibility?) &&
|
||||
status.account.discoverable? && !status.account.silenced? && !status.account.sensitized? &&
|
||||
status.spoiler_text.blank? && (!status.sensitive? || status.media_attachments.none?) &&
|
||||
!status.reply? && valid_locale?(status.language)
|
||||
!status.reply? && valid_locale?(status.language) && !domain_blocked?(status)
|
||||
end
|
||||
|
||||
def domain_blocked?(status)
|
||||
return false if status.account.local?
|
||||
|
||||
DomainBlock.block_trends?(status.account.domain)
|
||||
end
|
||||
|
||||
def calculate_scores(statuses, at_time)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
class REST::Admin::DomainBlockSerializer < ActiveModel::Serializer
|
||||
attributes :id, :domain, :created_at, :severity,
|
||||
:reject_media, :reject_favourite, :reject_reply, :reject_reports,
|
||||
:reject_reply_exclude_followers, :reject_send_sensitive,
|
||||
:reject_reply_exclude_followers, :reject_send_sensitive, :block_trends,
|
||||
:reject_hashtag, :reject_straight_follow, :reject_new_follow, :reject_friend, :detect_invalid_subscription,
|
||||
:private_comment, :public_comment, :obfuscate
|
||||
|
||||
|
|
|
@ -30,3 +30,6 @@
|
|||
|
||||
.fields-group
|
||||
= f.input :reject_send_sensitive, as: :boolean, kmyblue: true, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_send_sensitive'), hint: I18n.t('admin.domain_blocks.reject_send_sensitive_hint')
|
||||
|
||||
.fields-group
|
||||
= f.input :block_trends, as: :boolean, kmyblue: true, wrapper: :with_label, label: I18n.t('admin.domain_blocks.block_trends'), hint: I18n.t('admin.domain_blocks.block_trends_hint')
|
||||
|
|
|
@ -397,6 +397,8 @@ en:
|
|||
undo: Disallow federation with domain
|
||||
domain_blocks:
|
||||
add_new: Add new domain block
|
||||
block_trends: Reject trends
|
||||
block_trends_hint: Reject trends in the future
|
||||
confirm_suspension:
|
||||
cancel: Cancel
|
||||
confirm: Suspend
|
||||
|
@ -416,7 +418,7 @@ en:
|
|||
existing_domain_block_html: You have already imposed stricter limits on %{name}, you need to <a href="%{unblock_url}">unblock it</a> first.
|
||||
export: Export
|
||||
headers:
|
||||
disagreement: Protect sensitive posts from political disagreement
|
||||
disagreement: Political disagreement
|
||||
harassment: Harassment or spam
|
||||
invalid_privacy: Privacy is not protected
|
||||
mastodon_default: Original Mastodon supports
|
||||
|
@ -558,6 +560,7 @@ en:
|
|||
description_html: You can define content policies that will be applied to all accounts from this domain and any of its subdomains.
|
||||
limited_federation_mode_description_html: You can chose whether to allow federation with this domain.
|
||||
policies:
|
||||
block_trends: Reject trends
|
||||
reject_favourite: Reject favorite
|
||||
reject_friend: Reject friend server application
|
||||
reject_hashtag: Reject hashtags
|
||||
|
|
|
@ -390,6 +390,8 @@ ja:
|
|||
undo: 連合許可を外す
|
||||
domain_blocks:
|
||||
add_new: ドメインブロックを追加
|
||||
block_trends: トレンド掲載を拒否
|
||||
block_trends_hint: 今後の投稿のトレンド掲載を拒否します。反映には時間がかかります。停止とは無関係です
|
||||
confirm_suspension:
|
||||
cancel: キャンセル
|
||||
confirm: 停止
|
||||
|
@ -409,7 +411,7 @@ ja:
|
|||
existing_domain_block_html: 既に%{name}に対して、より厳しい制限を課しています。先に<a href="%{unblock_url}">その制限を解除</a>する必要があります。
|
||||
export: エクスポート
|
||||
headers:
|
||||
disagreement: 政治的な意見の相違からの敏感な投稿の保護
|
||||
disagreement: 意見の相違
|
||||
harassment: 嫌がらせまたはスパム
|
||||
invalid_privacy: プライバシーが守られていない
|
||||
mastodon_default: 本家Mastodonの設定項目
|
||||
|
@ -550,6 +552,7 @@ ja:
|
|||
description_html: このドメインとそのサブドメインのすべてのアカウントに適用されるコンテンツポリシーを定義できます。
|
||||
limited_federation_mode_description_html: このドメインとの連合を許可するかどうかを選択できます。
|
||||
policies:
|
||||
block_trends: トレンドへの掲載を拒否
|
||||
detect_invalid_subscription: 購読のプライバシーなし
|
||||
reject_favourite: お気に入りを拒否
|
||||
reject_friend: フレンドサーバー申請を拒否
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddBlockTrendsToDomainBlocks < ActiveRecord::Migration[7.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_column :domain_blocks, :block_trends, :boolean, default: false, null: false
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_01_17_022353) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_01_21_231131) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
|
@ -574,6 +574,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_17_022353) do
|
|||
t.boolean "detect_invalid_subscription", default: false, null: false
|
||||
t.boolean "reject_reply_exclude_followers", default: false, null: false
|
||||
t.boolean "reject_friend", default: false, null: false
|
||||
t.boolean "block_trends", default: false, null: false
|
||||
t.index ["domain"], name: "index_domain_blocks_on_domain", unique: true
|
||||
end
|
||||
|
||||
|
|
|
@ -81,6 +81,7 @@ namespace :dangerous do
|
|||
20230222232121
|
||||
20240117021025
|
||||
20240117022353
|
||||
20240121231131
|
||||
)
|
||||
# Removed: account_groups
|
||||
target_tables = %w(
|
||||
|
@ -122,6 +123,7 @@ namespace :dangerous do
|
|||
%w(custom_filters exclude_follows),
|
||||
%w(custom_filters exclude_localusers),
|
||||
%w(custom_filters with_quote),
|
||||
%w(domain_blocks block_trends),
|
||||
%w(domain_blocks detect_invalid_subscription),
|
||||
%w(domain_blocks hidden),
|
||||
# Removed: domain_blocks hidden_anonymous
|
||||
|
|
|
@ -57,6 +57,29 @@ RSpec.describe Trends::Statuses do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#register for remote user' do
|
||||
let(:account) { Fabricate(:account, searchability: :public, discoverable: true, domain: 'example.com', uri: 'https://example.com/actor') }
|
||||
let(:status) { Fabricate(:status, account: account, searchability: :public, language: 'en') }
|
||||
let(:domain_block) { false }
|
||||
|
||||
before do
|
||||
Fabricate(:domain_block, domain: 'example.com', severity: :noop, block_trends: true) if domain_block
|
||||
subject.register(status, at_time)
|
||||
end
|
||||
|
||||
it 'records use' do
|
||||
expect(subject.send(:recently_used_ids, at_time)).to eq [status.id]
|
||||
end
|
||||
|
||||
context 'when domain-blocked' do
|
||||
let(:domain_block) { true }
|
||||
|
||||
it 'does not record use' do
|
||||
expect(subject.send(:recently_used_ids, at_time)).to eq []
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#query' do
|
||||
it 'returns a composable query scope' do
|
||||
expect(subject.query).to be_a Trends::Query
|
||||
|
|
|
@ -56,6 +56,7 @@ RSpec.describe 'Domain Blocks' do
|
|||
private_comment: domain_block.private_comment,
|
||||
public_comment: domain_block.public_comment,
|
||||
obfuscate: domain_block.obfuscate,
|
||||
block_trends: domain_block.block_trends,
|
||||
reject_favourite: domain_block.reject_favourite,
|
||||
reject_hashtag: domain_block.reject_hashtag,
|
||||
detect_invalid_subscription: domain_block.detect_invalid_subscription,
|
||||
|
@ -105,6 +106,7 @@ RSpec.describe 'Domain Blocks' do
|
|||
private_comment: domain_block.private_comment,
|
||||
public_comment: domain_block.public_comment,
|
||||
obfuscate: domain_block.obfuscate,
|
||||
block_trends: domain_block.block_trends,
|
||||
reject_favourite: domain_block.reject_favourite,
|
||||
reject_hashtag: domain_block.reject_hashtag,
|
||||
detect_invalid_subscription: domain_block.detect_invalid_subscription,
|
||||
|
@ -136,6 +138,7 @@ RSpec.describe 'Domain Blocks' do
|
|||
private_comment: domain_block.private_comment,
|
||||
public_comment: domain_block.public_comment,
|
||||
obfuscate: domain_block.obfuscate,
|
||||
block_trends: domain_block.block_trends,
|
||||
reject_favourite: domain_block.reject_favourite,
|
||||
reject_hashtag: domain_block.reject_hashtag,
|
||||
detect_invalid_subscription: domain_block.detect_invalid_subscription,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue