39 lines
1021 B
JavaScript
39 lines
1021 B
JavaScript
const permissionBits = {
|
|
DEFAULT: 1, // 0001
|
|
CALL: 2, // 0010
|
|
UNUSED: 4, // 0100
|
|
ADMIN: 8, // 1000
|
|
}
|
|
|
|
function checkPermissions(userPermissionBits) {
|
|
// Default if you have no permissions
|
|
let permissions = {
|
|
default: false,
|
|
call: false,
|
|
unused: false,
|
|
admin: false,
|
|
}
|
|
|
|
if(userPermissionBits & permissionBits.DEFAULT) {
|
|
permissions.default = true;
|
|
}
|
|
if(userPermissionBits & permissionBits.CALL) {
|
|
permissions.call = true;
|
|
}
|
|
if(userPermissionBits & permissionBits.UNUSED) {
|
|
permissions.unused = true;
|
|
}
|
|
if(userPermissionBits & permissionBits.ADMIN) {
|
|
permissions.admin = true;
|
|
}
|
|
return permissions;
|
|
}
|
|
/*
|
|
let userPermissionBits = permissionBits.DEFAULT;
|
|
userPermissionBits |= permissionBits.CALL; // add permission
|
|
userPermissionBits ^= permissionBits.ADMIN; // toggle permission
|
|
userPermissionBits &= (~permissionBits.CALL); // remove permission
|
|
*/
|
|
|
|
export { permissionBits, checkPermissions };
|