Last active
August 29, 2015 14:17
-
-
Save dominictarr/bac6dc533f8c9ec6f81d to your computer and use it in GitHub Desktop.
perms for bittodo
This file contains 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
{ | |
allow: ['add', 'query'], deny: [], | |
rules: { | |
add: { | |
//allow the call of this method only if the argument is accepted by this function. | |
call: function (value) { | |
return (value.type === 'task' || value.type === '_task') | |
}, | |
query: { | |
//only allow calls matching this. | |
//here, "safe" is a set of helpers that make implementing perms functions easy. | |
call: function (value) { | |
return ( | |
safe.contains(value, {path: ['content', 'type'], eq: 'task'}) || | |
safe.contains(value, {path: ['content', 'type'], eq: '_task'}) | |
) | |
}, | |
//a filter would check the output of the stream. | |
//this should already be ensured by the call check, | |
//but if we filter twice, even safer. | |
filter: function (value) { | |
return (value.type === 'task' || value.type === '_task') | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment