Comments (1)
The main issue with the idea is that for some cases we would like to define not all actions or not all subjects.
Lets consider an example with hardware capabilities and user permissions. For example, there are devices which supports wifi and which not. So, we define ability like this:
const hardwareAbility = AbilityBuilder.define(can => {
if (hardware.supportsWiFi) {
can('manage', 'WiFi')
}
})
const userAbility = AbilityBuilder.define(can => {
if (user.is('admin')) {
can('manage', 'WiFi')
can(['read', 'update'], 'User', { id: user.id })
}
})
const ability = hardwareAbility.concat(userAbility)
Now when we do ability.can('read', 'Wifi')
all works as expected but if we do ability.can('read', 'User')
it will return false
because hardware ability doesn't have rules for User
(and shouldn't have them).
So, I decline this feature in favor of #45 . With conditional rules it may look like this:
const userAbility = AbilityBuilder.define(can => {
if (user.is('admin')) {
can('manage', 'WiFi').onlyIf(() => hardware.supportsWiFi, { error: 'This device does not have WiFi card' })
can(['read', 'update'], 'User', { id: user.id })
}
})
from casl.
Related Issues (20)
- [Doc]: improve explanation of useAbility within useEffect, useMemo, ... HOT 2
- [Question] How do I get the prisma query object without using accessibleBy? HOT 2
- ability.can requires third parameters to be string and subject() doesn't work HOT 6
- Recommended way to restrict fields access with @casl/prisma ?
- Accessing nested fields does not work as described in the docs HOT 4
- Subject from @casl/ability need a full object with prisma HOT 4
- Checking access on ability throws an error - Prisma, Nest HOT 5
- Angular 16 support HOT 5
- [prisma] Using extensions to remove the need for `subject` helper with prisma HOT 5
- Can not working like it should HOT 4
- Can not Working HOT 3
- question: using accessibleBy(ability) in prisma create query HOT 1
- [prisma] Support for Prisma V5 HOT 9
- accessibleBy does not throw an error as expected when using createPrismaAbility HOT 3
- $ability in component template is not updated after I update it in a mixin HOT 4
- 📖 Update docs for TypeScript in Vue 3 using `createMongoAbility` HOT 1
- Overriding via provide in a plugin causes strange behavior in templates HOT 19
- Subjects and Scopes (I need help) HOT 1
- CASL HOT 2
- Have to use @ts-ignore while defining abilities, is something broken? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from casl.