From 3b75ded25f65bb2e5bcc4e0c4b4286bb5529436c Mon Sep 17 00:00:00 2001 From: KMY Date: Wed, 17 May 2023 20:16:01 +0900 Subject: [PATCH] Add domainblocks to reject_reply_exclude_followers --- app/controllers/admin/domain_blocks_controller.rb | 6 +++--- .../api/v1/admin/domain_blocks_controller.rb | 4 ++-- app/lib/activitypub/activity/create.rb | 13 +++++++++++++ app/models/domain_block.rb | 10 ++++++++-- .../rest/admin/domain_block_serializer.rb | 2 +- app/views/admin/domain_blocks/edit.html.haml | 3 +++ app/views/admin/domain_blocks/new.html.haml | 3 +++ .../export_domain_blocks/_domain_block.html.haml | 1 + config/locales/en.yml | 3 +++ config/locales/ja.yml | 3 +++ ...ject_reply_exclude_followers_to_domain_blocks.rb | 8 ++++++++ db/schema.rb | 3 ++- 12 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 db/migrate/20230512122757_add_reject_reply_exclude_followers_to_domain_blocks.rb diff --git a/app/controllers/admin/domain_blocks_controller.rb b/app/controllers/admin/domain_blocks_controller.rb index 8a28410230..3c5b78e8b9 100644 --- a/app/controllers/admin/domain_blocks_controller.rb +++ b/app/controllers/admin/domain_blocks_controller.rb @@ -78,15 +78,15 @@ module Admin end def update_params - params.require(:domain_block).permit(:severity, :reject_media, :reject_favourite, :reject_reply, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous) + params.require(:domain_block).permit(:severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous) end def resource_params - params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous) + params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous) 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_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous]) + 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_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous]) 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 c2995902b9..209c896eb9 100644 --- a/app/controllers/api/v1/admin/domain_blocks_controller.rb +++ b/app/controllers/api/v1/admin/domain_blocks_controller.rb @@ -69,7 +69,7 @@ class Api::V1::Admin::DomainBlocksController < Api::BaseController end def domain_block_params - params.permit(:severity, :reject_media, :reject_favourite, :reject_reply, :reject_reports, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous) + params.permit(:severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_reports, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous) end def insert_pagination_headers @@ -101,6 +101,6 @@ class Api::V1::Admin::DomainBlocksController < Api::BaseController end def resource_params - params.permit(:domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous) + params.permit(:domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous) end end diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index c36e7edb8b..f110606bd3 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -47,6 +47,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity def create_status return reject_payload! if unsupported_object_type? || invalid_origin?(object_uri) || tombstone_exists? || !related_to_local_activity? return reject_payload! if (reply_to_local? || reply_to_local_account?) && reject_reply_to_local? + return reject_payload! if (!reply_to_local_account_following? || !reply_to_local_status_following?) && reject_reply_exclude_followers? with_lock("create:#{object_uri}") do return if delete_arrived_first?(object_uri) || poll_vote? @@ -141,6 +142,10 @@ class ActivityPub::Activity::Create < ActivityPub::Activity accounts_in_audience.any? { |account| account.local? } end + def reply_to_local_account_following? + !reply_to_local_account? || accounts_in_audience.none? { |account| account.local? && !account.following?(@account) } + end + def accounts_in_audience return @accounts_in_audience if @accounts_in_audience @@ -403,10 +408,18 @@ class ActivityPub::Activity::Create < ActivityPub::Activity !replied_to_status.nil? && replied_to_status.account.local? end + def reply_to_local_status_following? + !reply_to_local? || replied_to_status.account.following?(@account) + end + def reject_reply_to_local? @reject_reply_to_local ||= DomainBlock.reject_reply?(@account.domain) end + def reject_reply_exclude_followers? + @reject_reply_exclude_followers ||= DomainBlock.reject_reply_exclude_followers?(@account.domain) + end + def ignore_hashtags? @ignore_hashtags ||= DomainBlock.reject_hashtag?(@account.domain) end diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb index 512885ef27..98f78c3b86 100644 --- a/app/models/domain_block.rb +++ b/app/models/domain_block.rb @@ -27,6 +27,7 @@ # hidden :boolean default(FALSE), not null # hidden_anonymous :boolean default(FALSE), not null # detect_invalid_subscription :boolean default(FALSE), not null +# reject_reply_exclude_followers :boolean default(FALSE), not null # class DomainBlock < ApplicationRecord @@ -43,7 +44,7 @@ class DomainBlock < ApplicationRecord scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) } scope :with_user_facing_limitations, -> { where(hidden: false) } - scope :with_limitations, -> { where(severity: [:silence, :suspend]).or(where(reject_media: true)).or(where(reject_favourite: true)).or(where(reject_reply: true)).or(where(reject_new_follow: true)).or(where(reject_straight_follow: true)) } + scope :with_limitations, -> { where(severity: [:silence, :suspend]).or(where(reject_media: true)).or(where(reject_favourite: true)).or(where(reject_reply: true)).or(where(reject_reply_exclude_followers: true)).or(where(reject_new_follow: true)).or(where(reject_straight_follow: true)) } scope :by_severity, -> { order(Arel.sql('(CASE severity WHEN 0 THEN 1 WHEN 1 THEN 2 WHEN 2 THEN 0 END), domain')) } def to_log_human_identifier @@ -58,6 +59,7 @@ class DomainBlock < ApplicationRecord reject_media? ? :reject_media : nil, reject_favourite? ? :reject_favourite : nil, reject_reply? ? :reject_reply : nil, + reject_reply_exclude_followers? ? :reject_reply_exclude_followers : nil, reject_send_not_public_searchability? ? :reject_send_not_public_searchability : nil, reject_send_public_unlisted? ? :reject_send_public_unlisted : nil, reject_send_dissubscribable? ? :reject_send_dissubscribable : nil, @@ -93,6 +95,10 @@ class DomainBlock < ApplicationRecord !!rule_for(domain)&.reject_reply? end + def reject_reply_exclude_followers?(domain) + !!rule_for(domain)&.reject_reply_exclude_followers? + end + def reject_hashtag?(domain) !!rule_for(domain)&.reject_hashtag? end @@ -129,7 +135,7 @@ class DomainBlock < ApplicationRecord return false if other_block.suspend? && (silence? || noop?) return false if other_block.silence? && noop? - (reject_media || !other_block.reject_media) && (reject_reports || !other_block.reject_reports) + (reject_media || !other_block.reject_media) && (reject_favourite || !other_block.reject_favourite) && (reject_reply || !other_block.reject_reply) && (reject_reply_exclude_followers || !other_block.reject_reply_exclude_followers) && (reject_reports || !other_block.reject_reports) end def affected_accounts_count diff --git a/app/serializers/rest/admin/domain_block_serializer.rb b/app/serializers/rest/admin/domain_block_serializer.rb index 1177a23404..e7cdc40ad1 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_send_not_public_searchability, + :reject_send_not_public_searchability, :reject_reply_exclude_followers, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :private_comment, :public_comment, :obfuscate diff --git a/app/views/admin/domain_blocks/edit.html.haml b/app/views/admin/domain_blocks/edit.html.haml index b56237f618..380c6d001f 100644 --- a/app/views/admin/domain_blocks/edit.html.haml +++ b/app/views/admin/domain_blocks/edit.html.haml @@ -23,6 +23,9 @@ .fields-group = f.input :reject_reply, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reply'), hint: I18n.t('admin.domain_blocks.reject_reply_hint') + .fields-group + = f.input :reject_reply_exclude_followers, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reply_exclude_followers'), hint: I18n.t('admin.domain_blocks.reject_reply_exclude_followers_hint') + .fields-group = f.input :reject_send_not_public_searchability, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_send_not_public_searchability'), hint: I18n.t('admin.domain_blocks.reject_send_not_public_searchability_hint') diff --git a/app/views/admin/domain_blocks/new.html.haml b/app/views/admin/domain_blocks/new.html.haml index b34038d10d..264c514079 100644 --- a/app/views/admin/domain_blocks/new.html.haml +++ b/app/views/admin/domain_blocks/new.html.haml @@ -23,6 +23,9 @@ .fields-group = f.input :reject_reply, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reply'), hint: I18n.t('admin.domain_blocks.reject_reply_hint') + .fields-group + = f.input :reject_reply_exclude_followers, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reply_exclude_followers'), hint: I18n.t('admin.domain_blocks.reject_reply_exclude_followers_hint') + .fields-group = f.input :reject_send_not_public_searchability, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_send_not_public_searchability'), hint: I18n.t('admin.domain_blocks.reject_send_not_public_searchability_hint') diff --git a/app/views/admin/export_domain_blocks/_domain_block.html.haml b/app/views/admin/export_domain_blocks/_domain_block.html.haml index f38353aae5..2e1d68d0aa 100644 --- a/app/views/admin/export_domain_blocks/_domain_block.html.haml +++ b/app/views/admin/export_domain_blocks/_domain_block.html.haml @@ -12,6 +12,7 @@ = f.hidden_field :reject_media = f.hidden_field :reject_favourite = f.hidden_field :reject_reply + = f.hidden_field :reject_reply_exclude_followers = f.hidden_field :reject_send_not_public_searchability = f.hidden_field :reject_send_public_unlisted = f.hidden_field :reject_send_dissubscribable diff --git a/config/locales/en.yml b/config/locales/en.yml index 7b987dea20..571ee759c3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -423,7 +423,9 @@ en: reject_new_follow: Reject follows reject_new_follow_hint: Reject follows in the future reject_reply: Reject replies + reject_reply_exclude_followers: Reject replies exclude followers reject_reply_hint: Reject replies in the future + reject_reply_exclude_followers_hint: Reject replies exclude followers in the future reject_reports: Reject reports reject_reports_hint: Ignore all reports coming from this domain. Irrelevant for suspensions reject_send_dissubscribable: 購読拒否アカウントの投稿を配送しない @@ -513,6 +515,7 @@ en: reject_new_follow: Reject follows reject_straight_follow: Reject straight follow reject_reply: Reject reply + reject_reply_exclude_followers: Reject reply exclude followers reject_reports: Reject reports silence: Limit suspend: Suspend diff --git a/config/locales/ja.yml b/config/locales/ja.yml index e7a7a09b2c..be37e0cc35 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -420,7 +420,9 @@ ja: reject_new_follow: 新規フォローを拒否 reject_new_follow_hint: 今後の新規フォローを拒否します。停止とは無関係です reject_reply: リプライを拒否 + reject_reply_exclude_followers: フォロー相手以外からのリプライを拒否 reject_reply_hint: 今後のリプライを拒否します。停止とは無関係です + reject_reply_exclude_followers_hint: 今後のリプライを拒否します。停止とは無関係です reject_reports: 通報を拒否 reject_reports_hint: このドメインからの通報をすべて無視します。停止とは無関係です reject_send_dissubscribable: 購読拒否アカウントの投稿を配送しない @@ -507,6 +509,7 @@ ja: reject_media: メディアを拒否する reject_new_follow: 新規フォローを拒否 reject_reply: リプライを拒否 + reject_reply_exclude_followers: フォロー相手以外からのリプライを拒否 reject_reports: 通報を拒否 reject_send_dissubscribable: 購読拒否投稿配送なし reject_send_media: メディア付き投稿配送なし diff --git a/db/migrate/20230512122757_add_reject_reply_exclude_followers_to_domain_blocks.rb b/db/migrate/20230512122757_add_reject_reply_exclude_followers_to_domain_blocks.rb new file mode 100644 index 0000000000..fdac70a0a2 --- /dev/null +++ b/db/migrate/20230512122757_add_reject_reply_exclude_followers_to_domain_blocks.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class AddRejectReplyExcludeFollowersToDomainBlocks < ActiveRecord::Migration[6.1] + def change + add_column :domain_blocks, :reject_reply_exclude_followers, :boolean, null: false, default: false + add_index :domain_blocks, :reject_reply_exclude_followers + end +end diff --git a/db/schema.rb b/db/schema.rb index 50db1c205f..5ac3a3d7cc 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.define(version: 2023_05_09_045358) do +ActiveRecord::Schema.define(version: 2023_05_12_122757) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -482,6 +482,7 @@ ActiveRecord::Schema.define(version: 2023_05_09_045358) do t.boolean "hidden", default: false, null: false t.boolean "hidden_anonymous", default: false, null: false t.boolean "detect_invalid_subscription", default: false, null: false + t.boolean "reject_reply_exclude_followers", default: false, null: false t.index ["domain"], name: "index_domain_blocks_on_domain", unique: true end