Skip to content

Commit

Permalink
Add: ローカルからフォローされていない全てのアカウントからのフォローを拒否する設定 (#592)
Browse files Browse the repository at this point in the history
* Add: ローカルからフォローされていない全てのアカウントからのフォローを拒否する設定

* Fix test

* Fix test
  • Loading branch information
kmycode authored Feb 18, 2024
1 parent 1efeedf commit c35c13f
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => ({
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/features/list_timeline/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class ListTimeline extends PureComponent {
<div className='setting-toggle'>
<Toggle id={`list-${id}-exclusive`} checked={isExclusive} onChange={this.onExclusiveToggle} />
<label htmlFor={`list-${id}-exclusive`} className='setting-toggle__label'>
<FormattedMessage id='lists.exclusive' defaultMessage='Hide these posts from home or STL' />
<FormattedMessage id='lists.exclusive' defaultMessage='Hide list or antenna account posts from home' />
</label>
</div>

Expand Down
5 changes: 5 additions & 0 deletions app/lib/activitypub/activity/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def valid_status?
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
Expand Down Expand Up @@ -486,6 +487,10 @@ def reject_reply_exclude_followers?
@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)

Expand Down
2 changes: 2 additions & 0 deletions app/models/form/admin_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/ng_words/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: リモートの新規アカウントを保留する
Expand Down
44 changes: 44 additions & 0 deletions spec/lib/activitypub/activity/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2219,6 +2219,50 @@ def activity_for_object(json)
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
Expand Down

0 comments on commit c35c13f

Please sign in to comment.