stalniy / casl

CASL is an isomorphic authorization JavaScript library which restricts what resources a given user is allowed to access
https://casl.js.org/
MIT License
5.93k stars 269 forks source link

Using custom aliases in PureAbility constructor #356

Closed astralmedia closed 4 years ago

astralmedia commented 4 years ago

Describe the bug I have spent a few days trying to crack this before I reached out...but when using a createAliasResolver with the resolveAction parameter on the PureAbility constructor is not working.

To Reproduce Steps to reproduce the behavior:

  1. Create an alias with the createAliasResolver()
  2. Pass the alias into the resolveAction param on a PureAbility constructor
// Create Aliases
const resolveActions = createAliasResolver({
    patch: ['update'],
    read: ['get', 'find'],
    delete: ['remove']
})

// Construct Ability
let caslAbility = new PureAbility(Builder.rules, {
    detectSubjectType: subject => (subject && subject.subject ? subject.subject : detectSubjectType(subject)),
    conditionsMatcher: conditions => {
        return createQueryTester(conditions, { operations: { $in, $eq } })
    },
    resolveAction: normalize => {
        return resolveActions
    }
})

Expected behavior I expect the aliases to work.

CASL Version:

@casl/ability - v ^4.1.5

Environment: Node v8.17.0

stalniy commented 4 years ago

Check the docs please.

Replace

resolveAction: normalize => {
        return resolveActions
    }

With

resolveAction: resolveActions

And it will work