From 94df37238a7459c0f7e4cd7769243b7b257c47e9 Mon Sep 17 00:00:00 2001 From: Stan Silvert Date: Fri, 17 Feb 2023 13:23:02 -0500 Subject: [PATCH] Make role restrictions on group tree match group table. (#4418) --- apps/admin-ui/src/groups/GroupTable.tsx | 11 +++++---- apps/admin-ui/src/groups/GroupsSection.tsx | 17 ++++++++++--- .../src/groups/components/GroupTree.tsx | 24 ++++++++++++------- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/apps/admin-ui/src/groups/GroupTable.tsx b/apps/admin-ui/src/groups/GroupTable.tsx index abc5c424b8..75020a3583 100644 --- a/apps/admin-ui/src/groups/GroupTable.tsx +++ b/apps/admin-ui/src/groups/GroupTable.tsx @@ -21,9 +21,13 @@ import { MoveDialog } from "./components/MoveDialog"; type GroupTableProps = { refresh: () => void; + canViewDetails: boolean; }; -export const GroupTable = ({ refresh: viewRefresh }: GroupTableProps) => { +export const GroupTable = ({ + refresh: viewRefresh, + canViewDetails, +}: GroupTableProps) => { const { t } = useTranslation("groups"); const { adminClient } = useAdminClient(); @@ -47,9 +51,6 @@ export const GroupTable = ({ refresh: viewRefresh }: GroupTableProps) => { const { hasAccess } = useAccess(); const isManager = hasAccess("manage-users") || currentGroup()?.access?.manage; - const canView = - hasAccess("query-groups", "view-users") || - hasAccess("manage-users", "query-groups"); const loader = async (first?: number, max?: number) => { const params: Record = { @@ -87,7 +88,7 @@ export const GroupTable = ({ refresh: viewRefresh }: GroupTableProps) => { }; const GroupNameCell = (group: GroupRepresentation) => { - if (!canView) return {group.name}; + if (!canViewDetails) return {group.name}; return ( { @@ -167,7 +170,10 @@ export default function GroupsSection() { eventKey={0} title={{t("childGroups")}} > - + )} - {subGroups.length === 0 && } + {subGroups.length === 0 && ( + + )} } > - + diff --git a/apps/admin-ui/src/groups/components/GroupTree.tsx b/apps/admin-ui/src/groups/components/GroupTree.tsx index a53579fe8d..227f452feb 100644 --- a/apps/admin-ui/src/groups/components/GroupTree.tsx +++ b/apps/admin-ui/src/groups/components/GroupTree.tsx @@ -101,9 +101,13 @@ const GroupTreeContextMenu = ({ type GroupTreeProps = { refresh: () => void; + canViewDetails: boolean; }; -export const GroupTree = ({ refresh: viewRefresh }: GroupTreeProps) => { +export const GroupTree = ({ + refresh: viewRefresh, + canViewDetails, +}: GroupTreeProps) => { const { t } = useTranslation("groups"); const { adminClient } = useAdminClient(); const { realm } = useRealm(); @@ -132,19 +136,23 @@ export const GroupTree = ({ refresh: viewRefresh }: GroupTreeProps) => { id: group.id, name: ( - g.id!))}`} - onClick={() => setSubGroups(groups)} - > - {group.name} - + {(canViewDetails && ( + g.id!))}`} + onClick={() => setSubGroups(groups)} + > + {group.name} + + )) || {group.name}} ), children: group.subGroups && group.subGroups.length > 0 ? group.subGroups.map((g) => mapGroup(g, groups, refresh)) : undefined, - action: , + action: canViewDetails && ( + + ), defaultExpanded: subGroups.map((g) => g.id).includes(group.id), }; };