improve permissions access on playlist

This commit is contained in:
grimhilt
2023-08-14 01:19:06 +02:00
parent 4d6414d143
commit 5b2dd86e30
2 changed files with 41 additions and 19 deletions

View File

@@ -29,6 +29,20 @@ export const checkPerm = (perm, user, item = {}) => {
return user.roles.length >= 1 && checkBit(user.roles[0].permissions, Perm.CREATE_USER);
case Perm.OWN_PLAYLIST:
return item?.owner_id === user.id;
case Perm.VIEW_PLAYLIST:
return (
checkPerm(Perm.OWN_PLAYLIST, user, item) ||
item?.view.find(
(role) => role.user_id === user.id || user.roles.find((user_role) => user_role.id === role.id)
)
);
case Perm.EDIT_PLAYLIST:
return (
checkPerm(Perm.OWN_PLAYLIST, user, item) ||
item?.edit.find(
(role) => role.user_id === user.id || user.roles.find((user_role) => user_role.id === role.id)
)
);
default:
return false;
}
@@ -36,7 +50,7 @@ export const checkPerm = (perm, user, item = {}) => {
const GrantAccess = ({ role, roles, children, item }) => {
const { user } = useAuth();
if (role && checkPerm(role, user)) {
if (role && checkPerm(role, user, item)) {
return children;
} else if (roles) {
let flag = false;