diff --git a/package-lock.json b/package-lock.json index 69d0dcc4..acb158d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "utopia-ui", - "version": "3.0.1", + "version": "3.0.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "utopia-ui", - "version": "3.0.1", + "version": "3.0.5", "license": "MIT", "dependencies": { "@heroicons/react": "^2.0.17", diff --git a/package.json b/package.json index 821ca4ed..45742b15 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "utopia-ui", - "version": "3.0.1", + "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/", diff --git a/src/Components/Map/Subcomponents/AddButton.tsx b/src/Components/Map/Subcomponents/AddButton.tsx index 025c7e04..dc8242f5 100644 --- a/src/Components/Map/Subcomponents/AddButton.tsx +++ b/src/Components/Map/Subcomponents/AddButton.tsx @@ -1,21 +1,23 @@ import * as React from 'react' import { useLayers } from '../hooks/useLayers' -import { useHasUserPermission } from '../hooks/usePermissions' +import { useHasUserPermission } from '../hooks/usePermissions'; -export default function AddButton ({ triggerAction }: { triggerAction: React.Dispatch> }) { - const layers = useLayers() - const hasUserPermission = useHasUserPermission() - const canAddItems = () => { - let canAdd = false - layers.map(layer => { - if (layer.api?.createItem && hasUserPermission(layer.api.collectionName!, 'create', undefined, layer) && layer.listed) canAdd = true - return null - }) - return canAdd - } +export default function AddButton({ triggerAction }: { triggerAction: React.Dispatch> }) { - return ( + const layers = useLayers(); + const hasUserPermission = useHasUserPermission(); + + 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; + } + + + return ( <>{ canAddItems() ?
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/Components/Map/hooks/usePermissions.tsx b/src/Components/Map/hooks/usePermissions.tsx index 71d08d0c..f7227c19 100644 --- a/src/Components/Map/hooks/usePermissions.tsx +++ b/src/Components/Map/hooks/usePermissions.tsx @@ -76,6 +76,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,32 +105,34 @@ function usePermissionsManager (initialPermissions: Permission[]): { andCondition._or ? andCondition._or.some((orCondition: any) => evaluateCondition(orCondition)) : evaluateCondition(andCondition) - ) - } - - if (permissions.length === 0) return true - else if (user && user.role === adminRole) return true + ); + }; + 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) return true; + else if (user && user.role.id === adminRole) return true; else { return permissions.some(p => p.action === action && p.collection === collectionName && - ( - (p.role === user?.role && + ( - !item || evaluatePermissions(p.permissions) - )) || - (p.role == 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 === "$t:public_label" && + ( + (layer?.public_edit_items || item?.layer?.public_edit_items) && + (!item || evaluatePermissions(p.permissions)) + )) + ) + + ); } }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [permissions, user] - ) + [permissions, user, adminRole] + ); return { permissions, setPermissionApi, setPermissionData, setAdminRole, hasUserPermission } } diff --git a/src/Components/Profile/ProfileView.tsx b/src/Components/Profile/ProfileView.tsx index 0b5ad6c6..6e126bfe 100644 --- a/src/Components/Profile/ProfileView.tsx +++ b/src/Components/Profile/ProfileView.tsx @@ -134,12 +134,6 @@ export function ProfileView ({ userType, attestationApi }: { userType: string, a // eslint-disable-next-line react-hooks/exhaustive-deps }, [selectPosition]) - useEffect(() => { - setTemplate(item?.layer?.itemType.template || userType) - }, [userType, item]) - - const [setUrlParams] = useState(new URLSearchParams(location.search)) - return ( <> {item && @@ -157,8 +151,8 @@ export function ProfileView ({ userType, attestationApi }: { userType: string, a } - {template === 'tabs' && - linkItem(id, item, updateItem)} unlinkItem={(id) => unlinkItem(id, item, updateItem)}/> + {template == "tabs" && + 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 c294560b..c92c5a15 100644 --- a/src/Components/Profile/Templates/TabsView.tsx +++ b/src/Components/Profile/Templates/TabsView.tsx @@ -11,10 +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 }) => { - const addFilterTag = useAddFilterTag() - const [activeTab, setActiveTab] = useState() - const navigate = useNavigate() +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 [addItemPopupType] = useState('') @@ -37,11 +34,10 @@ export const TabsView = ({ attestations, userType, item, offers, needs, relation const updateActiveTab = useCallback((id: number) => { setActiveTab(id) - const params = new URLSearchParams(window.location.search) - params.set('tab', `${id}`) - const newUrl = location.pathname + '?' + params.toString() - window.history.pushState({}, '', newUrl) - setUrlParams(params) + const params = new URLSearchParams(window.location.search); + params.set("tab", `${id}`); + const newUrl = location.pathname + "?" + params.toString(); + window.history.pushState({}, '', newUrl); // eslint-disable-next-line react-hooks/exhaustive-deps }, [location.pathname]) diff --git a/src/Utils/MarkerIconFactory.ts b/src/Utils/MarkerIconFactory.ts index 1253e9bc..51c40147 100644 --- a/src/Utils/MarkerIconFactory.ts +++ b/src/Utils/MarkerIconFactory.ts @@ -36,8 +36,8 @@ const addIcon = (icon: string) => { return '' case 'puzzle': return '' - case 'staff-snake': - return '' + case "staff-snake": + return '' default: return '' } diff --git a/src/types.ts b/src/types.ts index 9f14fb4f..d32af351 100644 --- a/src/types.ts +++ b/src/types.ts @@ -134,7 +134,7 @@ export type Profile = { export type UserItem = { id?: string; - role?: string; + role?: any; email?: string; password?: string; profile?: Profile; @@ -166,7 +166,7 @@ export type PermissionAction = 'create'|'read'|'update'|'delete'; export type Permission = { id?: string; - role: string; + policy: any; collection: string; action: PermissionAction; permissions?: { // Optional, für spezifische Bedingungen wie `user_created`