diff --git a/CHANGELOG.md b/CHANGELOG.md index 6705535f0..bfd64a94b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,15 @@ You should also include the user name that made the change. --> + +## 13.x.x (unreleased) + +### Improvements +- コンディショナルロールもバッジとして表示可能に + +### Bugfixes +- + ## 13.5.6 (2023/02/10) ### Improvements diff --git a/packages/backend/src/core/RoleService.ts b/packages/backend/src/core/RoleService.ts index d15d8c0ae..9a782780d 100644 --- a/packages/backend/src/core/RoleService.ts +++ b/packages/backend/src/core/RoleService.ts @@ -211,8 +211,14 @@ export class RoleService implements OnApplicationShutdown { const assignedRoleIds = assigns.map(x => x.roleId); const roles = await this.rolesCache.fetch(null, () => this.rolesRepository.findBy({})); const assignedBadgeRoles = roles.filter(r => r.asBadge && assignedRoleIds.includes(r.id)); - // コンディショナルロールも含めるのは負荷高そうだから一旦無し - return assignedBadgeRoles; + const badgeCondRoles = roles.filter(r => r.asBadge && (r.target === 'conditional')); + if (badgeCondRoles.length > 0) { + const user = roles.some(r => r.target === 'conditional') ? await this.userCacheService.findById(userId) : null; + const matchedBadgeCondRoles = badgeCondRoles.filter(r => this.evalCond(user!, r.condFormula)); + return [...assignedBadgeRoles, ...matchedBadgeCondRoles]; + } else { + return assignedBadgeRoles; + } } @bindThis