Skip to content

Instantly share code, notes, and snippets.

@digitalsadhu
Last active August 29, 2015 13:57
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 digitalsadhu/9398307 to your computer and use it in GitHub Desktop.
Save digitalsadhu/9398307 to your computer and use it in GitHub Desktop.
Idea for new interface for admittance js
var fs = require('fs')
, admittance = require('admittance')
//read from the text file where we store pairs of user ids and permissions
var storeR = fs.createReadStream(__dirname + '/my-store.txt')
//read in permissions
storeR.pipe(admittance)
//do a permissions check
if (admittance(userid).is('admin')) {
//yay, user is admin!
}
var fs = require('fs')
, admittance = require('admittance')
//read from the text file where we store pairs of user ids and permissions
var storeR = fs.createReadStream(__dirname + '/my-store.txt')
//write to the text file where we store pairs of user ids and permissions
var storeW = fs.createReadStream(__dirname + '/my-store.txt')
//read in permissions
storeR.pipe(admittance)
//create a permission and store it
admittance(userid, 'admin').pipe(storeW)
//define a tree permission structure
admittance('editor', 'admin') //admin can do anything an editor can
.admittance('subscriber', 'editor') //editor can do anything a subscriber can
.admittance('user', 'editor') //editor can also do anything a user can
.pipe(storeW) //persist the structure
//do a permissions check
if (admittance(userid).is('admin')) {
//yay, user is admin!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment