Created
July 24, 2017 20:03
-
-
Save stalniy/38f923f7aa4597595744a09d0492f846 to your computer and use it in GitHub Desktop.
CASL expressjs changed
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
function defineAbilitiesFor(user) { | |
const { rules, can } = AbilityBuilder.extract() | |
if (user) { | |
can('manage', ['Post', 'Comment'], { author: user._id }) | |
can(['read', 'update'], 'User', { _id: user.id }) | |
} else { | |
can('read', ['Post', 'Comment']) | |
can('create', 'User') | |
} | |
return new Ability(rules) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment