1
0
Fork 0
forked from gitea/nas

Merge branch 'kb_development' into kb_migration

This commit is contained in:
KMY 2023-08-11 11:04:20 +09:00
commit aa248c6812
8 changed files with 146 additions and 9 deletions

View file

@ -507,11 +507,22 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
SCAN_SEARCHABILITY_FEDIBIRD_RE = /searchable_by_(all_users|followers_only|reacted_users_only|nobody)/
def searchability
searchability_from_audience || searchability_from_bio || (misskey_software? ? misskey_searchability : nil)
from_audience = searchability_from_audience
return from_audience if from_audience
return nil if default_searchability_from_bio?
searchability_from_bio || (misskey_software? ? misskey_searchability : nil)
end
def default_searchability_from_bio?
note = @account.note
return false if note.blank?
note.include?('searchable_by_default_range')
end
def searchability_from_bio
note = @account&.note
note = @account.note
return nil if note.blank?
searchability_bio = note.scan(SCAN_SEARCHABILITY_FEDIBIRD_RE).first || note.scan(SCAN_SEARCHABILITY_RE).first

View file

@ -42,6 +42,7 @@ en:
current_username: To confirm, please enter the username of the current account
digest: Only sent after a long period of inactivity and only if you have received any personal messages in your absence
discoverable: Allow your account to be discovered by strangers through recommendations, trends and other features
discoverable_local: Disable the setting on federated servers. The setting is available this server only for avoiding full-text search on other servers
dissubscribable: Your post is not picked by antenna
email: You will be sent a confirmation e-mail
group: Reps sent to this account will be automatically BT'd and distributed to all accounts you follow!
@ -184,6 +185,7 @@ en:
current_password: Current password
data: Data
discoverable: Suggest account to others
discoverable_local: Disallow suggesting account on other servers
display_name: Display name
dissubscribable: Reject any subscriptions
email: E-mail address

View file

@ -40,8 +40,8 @@ ja:
current_password: 現在のアカウントのパスワードを入力してください
current_username: 確認のため、現在のアカウントのユーザー名を入力してください
digest: 長期間使用していない場合と不在時に返信を受けた場合のみ送信されます
discoverable: レコメンド、トレンド、その他の機能により、あなたのアカウントを他の人から見つけられるようにします
discoverable_local: 上記設定を当サーバー内でのみ適用するようにします
discoverable: レコメンド、トレンド、その他の機能により、あなたのアカウントを他の人から見つけられるようにします。なおkmyblueのローカルユーザーはこの設定をオンにしても全文検索結果には掲載されません。全文検索結果への掲載には、投稿の検索許可設定を変更する必要があります
discoverable_local: 上記設定を当サーバー内でのみ適用するようにします。他のサーバーの全文検索結果への掲載を回避できますが、レコメンド、トレンドなどその他の機能への掲載も回避されます
dissubscribable: あなたの投稿はすべてのアンテナに掲載されなくなります。Misskeyのアンテナを拒否することはできません。Mastodonの一部のサーバーもこの設定に対応しますが、挙動が一部kmyblueと異なる場合があります
email: 確認のメールが送信されます
group: このアカウントに送られたメンションは自動でBTされ、フォローしている全てのアカウントに配信されます

View file

