1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-21 06:19:41 +02:00

fix showing namespaces for standard user (#7917)

This commit is contained in:
Prabhat Khera 2022-10-27 16:14:54 +13:00 committed by GitHub
parent 446febb0f6
commit a550bfaedb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 7 deletions

View file

@ -2,13 +2,29 @@ import { useQuery } from 'react-query';
import { EnvironmentId } from '@/react/portainer/environments/types';
import { error as notifyError } from '@/portainer/services/notifications';
import { getIngresses } from '@/kubernetes/react/views/networks/ingresses/service';
import { getNamespaces, getNamespace } from './service';
import { Namespaces } from './types';
export function useNamespaces(environmentId: EnvironmentId) {
return useQuery(
['environments', environmentId, 'kubernetes', 'namespaces'],
() => getNamespaces(environmentId),
async () => {
const namespaces = await getNamespaces(environmentId);
const settledNamespacesPromise = await Promise.allSettled(
Object.keys(namespaces).map((namespace) =>
getIngresses(environmentId, namespace).then(() => namespace)
)
);
const ns: Namespaces = {};
settledNamespacesPromise.forEach((namespace) => {
if (namespace.status === 'fulfilled') {
ns[namespace.value] = namespaces[namespace.value];
}
});
return ns;
},
{
onError: (err) => {
notifyError('Failure', err as Error, 'Unable to get namespaces.');