Created
September 17, 2021 09:07
-
-
Save aravindarc/89cdcae925851eb9c460587e4dc36096 to your computer and use it in GitHub Desktop.
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
const OBJECTTYPES = { | |
FILES: 1, | |
DIRECTORIES: 2 | |
}; | |
const FILEACTIONS = { | |
READ: 1, | |
WRITE: 2 | |
}; | |
const DIRECTORYACTIONS = { | |
READ: 1, | |
WRITE: 2 | |
}; | |
var helloAcl = { | |
"Alice": [ FILEACTIONS.READ, FILEACTIONS.WRITE ], | |
"Bob": [ FILEACTIONS.READ ] | |
}; | |
var documentsAcl = { | |
"Alice": [ DIRECTORYACTIONS.READ, DIRECTORYACTIONS.WRITE ], | |
"Bob": [ DIRECTORYACTIONS.READ ] | |
} | |
var objects = { | |
"hello.txt": { name: "hello.txt", type: OBJECTTYPES.FILES, acl: helloAcl }, | |
"documents": { name: "documents", type: OBJECTTYPES.DIRECTORIES, acl: documentsAcl } | |
}; | |
function check(subject, action, object) { | |
if (object.acl[subject].includes(action)) { | |
return true; | |
} | |
return false; | |
} | |
console.log(check("Alice", FILEACTIONS.WRITE, objects["hello.txt"])); | |
console.log(check("Bob", FILEACTIONS.WRITE, objects["hello.txt"])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment