Skip to content

Instantly share code, notes, and snippets.

@stalniy
Last active July 27, 2017 13:18
Show Gist options
  • Save stalniy/8653de4c7b5f5f7897e602f07e00e50d to your computer and use it in GitHub Desktop.
Save stalniy/8653de4c7b5f5f7897e602f07e00e50d to your computer and use it in GitHub Desktop.
CASL abilities js-data aurelia
import { DataStore } from '../services/ds'
function listenToSessionChanges(ds, onChange) {
ds.on('afterCreate', (name, session) => {
if (name === 'Session') {
onChange(session)
}
})
ds.on('afterFind', (name, id, mapper, session) => {
if (name === 'Session') {
onChange(session)
}
})
ds.on('afterDestroy', (name) => {
if (name === 'Session') {
onChange(null)
}
})
}
export function configureAbility({ container }) {
const ability = new Ability([])
container.registerInstance(Ability, ability)
listenToSessionChanges(container.get(DataStore), session => {
const rules = defineRulesFor(session ? session.user : null)
ability.update(rules)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment