hotfix to fix permission issue

This commit is contained in:
Anton Tranelis 2024-10-29 23:46:36 +01:00
parent a4d3285829
commit c37bc2cb57
3 changed files with 23 additions and 14 deletions

View File

@ -96,14 +96,18 @@ function usePermissionsManager(initialPermissions: Permission[]): {
); );
}; };
if (permissions.length === 0) return true; // Bedingung für leere Berechtigungen nur, wenn NICHT item und create
else if (user && user.role === adminRole) return true; if (permissions.length === 0 && !(collectionName === "item" && action === "create")) return true;
else if (user && user.role.id === adminRole) return true;
else { else {
return permissions.some(p => return permissions.some(p =>
p.action === action && p.action === action &&
p.collection === collectionName && p.collection === collectionName &&
( (
(p.policy === user?.role && // Neue Bedingung für "item" und "create"
(collectionName === "item" && action === "create" && layer?.public_edit_items === true) ||
(
(p.policy.name === user?.role.name &&
( (
!item || evaluatePermissions(p.permissions) !item || evaluatePermissions(p.permissions)
)) || )) ||
@ -113,12 +117,17 @@ function usePermissionsManager(initialPermissions: Permission[]): {
(!item || evaluatePermissions(p.permissions)) (!item || evaluatePermissions(p.permissions))
)) ))
) )
)
); );
} }
}, },
[permissions, user] [permissions, user]
); );
return { permissions, setPermissionApi, setPermissionData, setAdminRole, hasUserPermission }; return { permissions, setPermissionApi, setPermissionData, setAdminRole, hasUserPermission };
} }

View File

@ -130,7 +130,7 @@ export interface UserApi {
export type UserItem = { export type UserItem = {
id?: string; id?: string;
role?: string; role?: any;
email?: string; email?: string;
password?: string; password?: string;
profile?: Profile; profile?: Profile;
@ -158,7 +158,7 @@ export type PermissionCondition = {
export type Permission = { export type Permission = {
id?: string; id?: string;
policy: string; policy: any;
collection: string; collection: string;
action: PermissionAction; action: PermissionAction;
permissions?: { // Optional, für spezifische Bedingungen wie `user_created` permissions?: { // Optional, für spezifische Bedingungen wie `user_created`