Skip to content

Instantly share code, notes, and snippets.

@dominictarr
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominictarr/bac6dc533f8c9ec6f81d to your computer and use it in GitHub Desktop.
Save dominictarr/bac6dc533f8c9ec6f81d to your computer and use it in GitHub Desktop.
perms for bittodo
{
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