feat: refactoring casl permission checks for recursive nested operations#778
Merged
charlesBochet merged 16 commits intomainfrom Jul 25, 2023
Merged
feat: refactoring casl permission checks for recursive nested operations#778charlesBochet merged 16 commits intomainfrom
charlesBochet merged 16 commits intomainfrom
Conversation
99d05d4 to
7c03c13
Compare
7c03c13 to
aec68ae
Compare
charlesBochet
approved these changes
Jul 25, 2023
| { | ||
| create: createAbilityCheck, | ||
| createMany: createAbilityCheck, | ||
| upsert: simpleAbilityCheck, |
Member
There was a problem hiding this comment.
I think that we should find a better naming than "simple". existing?
server/src/ability/ability.util.ts
Outdated
| data, | ||
| ) => { | ||
| // Handle all operations cases | ||
| const items = !Array.isArray(data?.data ?? data) ? [data] : data; |
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.
This PR introduces a new capability to the project: checking permissions for Prisma operations involving nested relationships. This new feature ensures that the right permissions are in place when performing complex nested operations in our database.
Key highlights include:
Operations Definition: Operations are categorized into 'create' and 'simple' based on the type of permission checks they require. This classification improves how we process each operation.
Operations Checking: We've introduced 'OperationAbilityCheckers' that conduct permission checks depending on the operation type. 'createAbilityCheck' ensures a user has the ability to create a new entity, while 'simpleAbilityCheck' checks permissions for operations like 'connect', 'disconnect', 'delete', etc.
Recursive Nested Operations: We have introduced a new function,
relationAbilityChecker, that handles recursive nested operations. It splits each operation and checks them independently.Here is an example of how to use these new permission checks: