refactor: enhance user permission checks and streamline access evaluation logic#1678
Merged
refactor: enhance user permission checks and streamline access evaluation logic#1678
Conversation
Contributor
There was a problem hiding this comment.
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) vialoadContext()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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.