From aa7ef78a7158e6aa21c593f5ef6c83ff7974429e Mon Sep 17 00:00:00 2001 From: KMY Date: Fri, 1 Mar 2024 09:19:41 +0900 Subject: [PATCH] =?UTF-8?q?Change:=20#556=20=E3=83=89=E3=83=A1=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=83=96=E3=83=AD=E3=83=83=E3=82=AF=E3=80=8C=E3=83=95?= =?UTF-8?q?=E3=82=A9=E3=83=AD=E3=83=BC=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=AA=E3=81=84=E7=9B=B8=E6=89=8B=E3=81=8B=E3=82=89=E3=81=AE?= =?UTF-8?q?=E3=83=AA=E3=83=97=E3=83=A9=E3=82=A4=E3=82=92=E6=8B=92=E5=90=A6?= =?UTF-8?q?=E3=80=8D=E3=81=AB=E3=80=81=E5=8F=82=E7=85=A7=E3=82=92=E5=90=AB?= =?UTF-8?q?=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process_status_update_service.rb | 20 ++++++++--- config/locales/en.yml | 4 +-- config/locales/ja.yml | 4 +-- .../process_status_update_service_spec.rb | 36 ++++++++++++++++++- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/app/services/activitypub/process_status_update_service.rb b/app/services/activitypub/process_status_update_service.rb index f174ae1575172e..d3f220cf57fc72 100644 --- a/app/services/activitypub/process_status_update_service.rb +++ b/app/services/activitypub/process_status_update_service.rb @@ -164,15 +164,16 @@ def update_poll!(allow_significant_changes: true) def valid_status? valid = !Admin::NgWord.reject?("#{@status_parser.spoiler_text}\n#{@status_parser.text}", uri: @status.uri, target_type: :status) valid = !Admin::NgWord.hashtag_reject?(@raw_tags.size) if valid + valid = false if valid && Admin::NgWord.mention_reject?(@raw_mentions.size, uri: @status.uri, target_type: :status, text: "#{@status_parser.spoiler_text}\n#{@status_parser.text}") + valid = false if valid && (mention_to_local_stranger? || reference_to_local_stranger?) && Admin::NgWord.stranger_mention_reject?("#{@status_parser.spoiler_text}\n#{@status_parser.text}", uri: @status.uri, target_type: :status) + valid = false if valid && (mention_to_local_stranger? || reference_to_local_stranger?) && Admin::NgWord.stranger_mention_reject_with_count?(@raw_mentions.size, uri: @status.uri, target_type: :status, text: "#{@status_parser.spoiler_text}\n#{@status_parser.text}") + valid = false if valid && (mention_to_local_stranger? || reference_to_local_stranger?) && reject_reply_exclude_followers? valid end def validate_status_mentions! raise AbortError unless valid_status_for_ng_rule? - raise AbortError if (mention_to_local_stranger? || reference_to_local_stranger?) && Admin::NgWord.stranger_mention_reject?("#{@status_parser.spoiler_text}\n#{@status_parser.text}", uri: @status.uri, target_type: :status) - raise AbortError if Admin::NgWord.mention_reject?(@raw_mentions.size, uri: @status.uri, target_type: :status, text: "#{@status_parser.spoiler_text}\n#{@status_parser.text}") - raise AbortError if (mention_to_local_stranger? || reference_to_local_stranger?) && Admin::NgWord.stranger_mention_reject_with_count?(@raw_mentions.size, uri: @status.uri, target_type: :status, text: "#{@status_parser.spoiler_text}\n#{@status_parser.text}") end def valid_status_for_ng_rule? @@ -196,8 +197,11 @@ def valid_status_for_ng_rule? end def mention_to_local_stranger? - @status.mentions.map(&:account).to_a.any? { |mentioned_account| mentioned_account.id != @status.account.id && mentioned_account.local? && !mentioned_account.following?(@status.account) } || - (@status.thread.present? && @status.thread.account.id != @status.account.id && @status.thread.account.local? && !@status.thread.account.following?(@status.account)) + return @mention_to_local_stranger if defined?(@mention_to_local_stranger) + + @mention_to_local_stranger = @raw_mentions.filter_map { |uri| ActivityPub::TagManager.instance.local_uri?(uri) && ActivityPub::TagManager.instance.uri_to_resource(uri, Account) }.any? { |mentioned_account| !mentioned_account.following?(@status.account) } + @mention_to_local_stranger ||= @status.thread.present? && @status.thread.account_id != @status.account_id && @status.thread.account.local? && !@status.thread.account.following?(@status.account) + @mention_to_local_stranger end def reference_to_local_stranger? @@ -365,6 +369,12 @@ def ignore_hashtags? @ignore_hashtags ||= DomainBlock.reject_hashtag?(@account.domain) end + def reject_reply_exclude_followers? + return @reject_reply_exclude_followers if defined?(@reject_reply_exclude_followers) + + @reject_reply_exclude_followers ||= DomainBlock.reject_reply_exclude_followers?(@account.domain) + end + def unsupported_media_type?(mime_type) mime_type.present? && !MediaAttachment.supported_mime_types.include?(mime_type) end diff --git a/config/locales/en.yml b/config/locales/en.yml index 7bf22c1ea27860..3e2645b86bbb96 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -458,7 +458,7 @@ 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_exclude_followers: Reject mentions/references 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 @@ -575,7 +575,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_reply_exclude_followers: Reject reply/reference exclude followers reject_reports: Reject reports silence: Limit suspend: Suspend diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 005217f1acdc04..666b8efb679c82 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -453,7 +453,7 @@ ja: reject_new_follow: 新規フォローを拒否 reject_new_follow_hint: 今後の新規フォローを拒否します。停止とは無関係です reject_reply: リプライを拒否 - reject_reply_exclude_followers: フォロー相手以外からのリプライを拒否 + reject_reply_exclude_followers: フォロー相手以外からのメンションと参照を拒否 reject_reply_hint: 今後のリプライを拒否します。停止とは無関係です reject_reply_exclude_followers_hint: 今後のリプライを拒否します。停止とは無関係です reject_reports: 通報を拒否 @@ -567,7 +567,7 @@ ja: reject_media: メディアを拒否する reject_new_follow: 新規フォローを拒否 reject_reply: リプライを拒否 - reject_reply_exclude_followers: フォロー相手以外からのリプライを拒否 + reject_reply_exclude_followers: フォロー相手以外からのメンション・参照を拒否 reject_reports: 通報を拒否 reject_send_sensitive: センシティブ投稿配送なし reject_straight_follow: フォローを制限 diff --git a/spec/services/activitypub/process_status_update_service_spec.rb b/spec/services/activitypub/process_status_update_service_spec.rb index 9a02b500d2d62a..13b93a8acfaff6 100644 --- a/spec/services/activitypub/process_status_update_service_spec.rb +++ b/spec/services/activitypub/process_status_update_service_spec.rb @@ -325,6 +325,31 @@ def poll_option_json(name, votes) end end + context 'when reject mentions to stranger by domain-block' do + let(:json_tags) do + [ + { type: 'Mention', href: ActivityPub::TagManager.instance.uri_for(alice) }, + ] + end + + before do + Fabricate(:domain_block, domain: 'example.com', reject_reply_exclude_followers: true, severity: :noop) + end + + it 'updates mentions' do + subject.call(status, json, json) + + expect(status.mentions.reload.map(&:account_id)).to eq [] + end + + it 'updates mentions when follower' do + alice.follow!(status.account) + subject.call(status, json, json) + + expect(status.mentions.reload.map(&:account_id)).to eq [alice.id] + end + end + context 'when originally without mentions' do before do subject.call(status, json, json) @@ -508,7 +533,7 @@ def poll_option_json(name, votes) end end - context 'when hit ng words for mention' do + context 'when hit ng words for mention to local stranger' do let(:json_tags) do [ { type: 'Mention', href: ActivityPub::TagManager.instance.uri_for(alice) }, @@ -523,6 +548,15 @@ def poll_option_json(name, votes) expect(status.reload.text).to_not eq content expect(status.mentioned_accounts.pluck(:id)).to_not include alice.id end + + it 'update status when following' do + Form::AdminSettings.new(ng_words_for_stranger_mention: 'test', stranger_mention_from_local_ng: '1').save + alice.follow!(status.account) + + subject.call(status, json, json) + expect(status.reload.text).to eq content + expect(status.mentioned_accounts.pluck(:id)).to include alice.id + end end context 'when hit ng words for mention but local posts are not checked' do