@ -0,0 +1,75 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Timelines::PublicController do
render_views
let!(:account) { Fabricate(:account) }
let!(:user) { Fabricate(:user, account: account) }
let!(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') }
before do
allow(controller).to receive(:doorkeeper_token) { token }
end
describe 'GET #show' do
subject do
get :show
body_as_json
end
let!(:local_account) { Fabricate(:account, domain: nil) }
let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
let!(:local_status) { Fabricate(:status, account: local_account, text: 'ohagi is good') }
let!(:remote_status) { Fabricate(:status, account: remote_account, text: 'ohagi is ohagi') }
it 'load statuses', :aggregate_failures do
json = subject
expect(response).to have_http_status(200)
expect(json).to be_an Array
expect(json.any? { |status| status[:id] == local_status.id.to_s }).to be true
expect(json.any? { |status| status[:id] == remote_status.id.to_s }).to be true
end
context 'with filter' do
subject do
Fabricate(:follow, account: account, target_account: remote_account)
get :show
body_as_json.filter { |status| status[:filtered].empty? || status[:filtered][0][:filter][:id] != filter.id.to_s }.map { |status| status[:id].to_i }
end
let(:exclude_follows) { false }
let(:exclude_localusers) { false }
let!(:filter) { Fabricate(:custom_filter, account: account, exclude_follows: exclude_follows, exclude_localusers: exclude_localusers) }
let!(:filter_keyword) { Fabricate(:custom_filter_keyword, custom_filter: filter, keyword: 'ohagi') } # rubocop:disable RSpec/LetSetup
it 'load statuses', :aggregate_failures do
ids = subject
expect(ids).to exclude(local_status.id)
expect(ids).to exclude(remote_status.id)
end
context 'when exclude_followers' do
let(:exclude_follows) { true }
it 'load statuses', :aggregate_failures do
ids = subject
expect(ids).to exclude(local_status.id)
expect(ids).to include(remote_status.id)
end
end
context 'when exclude_localusers' do
let(:exclude_localusers) { true }
it 'load statuses', :aggregate_failures do
ids = subject
expect(ids).to include(local_status.id)
expect(ids).to exclude(remote_status.id)
end
end
end
end
end

View file

@ -5,4 +5,6 @@ Fabricator(:custom_filter) do
expires_at nil
phrase 'discourse'
context %w(home notifications)
exclude_follows false
exclude_localusers false
end

View file

@ -178,6 +178,26 @@ RSpec.describe Status do
expect(subject.compute_searchability).to eq 'public'
end
end
context 'when direct-public of local account' do
let(:account_searchability) { :direct }
let(:account_domain) { nil }
let(:status_searchability) { :public }
it 'returns public' do
expect(subject.compute_searchability).to eq 'public'
end
end
context 'when limited-public of local account' do
let(:account_searchability) { :limited }
let(:account_domain) { nil }
let(:status_searchability) { :public }
it 'returns public' do
expect(subject.compute_searchability).to eq 'public'
end
end
end
describe '#content' do

View file

@ -47,7 +47,16 @@ RSpec.describe 'Filters' do
it_behaves_like 'unauthorized for invalid token'
context 'with valid params' do
let(:params) { { title: 'magic', context: %w(home), filter_action: 'hide', keywords_attributes: [keyword: 'magic', whole_word: true] } }
let(:params) do
{
title: 'magic',
context: %w(home),
filter_action: 'hide',
exclude_follows: true,
exclude_localusers: true,
keywords_attributes: [keyword: 'magic', whole_word: true],
}
end
it 'returns http success' do
subject
@ -64,6 +73,8 @@ RSpec.describe 'Filters' do
expect(json[:filter_action]).to eq 'hide'
expect(json[:context]).to eq ['home']
expect(json[:keywords].map { |keyword| keyword.slice(:keyword, :whole_word) }).to eq [{ keyword: 'magic', whole_word: true }]
expect(json[:exclude_follows]).to be true
expect(json[:exclude_localusers]).to be true
end
it 'creates a filter', :aggregate_failures do
@ -74,13 +85,15 @@ RSpec.describe 'Filters' do
expect(filter).to be_present
expect(filter.keywords.pluck(:keyword)).to eq ['magic']
expect(filter.context).to eq %w(home)
expect(filter.exclude_follows).to be true
expect(filter.exclude_localusers).to be true
expect(filter.irreversible?).to be true
expect(filter.expires_at).to be_nil
end
end
context 'when the required title param is missing' do
let(:params) { { context: %w(home), filter_action: 'hide', keywords_attributes: [keyword: 'magic'] } }
let(:params) { { context: %w(home), filter_action: 'hide', keywords_attributes: [keyword: 'magic'], exclude_follows: false, exclude_localusers: false } }
it 'returns http unprocessable entity' do
subject
@ -90,7 +103,7 @@ RSpec.describe 'Filters' do
end
context 'when the required context param is missing' do
let(:params) { { title: 'magic', filter_action: 'hide', keywords_attributes: [keyword: 'magic'] } }
let(:params) { { title: 'magic', filter_action: 'hide', keywords_attributes: [keyword: 'magic'], exclude_follows: false, exclude_localusers: false } }
it 'returns http unprocessable entity' do
subject
@ -99,8 +112,18 @@ RSpec.describe 'Filters' do
end
end
context 'when the required kmyblue original params are missing' do
let(:params) { { title: 'magic', context: %w(home), filter_action: 'hide', keywords_attributes: [keyword: 'magic'] } }
it 'returns http success' do
subject
expect(response).to have_http_status(200)
end
end
context 'when the given context value is invalid' do
let(:params) { { title: 'magic', context: %w(shaolin), filter_action: 'hide', keywords_attributes: [keyword: 'magic'] } }
let(:params) { { title: 'magic', context: %w(shaolin), filter_action: 'hide', keywords_attributes: [keyword: 'magic'], exclude_follows: false, exclude_localusers: false } }
it 'returns http unprocessable entity' do
subject
@ -152,7 +175,7 @@ RSpec.describe 'Filters' do
context 'when updating filter parameters' do
context 'with valid params' do
let(:params) { { title: 'updated', context: %w(home public) } }
let(:params) { { title: 'updated', context: %w(home public), exclude_follows: true, exclude_localusers: true } }
it 'updates the filter successfully', :aggregate_failures do
subject
@ -162,6 +185,8 @@ RSpec.describe 'Filters' do
expect(response).to have_http_status(200)
expect(filter.title).to eq 'updated'
expect(filter.reload.context).to eq %w(home public)
expect(filter.exclude_follows).to be true
expect(filter.exclude_localusers).to be true
end
end

View file

@ -2,6 +2,8 @@
require 'rspec/retry'
RSpec::Matchers.define_negated_matcher :exclude, :include
if ENV['DISABLE_SIMPLECOV'] != 'true'
require 'simplecov'
SimpleCov.start 'rails' do