From 78503d498ece26468cc2b150b97f34582b68e5b6 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Wed, 23 Oct 2024 11:36:05 +0200 Subject: [PATCH 01/10] 3.0.2 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1453add6..4ed638a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "utopia-ui", - "version": "3.0.1", + "version": "3.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "utopia-ui", - "version": "3.0.1", + "version": "3.0.2", "license": "MIT", "dependencies": { "@heroicons/react": "^2.0.17", diff --git a/package.json b/package.json index d4fe0244..275d9b0c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "utopia-ui", - "version": "3.0.1", + "version": "3.0.2", "description": "Reuseable React Components to build mapping apps for real life communities and networks", "repository": "https://github.com/utopia-os/utopia-ui", "homepage:": "https://utopia-os.org/", From ddbf262912428f7e6cf0ca0c87309d249be32702 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Tue, 29 Oct 2024 11:55:40 +0100 Subject: [PATCH 02/10] fixed staff-snake --- src/Components/Map/UtopiaMap.css | 2 +- src/Utils/MarkerIconFactory.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Components/Map/UtopiaMap.css b/src/Components/Map/UtopiaMap.css index 70812368..389e3469 100644 --- a/src/Components/Map/UtopiaMap.css +++ b/src/Components/Map/UtopiaMap.css @@ -116,7 +116,7 @@ .staff-snake-icon { position: relative; - top: -36px; + top: -35px; left: 4px; width: 24px; } diff --git a/src/Utils/MarkerIconFactory.ts b/src/Utils/MarkerIconFactory.ts index 543dd459..31da6bf6 100644 --- a/src/Utils/MarkerIconFactory.ts +++ b/src/Utils/MarkerIconFactory.ts @@ -39,7 +39,7 @@ const addIcon = (icon: string) => { case "puzzle": return '' case "staff-snake": - return '' + return '' default: return ""; } From 03e7a9ca8ca30ef59ccc8b24ebdd99e699abd673 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Tue, 29 Oct 2024 16:19:52 +0100 Subject: [PATCH 03/10] updated permission types --- src/Components/Map/hooks/usePermissions.tsx | 8 ++------ src/types.ts | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Components/Map/hooks/usePermissions.tsx b/src/Components/Map/hooks/usePermissions.tsx index cb11a81f..dc607260 100644 --- a/src/Components/Map/hooks/usePermissions.tsx +++ b/src/Components/Map/hooks/usePermissions.tsx @@ -103,11 +103,11 @@ function usePermissionsManager(initialPermissions: Permission[]): { p.action === action && p.collection === collectionName && ( - (p.role === user?.role && + (p.policy === user?.role && ( !item || evaluatePermissions(p.permissions) )) || - (p.role == null && + (p.policy == null && ( (layer?.public_edit_items || item?.layer?.public_edit_items) && (!item || evaluatePermissions(p.permissions)) @@ -116,12 +116,8 @@ function usePermissionsManager(initialPermissions: Permission[]): { ); } }, - // eslint-disable-next-line react-hooks/exhaustive-deps [permissions, user] ); - - - return { permissions, setPermissionApi, setPermissionData, setAdminRole, hasUserPermission }; } diff --git a/src/types.ts b/src/types.ts index 5e80b58f..4ac29c3a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -158,7 +158,7 @@ export type PermissionCondition = { export type Permission = { id?: string; - role: string; + policy: string; collection: string; action: PermissionAction; permissions?: { // Optional, für spezifische Bedingungen wie `user_created` From a4d32858299d88a733e01a553ad9d91eb518a10e Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Tue, 29 Oct 2024 16:20:00 +0100 Subject: [PATCH 04/10] 3.0.3 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 392c2484..851055cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "utopia-ui", - "version": "3.0.2", + "version": "3.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "utopia-ui", - "version": "3.0.2", + "version": "3.0.3", "license": "MIT", "dependencies": { "@heroicons/react": "^2.0.17", diff --git a/package.json b/package.json index 1aeb9779..93d1a687 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "utopia-ui", - "version": "3.0.2", + "version": "3.0.3", "description": "Reuseable React Components to build mapping apps for real life communities and networks", "repository": "https://github.com/utopia-os/utopia-ui", "homepage:": "https://utopia-os.org/", From c37bc2cb575d35ec7bab236a2ef9d40a0e1781b1 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Tue, 29 Oct 2024 23:46:36 +0100 Subject: [PATCH 05/10] hotfix to fix permission issue --- .../Map/Subcomponents/AddButton.tsx | 4 +-- src/Components/Map/hooks/usePermissions.tsx | 29 ++++++++++++------- src/types.ts | 4 +-- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/Components/Map/Subcomponents/AddButton.tsx b/src/Components/Map/Subcomponents/AddButton.tsx index f5d6c7ff..84073aa6 100644 --- a/src/Components/Map/Subcomponents/AddButton.tsx +++ b/src/Components/Map/Subcomponents/AddButton.tsx @@ -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; } diff --git a/src/Components/Map/hooks/usePermissions.tsx b/src/Components/Map/hooks/usePermissions.tsx index dc607260..ec98cb3f 100644 --- a/src/Components/Map/hooks/usePermissions.tsx +++ b/src/Components/Map/hooks/usePermissions.tsx @@ -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 }; } diff --git a/src/types.ts b/src/types.ts index 4ac29c3a..7ec77af2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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` From 7f121228728fc2b4c1bd272054a2aaf68ff72f85 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Tue, 29 Oct 2024 23:47:13 +0100 Subject: [PATCH 06/10] 3.0.4 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 851055cb..f5950367 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "utopia-ui", - "version": "3.0.3", + "version": "3.0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "utopia-ui", - "version": "3.0.3", + "version": "3.0.4", "license": "MIT", "dependencies": { "@heroicons/react": "^2.0.17", diff --git a/package.json b/package.json index 93d1a687..9e35ed75 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "utopia-ui", - "version": "3.0.3", + "version": "3.0.4", "description": "Reuseable React Components to build mapping apps for real life communities and networks", "repository": "https://github.com/utopia-os/utopia-ui", "homepage:": "https://utopia-os.org/", From 9dcd2b858fc6dabbc9e6c0c744ae068df8df5d44 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Wed, 30 Oct 2024 07:43:16 +0100 Subject: [PATCH 07/10] hotfix to fix permission issue --- src/Components/Profile/ProfileView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Profile/ProfileView.tsx b/src/Components/Profile/ProfileView.tsx index 8ce0efba..c1ac6efd 100644 --- a/src/Components/Profile/ProfileView.tsx +++ b/src/Components/Profile/ProfileView.tsx @@ -140,7 +140,7 @@ export function ProfileView({ userType, attestationApi }: { userType: string , a setTemplate(item?.layer?.itemType.template || userType); }, [userType, item]) - const [/* urlParams, */ setUrlParams] = useState(new URLSearchParams(location.search)); + const [ urlParams, setUrlParams] = useState(new URLSearchParams(location.search)); return ( From 1c2fa0728549ec1effb3fcac91d9f358c04911e9 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Wed, 30 Oct 2024 07:43:23 +0100 Subject: [PATCH 08/10] 3.0.5 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index f5950367..411019d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "utopia-ui", - "version": "3.0.4", + "version": "3.0.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "utopia-ui", - "version": "3.0.4", + "version": "3.0.5", "license": "MIT", "dependencies": { "@heroicons/react": "^2.0.17", diff --git a/package.json b/package.json index 9e35ed75..42112809 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "utopia-ui", - "version": "3.0.4", + "version": "3.0.5", "description": "Reuseable React Components to build mapping apps for real life communities and networks", "repository": "https://github.com/utopia-os/utopia-ui", "homepage:": "https://utopia-os.org/", From 97add15469005d75f1530054b488c3eb7ebc4ad0 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Wed, 30 Oct 2024 08:03:19 +0100 Subject: [PATCH 09/10] removed unused var --- src/Components/Map/hooks/usePermissions.tsx | 2 +- src/Components/Profile/ProfileView.tsx | 4 +--- src/Components/Profile/Templates/TabsView.tsx | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Components/Map/hooks/usePermissions.tsx b/src/Components/Map/hooks/usePermissions.tsx index ec98cb3f..b9d02afc 100644 --- a/src/Components/Map/hooks/usePermissions.tsx +++ b/src/Components/Map/hooks/usePermissions.tsx @@ -121,7 +121,7 @@ function usePermissionsManager(initialPermissions: Permission[]): { ); } }, - [permissions, user] + [permissions, user, adminRole] ); diff --git a/src/Components/Profile/ProfileView.tsx b/src/Components/Profile/ProfileView.tsx index c1ac6efd..d7b7e4e7 100644 --- a/src/Components/Profile/ProfileView.tsx +++ b/src/Components/Profile/ProfileView.tsx @@ -140,8 +140,6 @@ export function ProfileView({ userType, attestationApi }: { userType: string , a setTemplate(item?.layer?.itemType.template || userType); }, [userType, item]) - const [ urlParams, setUrlParams] = useState(new URLSearchParams(location.search)); - return ( <> @@ -161,7 +159,7 @@ export function ProfileView({ userType, attestationApi }: { userType: string , a } {template == "tabs" && - linkItem(id, item, updateItem)} unlinkItem={(id) => unlinkItem(id, item, updateItem)}/> + linkItem(id, item, updateItem)} unlinkItem={(id) => unlinkItem(id, item, updateItem)}/> } diff --git a/src/Components/Profile/Templates/TabsView.tsx b/src/Components/Profile/Templates/TabsView.tsx index 00ef9532..d8deb7b0 100644 --- a/src/Components/Profile/Templates/TabsView.tsx +++ b/src/Components/Profile/Templates/TabsView.tsx @@ -11,7 +11,7 @@ import { useAssetApi } from '../../AppShell/hooks/useAssets' import { timeAgo } from '../../../Utils/TimeAgo' // eslint-disable-next-line no-unused-vars -export const TabsView = ({ attestations, userType, item, offers, needs, relations, updatePermission, loading, linkItem, unlinkItem, setUrlParams }: { attestations: Array, userType: string, item: Item, offers: Array, needs: Array, relations: Array, updatePermission: boolean, loading: boolean, linkItem: (id: string) => Promise, unlinkItem: (id: string) => Promise, setUrlParams: any }) => { +export const TabsView = ({ attestations, userType, item, offers, needs, relations, updatePermission, loading, linkItem, unlinkItem }: { attestations: Array, userType: string, item: Item, offers: Array, needs: Array, relations: Array, updatePermission: boolean, loading: boolean, linkItem: (id: string) => Promise, unlinkItem: (id: string) => Promise }) => { const addFilterTag = useAddFilterTag(); const [activeTab, setActiveTab] = useState(); @@ -42,7 +42,6 @@ export const TabsView = ({ attestations, userType, item, offers, needs, relation params.set("tab", `${id}`); const newUrl = location.pathname + "?" + params.toString(); window.history.pushState({}, '', newUrl); - setUrlParams(params); // eslint-disable-next-line react-hooks/exhaustive-deps }, [location.pathname]); From 0cef378cd6201ccc21a2a62d29ecd041770d6fb8 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Thu, 31 Oct 2024 12:04:57 +0100 Subject: [PATCH 10/10] fix some issues with th previous fix --- src/Components/Map/hooks/usePermissions.tsx | 22 ++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Components/Map/hooks/usePermissions.tsx b/src/Components/Map/hooks/usePermissions.tsx index b9d02afc..2f94b7b0 100644 --- a/src/Components/Map/hooks/usePermissions.tsx +++ b/src/Components/Map/hooks/usePermissions.tsx @@ -74,6 +74,16 @@ function usePermissionsManager(initialPermissions: Permission[]): { item?: Item, layer?: LayerProps ) => { + + console.log(layer?.name); + console.log(user?.role.name); + console.log(action); + console.log(permissions.filter(p => p.policy.name === user?.role.name || (p.policy.name === "$t:public_label" && !user))); + + + + + const evaluateCondition = (condition: any) => { if (condition.user_created?._eq === "$CURRENT_USER") { return item?.user_created?.id === user?.id; @@ -95,29 +105,27 @@ function usePermissionsManager(initialPermissions: Permission[]): { : evaluateCondition(andCondition) ); }; - + if (collectionName === "items" && action === "create" && layer?.public_edit_items) return true; // Bedingung für leere Berechtigungen nur, wenn NICHT item und create - if (permissions.length === 0 && !(collectionName === "item" && action === "create")) return true; + if (permissions.length === 0) return true; else if (user && user.role.id === adminRole) return true; else { return permissions.some(p => p.action === action && p.collection === collectionName && - ( - // 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) )) || - (p.policy == null && + (p.policy === "$t:public_label" && ( (layer?.public_edit_items || item?.layer?.public_edit_items) && (!item || evaluatePermissions(p.permissions)) )) ) - ) + ); } },