Skip to content
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

Allow to specify possible actions, subject types and conditions for Ability #256

Closed
11 tasks done
stalniy opened this issue Feb 4, 2020 · 0 comments
Closed
11 tasks done
Milestone

Comments

@stalniy
Copy link
Owner

stalniy commented Feb 4, 2020

Allow to specify which subjects Ability can use. Affects:

  • Ability
    • can
    • cannot
    • update
    • Rule & RawRule
  • AbilityBuilder
    • can
    • cannot
  • ForbiddenError
  • casl/aurelia
  • casl/angular
  • casl/vue
  • casl/react
  • casl/mongoose

For example:

import { Ability, AbilityOptions } from '@casl/ability';
import { Post, User } from './models'

type AppSubjects = 'Post' | 'User' | 'all'
// or
type AppSubjects = Post | User | 'all'
interface AppAbilityOptions extends AbilityOptions<AppSubjects> {}

const ability = new Ability<AppAbilityOptions>([]);

// alternatively it can be (need to decide whether it's possible to keep this thing simpler)

const ability = new Ability<Subjects>([]);

// or
const ability = AbilityBuilder.define<Subjects>((can, cannot) => {
  can('read', 'User') // ok
  can('read', 'user') // error
})
// or
const { can, cannot, rules } = AbilityBuilder.extract<Subjects>();

can('read', 'User') // ok
can('read', 'user') // error

// so then
ability.can('read', 'user') // error, but
ability.can('read', 'User') // ok
@stalniy stalniy added this to the 4.x milestone Feb 4, 2020
@stalniy stalniy changed the title Allow to specify possible subject types for can functions Allow to specify possible actions, subject types and conditions for Ability Feb 13, 2020
stalniy added a commit that referenced this issue Feb 13, 2020
deprecates `actions` field in `Rule` types use `action` instead
deprecates `AbilityBuilder.define` use `AbilityBuilder.extract` instead
removes default `crud` alias. If you want it use `Ability.addAlias('crud', ['create', 'read', 'update', 'delete'])`
removes possibility to pass `RuleType` option in `Ability` constructor. Use `conditionsMatcher` and `fieldMatcher` options instead.
`packRules` and `unpackRules` now accepts optional second argument which packs/unpacks subject type. This is useful when you want to use Classes as subject types

Fixes #256 BREAKING CHANGES
stalniy added a commit that referenced this issue Feb 13, 2020
Relates to #256 BREAKING CHANGES
stalniy added a commit that referenced this issue Feb 13, 2020
…lues for generics

Also adds default generic values for AbilityModule in angular package

Relates to #256
stalniy added a commit that referenced this issue Feb 13, 2020
stalniy added a commit that referenced this issue Feb 13, 2020
Relates to #256 BREAKING CHANGES
stalniy added a commit that referenced this issue Feb 14, 2020
Prefixed private methods with _

Relates to #256 BREAKING CHANGES
stalniy added a commit that referenced this issue Feb 14, 2020
Prefixed private methods with _

Relates to #256 BREAKING CHANGES
stalniy added a commit that referenced this issue Feb 14, 2020
stalniy added a commit that referenced this issue Feb 14, 2020
This is an initial support for claim based abilities in #107

Relates to #256 BREAKING CHANGES
@stalniy stalniy closed this as completed Feb 14, 2020
stalniy added a commit that referenced this issue Feb 17, 2020
deprecates `actions` field in `Rule` types use `action` instead
deprecates `AbilityBuilder.define` use `AbilityBuilder.extract` instead
removes default `crud` alias. If you want it use `Ability.addAlias('crud', ['create', 'read', 'update', 'delete'])`
removes possibility to pass `RuleType` option in `Ability` constructor. Use `conditionsMatcher` and `fieldMatcher` options instead.
`packRules` and `unpackRules` now accepts optional second argument which packs/unpacks subject type. This is useful when you want to use Classes as subject types

Fixes #256 BREAKING CHANGES
stalniy added a commit that referenced this issue Feb 17, 2020
Relates to #256 BREAKING CHANGES
stalniy added a commit that referenced this issue Feb 17, 2020
…lues for generics

Also adds default generic values for AbilityModule in angular package

Relates to #256
stalniy added a commit that referenced this issue Feb 17, 2020
stalniy added a commit that referenced this issue Feb 17, 2020
Relates to #256 BREAKING CHANGES
stalniy added a commit that referenced this issue Feb 17, 2020
Prefixed private methods with _

Relates to #256 BREAKING CHANGES
stalniy added a commit that referenced this issue Feb 17, 2020
stalniy added a commit that referenced this issue Feb 17, 2020
This is an initial support for claim based abilities in #107

Relates to #256 BREAKING CHANGES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant