Scope Ablity improvement

Whenever a user is created, we’re creating default roles like social, billing manager, and developer roles. I don’t think that’s necessary. If every user gets all roles by default, then assigning roles per user becomes redundant. Removing this can improve the overall codebase.

The reason we added those default roles was to ensure all users can pass the ScopeAbilityGuard, since having the role allows access. But that guard is meant to be used in organization context mode, where it checks if the user has a role within a specific organization.

Instead, we can keep the guard and update our logic to check request.params.id. If that ID is not defined and the user is not in organization mode, we can simply return true, instead of checking whether the user has roles like Social, Billing Manager, or Developer which is unnecessary if everyone has them by default.

this will improve performance by avoiding the need to call this.abilityFactory.defineAbility(user, resource) every time we send a request to endpoints guarded by ScopeAbilityGuard.

Domain
AuthN-Z
Action
fix
Department
Backend

Please authenticate to join the conversation.

Upvoters
Status

Completed

Board
💡

Feature Request

Tags

Low Priority

Date

11 months ago

Author

tadael shewarega

Subscribe to post

Get notified by email when there are changes.