Last active
July 27, 2017 12:54
-
-
Save stalniy/5a967446abdcca949ec82444e3e9fd6c to your computer and use it in GitHub Desktop.
CASL abilities without models in Aurelia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AbilityBuilder, Ability } from 'casl' | |
function defineRulesFor(user) { | |
const { can, rules } = AbilityBuilder.extract() | |
can('read', ['Post', 'Comment']) | |
if (user) { | |
can('create', 'Post') | |
can('manage', ['Post', 'Comment'], { authorId: user._id }) | |
can(['read', 'update'], 'User', { _id: user._id }) | |
} | |
return rules | |
} | |
export function configureAbility({ container }) { | |
const ability = new Ability([]) | |
container.registerInstance(Ability, ability) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment