From c35c13ffba1408cf39295b5931b26da868b7bdf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KMY=EF=BC=88=E9=9B=AA=E3=81=82=E3=81=99=E3=81=8B=EF=BC=89?= Date: Sun, 18 Feb 2024 11:39:09 +0900 Subject: [PATCH] =?UTF-8?q?Add:=20=E3=83=AD=E3=83=BC=E3=82=AB=E3=83=AB?= =?UTF-8?q?=E3=81=8B=E3=82=89=E3=83=95=E3=82=A9=E3=83=AD=E3=83=BC=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84=E5=85=A8=E3=81=A6?= =?UTF-8?q?=E3=81=AE=E3=82=A2=E3=82=AB=E3=82=A6=E3=83=B3=E3=83=88=E3=81=8B?= =?UTF-8?q?=E3=82=89=E3=81=AE=E3=83=95=E3=82=A9=E3=83=AD=E3=83=BC=E3=82=92?= =?UTF-8?q?=E6=8B=92=E5=90=A6=E3=81=99=E3=82=8B=E8=A8=AD=E5=AE=9A=20(#592)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add: ローカルからフォローされていない全てのアカウントからのフォローを拒否する設定 * Fix test * Fix test --- .../features/list_adder/components/list.jsx | 2 +- .../mastodon/features/list_timeline/index.jsx | 2 +- app/lib/activitypub/activity/create.rb | 5 +++ app/models/form/admin_settings.rb | 2 + app/views/admin/ng_words/show.html.haml | 3 ++ config/locales/en.yml | 1 + config/locales/ja.yml | 1 + spec/lib/activitypub/activity/create_spec.rb | 44 +++++++++++++++++++ 8 files changed, 58 insertions(+), 2 deletions(-) diff --git a/app/javascript/mastodon/features/list_adder/components/list.jsx b/app/javascript/mastodon/features/list_adder/components/list.jsx index 0c303f1fae..1cb0d50d17 100644 --- a/app/javascript/mastodon/features/list_adder/components/list.jsx +++ b/app/javascript/mastodon/features/list_adder/components/list.jsx @@ -20,7 +20,7 @@ import { IconButton } from '../../../components/icon_button'; const messages = defineMessages({ remove: { id: 'lists.account.remove', defaultMessage: 'Remove from list' }, add: { id: 'lists.account.add', defaultMessage: 'Add to list' }, - exclusive: { id: 'lists.exclusive', defaultMessage: 'Exclusive from home' }, + exclusive: { id: 'lists.exclusive', defaultMessage: 'Hide list or antenna account posts from home' }, }); const MapStateToProps = (state, { listId, added }) => ({ diff --git a/app/javascript/mastodon/features/list_timeline/index.jsx b/app/javascript/mastodon/features/list_timeline/index.jsx index d7af83a49f..8be3350edb 100644 --- a/app/javascript/mastodon/features/list_timeline/index.jsx +++ b/app/javascript/mastodon/features/list_timeline/index.jsx @@ -221,7 +221,7 @@ class ListTimeline extends PureComponent {
diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index 6dbe72a871..21646524ea 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -149,6 +149,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity valid = !Admin::NgWord.mention_reject?(@raw_mention_uris.size, uri: @params[:uri], target_type: :status, public: @status_parser.distributable_visibility?, text: "#{@params[:spoiler_text]}\n#{@params[:text]}") if valid valid = !Admin::NgWord.stranger_mention_reject_with_count?(@raw_mention_uris.size, uri: @params[:uri], target_type: :status, public: @status_parser.distributable_visibility?, text: "#{@params[:spoiler_text]}\n#{@params[:text]}") if valid && (mention_to_local_stranger? || reference_to_local_stranger?) valid = !Admin::NgWord.stranger_mention_reject?("#{@params[:spoiler_text]}\n#{@params[:text]}", uri: @params[:uri], target_type: :status, public: @status_parser.distributable_visibility?) if valid && (mention_to_local_stranger? || reference_to_local_stranger?) + valid = false if valid && Setting.block_unfollow_account_mention && (mention_to_local_stranger? || reference_to_local_stranger?) && !local_following_sender? valid end @@ -486,6 +487,10 @@ class ActivityPub::Activity::Create < ActivityPub::Activity @reject_reply_exclude_followers ||= DomainBlock.reject_reply_exclude_followers?(@account.domain) end + def local_following_sender? + ::Follow.exists?(account: Account.local, target_account: @account) + end + def ignore_hashtags? return @ignore_hashtags if defined?(@ignore_hashtags) diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index 08e580ea8e..99d738d348 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -65,6 +65,7 @@ class Form::AdminSettings enable_local_timeline emoji_reaction_disallow_domains permit_new_account_domains + block_unfollow_account_mention hold_remote_new_accounts ).freeze @@ -108,6 +109,7 @@ class Form::AdminSettings stranger_mention_from_local_ng enable_local_timeline delete_content_cache_without_reaction + block_unfollow_account_mention hold_remote_new_accounts ).freeze diff --git a/app/views/admin/ng_words/show.html.haml b/app/views/admin/ng_words/show.html.haml index 9115237e86..7b76fe92da 100644 --- a/app/views/admin/ng_words/show.html.haml +++ b/app/views/admin/ng_words/show.html.haml @@ -32,6 +32,9 @@ .fields-group = f.input :hide_local_users_for_anonymous, wrapper: :with_label, as: :boolean, label: t('admin.ng_words.hide_local_users_for_anonymous') + .fields-group + = f.input :block_unfollow_account_mention, wrapper: :with_label, as: :boolean, label: t('admin.ng_words.block_unfollow_account_mention') + %p.hint = t 'admin.ng_words.remote_approval_hint' = link_to t('admin.ng_words.remote_approval_list'), admin_accounts_path(status: 'remote_pending', origin: 'remote') diff --git a/config/locales/en.yml b/config/locales/en.yml index 4d6b67f875..8a5e5a4a3a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -648,6 +648,7 @@ en: media_attachments: title: Media attachments ng_words: + block_unfollow_account_mention: Reject all mentions/references from all accounts that do not have followers on your server hide_local_users_for_anonymous: Hide timeline local user posts from anonymous history_hint: We recommend that you regularly check your NG words to make sure that you have not specified the NG words incorrectly. hold_remote_new_accounts: Hold new remote accounts diff --git a/config/locales/ja.yml b/config/locales/ja.yml index bf2c8b6088..d49383038b 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -641,6 +641,7 @@ ja: media_attachments: title: 投稿された画像 ng_words: + block_unfollow_account_mention: 自分のサーバーのフォロワーを持たない全てのアカウントからのメンション・参照を全て拒否する hide_local_users_for_anonymous: ログインしていない状態でローカルユーザーの投稿をタイムラインから取得できないようにする history_hint: 設定されたNGワードによって実際に拒否された投稿などは、履歴より確認できます。NGワードの指定に誤りがないか定期的に確認することをおすすめします。 hold_remote_new_accounts: リモートの新規アカウントを保留する diff --git a/spec/lib/activitypub/activity/create_spec.rb b/spec/lib/activitypub/activity/create_spec.rb index 25798df570..e1103e3397 100644 --- a/spec/lib/activitypub/activity/create_spec.rb +++ b/spec/lib/activitypub/activity/create_spec.rb @@ -2219,6 +2219,50 @@ RSpec.describe ActivityPub::Activity::Create do end end end + + context 'when stranger mention for domain' do + let(:object_json) do + { + id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, + type: 'Note', + content: 'Lorem ipsum', + to: 'https://www.w3.org/ns/activitystreams#Public', + tag: [ + { + type: 'Mention', + href: ActivityPub::TagManager.instance.uri_for(Fabricate(:account)), + }, + ], + } + end + + context 'when the domain does not have follower' do + let(:custom_before) { true } + + before do + Setting.block_unfollow_account_mention = true + subject.perform + end + + it 'creates status' do + expect(sender.statuses.first).to be_nil + end + end + + context 'when other account following' do + let(:custom_before) { true } + + before do + Setting.block_unfollow_account_mention = true + Fabricate(:account).follow!(sender) + subject.perform + end + + it 'creates status' do + expect(sender.statuses.first).to_not be_nil + end + end + end end context 'when object URI uses bearcaps' do