From a0bcf352369022feeff762153d62541e13370e7f Mon Sep 17 00:00:00 2001 From: Peter Keuter Date: Wed, 24 Jan 2024 08:30:47 +0100 Subject: [PATCH] fix: check actual subgroup rights when clicking a subgroup (#26230) Signed-off-by: Peter Keuter --- .../src/groups/components/GroupTree.tsx | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/js/apps/admin-ui/src/groups/components/GroupTree.tsx b/js/apps/admin-ui/src/groups/components/GroupTree.tsx index 681f524a1695..44cb3e96e593 100644 --- a/js/apps/admin-ui/src/groups/components/GroupTree.tsx +++ b/js/apps/admin-ui/src/groups/components/GroupTree.tsx @@ -34,6 +34,10 @@ import { MoveDialog } from "./MoveDialog"; import "./group-tree.css"; +type ExtendedTreeViewDataItem = TreeViewDataItem & { + access?: Record; +}; + type GroupTreeContextMenuProps = { group: GroupRepresentation; refresh: () => void; @@ -137,7 +141,7 @@ export const GroupTree = ({ const { addAlert } = useAlerts(); const { hasAccess } = useAccess(); - const [data, setData] = useState(); + const [data, setData] = useState(); const { subGroups, clear } = useSubGroups(); const [search, setSearch] = useState(""); @@ -147,7 +151,7 @@ export const GroupTree = ({ const prefMax = useRef(20); const [count, setCount] = useState(0); const [exact, setExact] = useState(false); - const [activeItem, setActiveItem] = useState(); + const [activeItem, setActiveItem] = useState(); const [firstSub, setFirstSub] = useState(0); @@ -160,7 +164,7 @@ export const GroupTree = ({ const mapGroup = ( group: GroupRepresentation, refresh: () => void, - ): TreeViewDataItem => { + ): ExtendedTreeViewDataItem => { return { id: group.id, name: ( @@ -168,6 +172,7 @@ export const GroupTree = ({ {group.name} ), + access: group.access || {}, children: group.subGroups && group.subGroups.length > 0 ? group.subGroups.map((g) => mapGroup(g, refresh)) @@ -250,9 +255,9 @@ export const GroupTree = ({ ); const findGroup = ( - groups: TreeViewDataItem[], + groups: ExtendedTreeViewDataItem[], id: string, - path: TreeViewDataItem[], + path: ExtendedTreeViewDataItem[], ) => { for (let index = 0; index < groups.length; index++) { const group = groups[index]; @@ -316,8 +321,11 @@ export const GroupTree = ({ const path = findGroup(data, item.id!, []); if (!subGroups.every(({ id }) => path.find((t) => t.id === id))) clear(); - - if (canViewDetails || subGroups.at(-1)?.access?.view) { + if ( + canViewDetails || + path.at(-1)?.access?.view || + subGroups.at(-1)?.access?.view + ) { navigate( toGroups({ realm,