Skip to content

Commit

Permalink
EVEREST-1712-fix-infinite-loop (#889)
Browse files Browse the repository at this point in the history
* EVEREST-1712-fix-infinite-loop

---------

Co-authored-by: solovevayaroslavna <[email protected]>
  • Loading branch information
solovevayaroslavna and solovevayaroslavna authored Dec 2, 2024
1 parent a54e5db commit 8e3f5a7
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions ui/apps/everest/src/hooks/rbac/rbac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export const useNamespacePermissionsForResource = (
create: [],
delete: [],
});
const { data: namespaces = [], isFetching } = useNamespaces();

const { data: namespaces, isFetching } = useNamespaces();

const checkPermissions = useCallback(async () => {
const newPermissions: Record<RBACAction, string[]> = {
Expand All @@ -79,24 +80,24 @@ export const useNamespacePermissionsForResource = (
};
const permissionsPromisesArr: Promise<void>[] = [];

for (const namespace of namespaces) {
['read', 'update', 'delete', 'create'].forEach((action) => {
permissionsPromisesArr.push(
can(
action as RBACAction,
resource,
`${namespace}/${specificResource}`
).then((canDo) => {
if (canDo) {
newPermissions[action as RBACAction].push(namespace);
}
})
);
});
if (namespaces) {
for (const namespace of namespaces) {
['read', 'update', 'delete', 'create'].forEach((action) => {
permissionsPromisesArr.push(
can(
action as RBACAction,
resource,
`${namespace}/${specificResource}`
).then((canDo) => {
if (canDo) {
newPermissions[action as RBACAction].push(namespace);
}
})
);
});
}
}

await Promise.all(permissionsPromisesArr);

setPermissions(newPermissions);
}, [namespaces, resource, specificResource]);

Expand Down

0 comments on commit 8e3f5a7

Please sign in to comment.