Skip to content

Instantly share code, notes, and snippets.

@stalniy
Last active July 27, 2017 12:54
Show Gist options
  • Save stalniy/5a967446abdcca949ec82444e3e9fd6c to your computer and use it in GitHub Desktop.
Save stalniy/5a967446abdcca949ec82444e3e9fd6c to your computer and use it in GitHub Desktop.
CASL abilities without models in Aurelia
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