Skip to content

Commit

Permalink
Fix: kokonect-link#449 で変えた部分の修正3 (kokonect-link#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
penginn-net authored Oct 18, 2024
1 parent a64fc9f commit 747f162
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 19 deletions.
30 changes: 12 additions & 18 deletions packages/backend/src/core/AdvancedSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,9 @@ export class AdvancedSearchService {
Followings: string[],
followingFilter: string,
meUserId?: string ): Promise<OpenSearchHit| null> {
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;
Expand All @@ -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: {
Expand Down Expand Up @@ -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;
Expand Down
87 changes: 86 additions & 1 deletion packages/backend/test/e2e/search-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down Expand Up @@ -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);
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -245,6 +329,7 @@ describe('検索', () => {
assert.strictEqual(Array.isArray(asres0.body), true);
assert.strictEqual(asres0.body.length, 0);
});

/*
DB検索では未実装 別PRで出す
test('センシティブオプション:含む', async() => {
Expand Down

0 comments on commit 747f162

Please sign in to comment.