AutoCallManu/utils/permissions.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

const permissionBits = {
2023-12-12 14:11:34 +01:00
DEFAULT: 1, // 00001
CALL: 2, // 00010
USERS: 4, // 00100
ADMIN: 8, // 01000
CONTACTS: 16, // 10000
}
function checkPermissions(userPermissionBits) {
// Default if you have no permissions
let permissions = {
default: false,
call: false,
2023-12-12 14:11:34 +01:00
users: false,
admin: false,
2023-12-12 14:11:34 +01:00
contacts: false,
}
if(userPermissionBits & permissionBits.DEFAULT) {
permissions.default = true;
}
if(userPermissionBits & permissionBits.CALL) {
permissions.call = true;
}
2023-12-12 14:11:34 +01:00
if(userPermissionBits & permissionBits.USERS) {
permissions.users = true;
}
if(userPermissionBits & permissionBits.ADMIN) {
permissions.admin = true;
}
2023-12-12 14:11:34 +01:00
if(userPermissionBits & permissionBits.CONTACTS) {
permissions.contacts = 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 };