summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/RoleService.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-07-20 10:54:41 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2023-07-20 10:54:41 +0900
commit871027fa0cd2bd92411108f069eec0b188cc19ae (patch)
treee55ea8d558e84c35a7f58074134e9f0e19008ab0 /packages/backend/src/core/RoleService.ts
parentuse storybook 7.0.27 (diff)
downloadsharkey-871027fa0cd2bd92411108f069eec0b188cc19ae.tar.gz
sharkey-871027fa0cd2bd92411108f069eec0b188cc19ae.tar.bz2
sharkey-871027fa0cd2bd92411108f069eec0b188cc19ae.zip
enhance: ユーザーにロールが期限付きでアサインされている場合、その期限をユーザーのモデレーションページで確認できるように
Close #11059
Diffstat (limited to 'packages/backend/src/core/RoleService.ts')
-rw-r--r--packages/backend/src/core/RoleService.ts11
1 files changed, 8 insertions, 3 deletions
diff --git a/packages/backend/src/core/RoleService.ts b/packages/backend/src/core/RoleService.ts
index 3b501cf8d7..d065b460c6 100644
--- a/packages/backend/src/core/RoleService.ts
+++ b/packages/backend/src/core/RoleService.ts
@@ -220,14 +220,19 @@ export class RoleService implements OnApplicationShutdown {
}
@bindThis
- public async getUserRoles(userId: User['id']) {
+ public async getUserAssigns(userId: User['id']) {
const now = Date.now();
let assigns = await this.roleAssignmentByUserIdCache.fetch(userId, () => this.roleAssignmentsRepository.findBy({ userId }));
// 期限切れのロールを除外
assigns = assigns.filter(a => a.expiresAt == null || (a.expiresAt.getTime() > now));
- const assignedRoleIds = assigns.map(x => x.roleId);
+ return assigns;
+ }
+
+ @bindThis
+ public async getUserRoles(userId: User['id']) {
const roles = await this.rolesCache.fetch(() => this.rolesRepository.findBy({}));
- const assignedRoles = roles.filter(r => assignedRoleIds.includes(r.id));
+ const assigns = await this.getUserAssigns(userId);
+ const assignedRoles = roles.filter(r => assigns.map(x => x.roleId).includes(r.id));
const user = roles.some(r => r.target === 'conditional') ? await this.cacheService.findUserById(userId) : null;
const matchedCondRoles = roles.filter(r => r.target === 'conditional' && this.evalCond(user!, r.condFormula));
return [...assignedRoles, ...matchedCondRoles];