-
-
Notifications
You must be signed in to change notification settings - Fork 284
Description
Is your feature request related to a problem? Please describe.
We cannot use accessibleBy with prisma's findUnique, update and delete functions.
When we use accessibleBy(ability).ModelName it gives this result: { OR: [ { uniqueValue: 1 } ] }
However what we need is only bare object: { uniqueValue: 1 }
Describe the solution you'd like
So, what I do is:
I also use params in the conditions... if there is param it adds and if there is not it leaves conditions alone:
To define:
can('read', 'post', { authorId: account.id, ...params });
(if there is any param it will add, and if there is none, there will be only authorId) - (Also ...params part is not the topic but this example shows that if casl solves the problem, how easy the implementation is) - (Also, we can even write conditions with operators like AND / OR)
prisma.post.findMany({ where: accessibleBy(ability).Post['OR'][0] })
prisma.post.findUnique({ where: accessibleBy(ability).Post['OR'][0] })
prisma.post.update({ where: accessibleBy(ability).Post['OR'][0] })
prisma.post.update({ where: accessibleBy(ability).Post['OR'][0] }) // runs if no foreign key constraint exist
(Also need to use // @ts-ignore if using with TypeScript)
We should not be writing ['OR'][0] to the end (also I do not think that anyone writes 😄)... and accessibleBy(ability).Post should be enough.
Are there any reason that casl does not provide bare object rather than default added OR array inside of an object? Because bare object will solve 95% of cases which people can face isn't it?