Skip to content

Commit 3a3057a

Browse files
fix(backend): RoleService.getAdministratorIds でユーザーIDが重複する問題を修正 (#17334)
* fix(backend): adminロールが複数付いてても通知が重複しないように * add tests * Update Changelog * ✌️ Co-Authored-by: lqvp <183242690+lqvp@users.noreply.github.com> --------- Co-authored-by: lqvp <183242690+lqvp@users.noreply.github.com>
1 parent 8a85ee1 commit 3a3057a

4 files changed

Lines changed: 17 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
- Fix: ID生成アルゴリズムにULIDを使用している場合にMisskeyが正しく動作しない問題を修正
2424
- Fix: リレー経由で届いたノートがリノートとして表示される問題を修正
2525
- Fix: robots.txtの内容を調整
26+
- Fix: 特定のユーザーに管理者権限を持つロールが複数ついている際に、取得できるユーザーIDが重複する問題を修正
27+
(Cherry-picked from https://github.com/lqvp/misskey-tempura/commit/17ed4108cec4b6bd2fd989db5a9091db91fa37a7)
2628

2729
## 2026.3.2
2830

packages/backend/src/core/RoleService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ export class RoleService implements OnApplicationShutdown, OnModuleInit {
533533
roleId: In(administratorRoles.map(r => r.id)),
534534
}) : [];
535535
// TODO: isRootなアカウントも含める
536-
return assigns.map(a => a.userId);
536+
// Setを経由して重複を除去(ユーザIDは重複する可能性があるので)
537+
return [...new Set(assigns.map(a => a.userId))].sort((x, y) => x.localeCompare(y));
537538
}
538539

539540
@bindThis

packages/backend/src/core/SignupService.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,3 @@ export class SignupService {
164164
return { account, secret };
165165
}
166166
}
167-

packages/backend/test/unit/RoleService.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,19 @@ describe('RoleService', () => {
696696
expect(adminIds).toHaveLength(0);
697697
});
698698

699+
test('should not include duplicate user IDs if a user has multiple administrator roles', async () => {
700+
const adminUser = await createUser();
701+
const adminRole1 = await createRole({ name: 'admin1', isAdministrator: true });
702+
const adminRole2 = await createRole({ name: 'admin2', isAdministrator: true });
703+
704+
await roleService.assign(adminUser.id, adminRole1.id);
705+
await roleService.assign(adminUser.id, adminRole2.id);
706+
707+
const adminIds = await roleService.getAdministratorIds();
708+
709+
expect(adminIds).toEqual([adminUser.id]);
710+
});
711+
699712
// TODO: rootユーザーは現在実装に含まれていないため、テストもそれに倣う
700713
test('should not include the root user', async () => {
701714
const rootUser = await createUser();

0 commit comments

Comments
 (0)