front update

This commit is contained in:
grimhilt
2023-08-08 15:12:08 +02:00
parent 7d84ed7f9e
commit f19a6fa57c
7 changed files with 78 additions and 41 deletions

View File

@@ -12,18 +12,20 @@ export const Perm = {
};
const checkBit = (dec, perm) => {
if (!dec || !perm) return false;
const binStr = (dec >>> 0).toString(2);
const len = binStr.length;
return binStr[len - perm - 1];
return binStr[len - perm] === '1';
};
export const checkPerm = (perm, user, item = {}) => {
if (!perm || !user) return false;
switch (perm) {
case Perm.CREATE_ROLE:
return user.roles.length >= 1 && checkBit(user.roles[0].permissions, Perm.CREATE_ROLE);
case Perm.CREATE_PLAYLIST:
return user.roles.length >= 1 && checkBit(user.roles[0].permissions, Perm.CREATE_PLAYLIST);
case Perm.CREATE_ROLE:
case Perm.CREATE_USER:
return user.roles.length >= 1 && checkBit(user.roles[0].permissions, Perm.CREATE_USER);
case Perm.OWN_PLAYLIST:
return item?.owner_id === user.id;