Skip to content

refactor: enhance user permission checks and streamline access evaluation logic#1678

Merged
Artuomka merged 3 commits intomainfrom
backend_ceadr_as_default
Mar 19, 2026
Merged

refactor: enhance user permission checks and streamline access evaluation logic#1678
Artuomka merged 3 commits intomainfrom
backend_ceadr_as_default

Conversation

@Artuomka
Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings March 19, 2026 14:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors Cedar-based permission checks to reduce repeated DB/policy loading work and centralize table permission evaluation logic in CedarPermissionsService.

Changes:

  • Introduces a reusable evaluation context (EvalContext) via loadContext() to fetch user groups and Cedar policies once per check.
  • Reworks connection/group/table access checks to use evaluatePolicies() directly with shared entities/context.
  • Adds an in-memory suspension check cache and consolidates table permission evaluation in evaluateTablePermissions().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 282 to 289
@@ -208,59 +288,63 @@ export class CedarPermissionsService implements IUserAccessRepository {
return cachedReadPermission;
}
Comment on lines +387 to +403
private async assertUserNotSuspended(userId: string): Promise<void> {
const cached = this.suspendedCheckCache.get(userId);
if (cached !== undefined) {
if (cached) {
throw new HttpException({ message: Messages.ACCOUNT_SUSPENDED }, HttpStatus.FORBIDDEN);
}
return;
}

const user = await this.globalDbContext.userRepository.findOne({
where: { id: userId },
select: ['id', 'suspended'],
});
if (user?.suspended) {
throw new HttpException(
{
message: Messages.ACCOUNT_SUSPENDED,
},
HttpStatus.FORBIDDEN,
);
const isSuspended = !!user?.suspended;
this.suspendedCheckCache.set(userId, isSuspended);
if (isSuspended) {
throw new HttpException({ message: Messages.ACCOUNT_SUSPENDED }, HttpStatus.FORBIDDEN);
@Artuomka Artuomka merged commit b4dfb28 into main Mar 19, 2026
17 of 19 checks passed
@Artuomka Artuomka deleted the backend_ceadr_as_default branch March 19, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants