diff --git a/app/controllers/admin/domain_blocks_controller.rb b/app/controllers/admin/domain_blocks_controller.rb index 987c82e7e3..deda7a7285 100644 --- a/app/controllers/admin/domain_blocks_controller.rb +++ b/app/controllers/admin/domain_blocks_controller.rb @@ -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 diff --git a/app/controllers/api/v1/admin/domain_blocks_controller.rb b/app/controllers/api/v1/admin/domain_blocks_controller.rb index c79a191407..45d4b598a7 100644 --- a/app/controllers/api/v1/admin/domain_blocks_controller.rb +++ b/app/controllers/api/v1/admin/domain_blocks_controller.rb @@ -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 diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb index a0d4f1afea..73c091e4aa 100644 --- a/app/models/domain_block.rb +++ b/app/models/domain_block.rb @@ -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 diff --git a/app/models/trends/statuses.rb b/app/models/trends/statuses.rb index c2e90bf7f6..d5fe55587f 100644 --- a/app/models/trends/statuses.rb +++ b/app/models/trends/statuses.rb @@ -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) diff --git a/app/serializers/rest/admin/domain_block_serializer.rb b/app/serializers/rest/admin/domain_block_serializer.rb index 73bc116c3d..77af88bfef 100644 --- a/app/serializers/rest/admin/domain_block_serializer.rb +++ b/app/serializers/rest/admin/domain_block_serializer.rb @@ -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 diff --git a/app/views/admin/domain_blocks/_domain_block_list.html.haml b/app/views/admin/domain_blocks/_domain_block_list.html.haml index 07c7253aca..135b8a0ba4 100644 --- a/app/views/admin/domain_blocks/_domain_block_list.html.haml +++ b/app/views/admin/domain_blocks/_domain_block_list.html.haml @@ -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') diff --git a/config/locales/en.yml b/config/locales/en.yml index 1bf5b051ae..6c4f4c0d66 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 unblock it 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 diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 714a8ad5bb..cb4713f0b9 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -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}に対して、より厳しい制限を課しています。先にその制限を解除する必要があります。 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: フレンドサーバー申請を拒否 diff --git a/db/migrate/20240121231131_add_block_trends_to_domain_blocks.rb b/db/migrate/20240121231131_add_block_trends_to_domain_blocks.rb new file mode 100644 index 0000000000..98c832dbd6 --- /dev/null +++ b/db/migrate/20240121231131_add_block_trends_to_domain_blocks.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 5bbcc29f37..1ba22b16a2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/lib/tasks/dangerous.rake b/lib/tasks/dangerous.rake index ebe3967e09..322b78885c 100644 --- a/lib/tasks/dangerous.rake +++ b/lib/tasks/dangerous.rake @@ -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 diff --git a/spec/models/trends/statuses_spec.rb b/spec/models/trends/statuses_spec.rb index 7c30b5b997..999c855867 100644 --- a/spec/models/trends/statuses_spec.rb +++ b/spec/models/trends/statuses_spec.rb @@ -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 diff --git a/spec/requests/api/v1/admin/domain_blocks_spec.rb b/spec/requests/api/v1/admin/domain_blocks_spec.rb index 6422404bd4..fa46dba71c 100644 --- a/spec/requests/api/v1/admin/domain_blocks_spec.rb +++ b/spec/requests/api/v1/admin/domain_blocks_spec.rb @@ -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,