From 747f16248085ab90047b85cc1d5c725c0e10e18c Mon Sep 17 00:00:00 2001 From: pen <121443048+penginn-net@users.noreply.github.com> Date: Sat, 19 Oct 2024 00:09:50 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20#449=20=E3=81=A7=E5=A4=89=E3=81=88?= =?UTF-8?q?=E3=81=9F=E9=83=A8=E5=88=86=E3=81=AE=E4=BF=AE=E6=AD=A33=20(#507?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/src/core/AdvancedSearchService.ts | 30 +++---- packages/backend/test/e2e/search-notes.ts | 87 ++++++++++++++++++- 2 files changed, 98 insertions(+), 19 deletions(-) diff --git a/packages/backend/src/core/AdvancedSearchService.ts b/packages/backend/src/core/AdvancedSearchService.ts index 06de298869..1c2c834221 100644 --- a/packages/backend/src/core/AdvancedSearchService.ts +++ b/packages/backend/src/core/AdvancedSearchService.ts @@ -1103,7 +1103,9 @@ export class AdvancedSearchService { Followings: string[], followingFilter: string, meUserId?: string ): Promise { - if (meUserId) {//ミュートしているか、ブロックされている + if (meUserId) { + if (Note._source.userId === meUserId) return Note;//自分のノート + //ミュートしているか、ブロックされている if (Filter.includes(Note._source.userId) ) return null; if (Note._source.referenceUserId) { if (Filter.includes(Note._source.referenceUserId)) return null; @@ -1114,9 +1116,10 @@ export class AdvancedSearchService { const user = await this.cacheService.findUserById(Note._source.userId); if (user.isIndexable === false && meUserId !== undefined && user.id !== meUserId) { //検索許可されていないが、 - if (!meUserId || !this.opensearch) { - return null; - } + if (!this.opensearch) return null; + if (Note._source.visibility === 'followers' && !Followings.includes(Note._source.userId)) return null;//鍵でフォローしてない + if (Note._source.visibility === 'specified' && Note._source.visibleUserIds && !Note._source.visibleUserIds.includes(meUserId)) return null; //ダイレクトで自分が宛先に含まれていない + const Option = { index: this.reactionIndex, body: { @@ -1176,21 +1179,12 @@ export class AdvancedSearchService { } return null; - } - - if (['public', 'home'].includes(Note._source.visibility)) return Note;//誰でも見れる - - if (meUserId) { - if (Note._source.visibility === 'followers') { //鍵だけどフォローしてる - if (Followings.includes(Note._source.userId)) return Note; - if (Note._source.userId === meUserId) return Note;//または自分 - } + } else { + if (['public', 'home'].includes(Note._source.visibility)) return Note;//誰でも見れる - if (Note._source.visibility === 'specified') {//自分が宛先に含まれている - if (Note._source.visibleUserIds) { - if (Note._source.visibleUserIds.includes(meUserId)) return Note; - if (Note._source.userId === meUserId) return Note;//または自分 - } + if (meUserId) { + if (Note._source.visibility === 'followers' && Followings.includes(Note._source.userId)) return Note;//鍵だけどフォローしてる + if (Note._source.visibility === 'specified' && Note._source.visibleUserIds && Note._source.visibleUserIds.includes(meUserId)) return Note;//自分が宛先に含まれている } } return null; diff --git a/packages/backend/test/e2e/search-notes.ts b/packages/backend/test/e2e/search-notes.ts index 6ca32498dd..04b7df08f6 100644 --- a/packages/backend/test/e2e/search-notes.ts +++ b/packages/backend/test/e2e/search-notes.ts @@ -150,6 +150,11 @@ describe('検索', () => { roleId: roleres.body.id, }, root); assert.strictEqual(assign.status, 204); + const assign2 = await api('admin/roles/assign', { + userId: bob.id, + roleId: roleres.body.id, + }, root); + assert.strictEqual(assign2.status, 204); }); test('ファイルオプション:フィルタなし', async() => { const res = await api('notes/advanced-search', { @@ -215,7 +220,15 @@ describe('検索', () => { assert.strictEqual(Array.isArray(res.body), true); assert.strictEqual(res.body.length, 3); }); - test('可視性 followers, specified', async() => { + test('可視性 followers, specified でてこない', async() => { + const asres0 = await api('notes/advanced-search', { + query: 'ff_test', + }, bob); + assert.strictEqual(asres0.status, 200); + assert.strictEqual(Array.isArray(asres0.body), true); + assert.strictEqual(asres0.body.length, 0); + }); + test('可視性 followers, specified でてくる', async() => { const asres0 = await api('notes/advanced-search', { query: 'ff_test', }, alice); @@ -229,6 +242,67 @@ describe('検索', () => { assert.strictEqual(ids.includes(daveNoteDirect.id), false); assert.strictEqual(asres0.body.length, 2); }); + test('可視性 followers, specified indexable:falseでてこない', async() => { + const ires = await api('i/update', { + isIndexable: false, + }, tom); + assert.strictEqual(ires.status, 200); + const ires2 = await api('i/update', { + isIndexable: false, + }, dave); + assert.strictEqual(ires2.status, 200); + + const asres0 = await api('notes/advanced-search', { + query: 'ff_test', + }, bob); + assert.strictEqual(asres0.status, 200); + assert.strictEqual(Array.isArray(asres0.body), true); + assert.strictEqual(asres0.body.length, 0); + }); + test('可視性 followers, specified indexable:falseでてくる', async() => { + const rres = await api('notes/reactions/create', { + reaction: '❤', + noteId: tomNote.id, + }, alice); + assert.strictEqual(rres.status, 204); + const rres2 = await api('notes/reactions/create', { + reaction: '❤', + noteId: tomNoteDirect.id, + }, alice); + assert.strictEqual(rres2.status, 204); + await new Promise(resolve => setTimeout(resolve, 5000)); + + const asres0 = await api('notes/advanced-search', { + query: 'ff_test', + }, alice); + assert.strictEqual(asres0.status, 200); + assert.strictEqual(Array.isArray(asres0.body), true); + assert.strictEqual(asres0.body.length, 2); + + const ids = asres0.body.map((x) => x.id); + assert.strictEqual(ids.includes(tomNote.id), true); + assert.strictEqual(ids.includes(tomNoteDirect.id), true); + assert.strictEqual(ids.includes(daveNote.id), false); + assert.strictEqual(ids.includes(daveNoteDirect.id), false); + const ires = await api('i/update', { + isIndexable: true, + }, tom); + assert.strictEqual(ires.status, 200); + const ires2 = await api('i/update', { + isIndexable: true, + }, dave); + assert.strictEqual(ires2.status, 200); + }); + test('ミュートのノート普通に出る', async() => { + const asres0 = await api('notes/advanced-search', { + query: 'muting', + }, bob); + assert.strictEqual(asres0.status, 200); + assert.strictEqual(Array.isArray(asres0.body), true); + assert.strictEqual(asres0.body.length, 1); + const asnids0 = asres0.body.map( x => x.id); + assert.strictEqual(asnids0.includes(mutingNote.id), true); + }); test('ミュートしてたら出ない', async() => { const asres0 = await api('notes/advanced-search', { query: 'muting', @@ -237,6 +311,16 @@ describe('検索', () => { assert.strictEqual(Array.isArray(asres0.body), true); assert.strictEqual(asres0.body.length, 0); }); + test('ブロックのノート普通に出る', async() => { + const asres0 = await api('notes/advanced-search', { + query: 'blocking', + }, bob); + assert.strictEqual(asres0.status, 200); + assert.strictEqual(Array.isArray(asres0.body), true); + assert.strictEqual(asres0.body.length, 1); + const asnids0 = asres0.body.map( x => x.id); + assert.strictEqual(asnids0.includes(blockingNote.id), true); + }); test('ブロックされてたら出ない', async() => { const asres0 = await api('notes/advanced-search', { query: 'blocking', @@ -245,6 +329,7 @@ describe('検索', () => { assert.strictEqual(Array.isArray(asres0.body), true); assert.strictEqual(asres0.body.length, 0); }); + /* DB検索では未実装 別PRで出す test('センシティブオプション:含む', async() => {