Skip to content

Instantly share code, notes, and snippets.

@aravindarc
Created September 17, 2021 09:07
Show Gist options
  • Save aravindarc/89cdcae925851eb9c460587e4dc36096 to your computer and use it in GitHub Desktop.
Save aravindarc/89cdcae925851eb9c460587e4dc36096 to your computer and use it in GitHub Desktop.
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