mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
hotfix to fix permission issue
This commit is contained in:
parent
a4d3285829
commit
c37bc2cb57
@ -8,11 +8,11 @@ export default function AddButton({ triggerAction }: { triggerAction: React.Disp
|
||||
const layers = useLayers();
|
||||
const hasUserPermission = useHasUserPermission();
|
||||
|
||||
const canAddItems = () => {
|
||||
const canAddItems = () => {
|
||||
let canAdd = false;
|
||||
layers.map(layer => {
|
||||
if (layer.api?.createItem && hasUserPermission(layer.api.collectionName!, "create", undefined, layer) && layer.listed) canAdd = true;
|
||||
})
|
||||
})
|
||||
return canAdd;
|
||||
}
|
||||
|
||||
|
||||
@ -96,28 +96,37 @@ function usePermissionsManager(initialPermissions: Permission[]): {
|
||||
);
|
||||
};
|
||||
|
||||
if (permissions.length === 0) return true;
|
||||
else if (user && user.role === adminRole) return true;
|
||||
// Bedingung für leere Berechtigungen nur, wenn NICHT item und create
|
||||
if (permissions.length === 0 && !(collectionName === "item" && action === "create")) return true;
|
||||
else if (user && user.role.id === adminRole) return true;
|
||||
else {
|
||||
return permissions.some(p =>
|
||||
p.action === action &&
|
||||
p.collection === collectionName &&
|
||||
(
|
||||
(p.policy === user?.role &&
|
||||
// Neue Bedingung für "item" und "create"
|
||||
(collectionName === "item" && action === "create" && layer?.public_edit_items === true) ||
|
||||
(
|
||||
!item || evaluatePermissions(p.permissions)
|
||||
)) ||
|
||||
(p.policy == null &&
|
||||
(
|
||||
(layer?.public_edit_items || item?.layer?.public_edit_items) &&
|
||||
(!item || evaluatePermissions(p.permissions))
|
||||
))
|
||||
(p.policy.name === user?.role.name &&
|
||||
(
|
||||
!item || evaluatePermissions(p.permissions)
|
||||
)) ||
|
||||
(p.policy == null &&
|
||||
(
|
||||
(layer?.public_edit_items || item?.layer?.public_edit_items) &&
|
||||
(!item || evaluatePermissions(p.permissions))
|
||||
))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
},
|
||||
[permissions, user]
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { permissions, setPermissionApi, setPermissionData, setAdminRole, hasUserPermission };
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ export interface UserApi {
|
||||
|
||||
export type UserItem = {
|
||||
id?: string;
|
||||
role?: string;
|
||||
role?: any;
|
||||
email?: string;
|
||||
password?: string;
|
||||
profile?: Profile;
|
||||
@ -158,7 +158,7 @@ export type PermissionCondition = {
|
||||
|
||||
export type Permission = {
|
||||
id?: string;
|
||||
policy: string;
|
||||
policy: any;
|
||||
collection: string;
|
||||
action: PermissionAction;
|
||||
permissions?: { // Optional, für spezifische Bedingungen wie `user_created`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user