-
-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error on new Ability(rules) #305
Comments
Starting from 4.0, const { can, cannot, rules } = new AbilityBuilder<Ability>(); For more details check the API docs |
By the way, you can simplify your rules by changing: for (const projectData of user.MandatoryProjectList) {
can(['share', 'edit', 'assign'], 'Project', { idProject: projectData.idProject });
} to const projectIds = user.MandatoryProjectList.map(projectData => projectData.idProject)
can(['share', 'edit', 'assign'], 'Project', { idProject: { $in: projectIds } }); |
I tried the minumum code, but the error persist...
|
Did you tried what I suggested? |
Please also check the new angular example - https://github.com/stalniy/casl-examples/blob/master/packages/angular-todo/src/services/AppAbility.ts |
I have tried what you sugget, but the problem is on the constructor from Ability, because not allow rules. if i do that:
the error still
|
i'm trying that example, but it's a little complicated, and i can not apply it to my current project... |
my code is:
And the error is on line this.ability.update(rules)
Where come that unknown of SubjectRawRule<string, SubjectType, unknown>? |
The problem on the |
If you think you know better, why do you ask me after all? :) I created a simple example for you, so you can make sure this is true - https://codesandbox.io/s/typescript-examples-l0p8b?file=/src/index.ts |
Close this as there is nothing to do from my side. Please check the docs and the examples |
Ran into the same issue. Even the very first example code snippet from the README produces this error, so it is a bit rich to suggest checking the docs, in my opinion. Glad there's an easy solution, though! |
Thanks for the note. I’ll fix the example in README. But I’d recommend to check docs instead - https://stalniy.github.io/casl/v4/en/guide/intro in CASL v5, I’ll remove some legacy types and errors will be easier to understand. |
@stalniy is this the issue I'm seeing on the below Sandbox: https://codesandbox.io/s/wonderful-meadow-02kls?file=/src/index.ts I'm trying to test a basic RBAC set up and hit a similar typescript error. I thought the workaround might be to remove the Ability class on line 32: const { can, build } = new AbilityBuilder<AppAbility>(Ability) but that causes the results to be incorrect (all conditions turn true): Any help in understanding the correct set up would be amazing. I'm trying to follow your cookbook recipe but it doesn't seem to validate so I created this slimmed-down version to try and see why :) https://casl.js.org/v4/en/cookbook/roles-with-static-permissions |
@theGC there are some typings issues in 4.x which I fixed in prerelease branch for v5. For now, you need to do this: import { AbilityClass, Ability } from '@casl/ability'
type AppAbility = ...
const AppAbility = Ability as AbilityClass<AppAbility>;
const { can, build } = new AbilityBuilder<AppAbility>(AppAbility); |
@stalniy that's got it, thank you and thanks for all your hard work on CASL. Been using it within Feathers for a few days now and it's making things much clearer in their structure and logic. Looking forward to v5 👍 In case it helps anyone else, I've updated the sandbox and pulled it more in line with the cookbook article: https://codesandbox.io/s/casl-demo-roles-with-static-permissions-02kls?file=/src/index.ts |
Hi,
I'm using casl angular and have alredy update the version from 3.X to 4.
I have updated my code a little but doesn't work.
Current version:
"@casl/ability": "^4.0.8",
"@casl/angular": "^4.0.4",
Returns a error on the line return new Ability(rules);
Angular CLI: 9.1.4
Node: 10.15.3
OS: darwin x64
Angular: 9.1.4
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes
Package Version
@angular-devkit/architect 0.900.7
@angular-devkit/build-angular 0.900.7
@angular-devkit/build-optimizer 0.900.7
@angular-devkit/build-webpack 0.900.7
@angular-devkit/core 9.0.7
@angular-devkit/schematics 9.1.4
@angular/cdk 9.2.2
@angular/flex-layout 9.0.0-beta.29
@angular/material 9.2.2
@angular/material-moment-adapter 9.2.2
@ngtools/webpack 9.0.7
@schematics/angular 9.1.4
@schematics/update 0.901.4
rxjs 6.5.5
typescript 3.7.5
webpack 4.41.2
The text was updated successfully, but these errors were encountered: