Skip to content

Commit

Permalink
fix: check actual subgroup rights when clicking a subgroup (keycloak#…
Browse files Browse the repository at this point in the history
…26230)

Signed-off-by: Peter Keuter <[email protected]>
  • Loading branch information
pkeuter authored Jan 24, 2024
1 parent 00fdb8e commit a0bcf35
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions js/apps/admin-ui/src/groups/components/GroupTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ import { MoveDialog } from "./MoveDialog";

import "./group-tree.css";

type ExtendedTreeViewDataItem = TreeViewDataItem & {
access?: Record<string, boolean>;
};

type GroupTreeContextMenuProps = {
group: GroupRepresentation;
refresh: () => void;
Expand Down Expand Up @@ -137,7 +141,7 @@ export const GroupTree = ({
const { addAlert } = useAlerts();
const { hasAccess } = useAccess();

const [data, setData] = useState<TreeViewDataItem[]>();
const [data, setData] = useState<ExtendedTreeViewDataItem[]>();
const { subGroups, clear } = useSubGroups();

const [search, setSearch] = useState("");
Expand All @@ -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<TreeViewDataItem>();
const [activeItem, setActiveItem] = useState<ExtendedTreeViewDataItem>();

const [firstSub, setFirstSub] = useState(0);

Expand All @@ -160,14 +164,15 @@ export const GroupTree = ({
const mapGroup = (
group: GroupRepresentation,
refresh: () => void,
): TreeViewDataItem => {
): ExtendedTreeViewDataItem => {
return {
id: group.id,
name: (
<Tooltip content={group.name}>
<span>{group.name}</span>
</Tooltip>
),
access: group.access || {},
children:
group.subGroups && group.subGroups.length > 0
? group.subGroups.map((g) => mapGroup(g, refresh))
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a0bcf35

Please sign in to comment.