Fix permissions loading

Signed-off-by: Dominika Zemanovicova <dzemanov@redhat.com>
This commit is contained in:
Dominika Zemanovicova
2025-01-09 19:34:56 +01:00
parent 2f993dfc9c
commit 7d7497785f
6 changed files with 160 additions and 188 deletions
@@ -24,8 +24,8 @@ import {
useKubernetesClusterError,
} from '../KubernetesClusterErrorContext/KubernetesClusterErrorContext';
import { WarningPanel } from '@backstage/core-components';
import { useKubernetesClustersPermission } from '../../hooks/useKubernetesClustersPermission';
import { kubernetesClustersPermission } from '@backstage/plugin-kubernetes-common';
import { RequirePermission } from '@backstage/plugin-permission-react';
const ContentGrid = () => {
const { error } = useKubernetesClusterError();
@@ -59,17 +59,20 @@ const ContentGrid = () => {
* @public
*/
export const KubernetesClusterContent = () => {
const hasKubernetesClustersPermission = useKubernetesClustersPermission();
return !hasKubernetesClustersPermission ? (
<WarningPanel
title="Permission required"
message={`To view Kubernetes objects, contact your administrator to give you the
'${kubernetesClustersPermission.name}' permission.`}
/>
) : (
<KubernetesClusterErrorProvider>
<ContentGrid />
</KubernetesClusterErrorProvider>
return (
<RequirePermission
permission={kubernetesClustersPermission}
errorPage={
<WarningPanel
title="Permission required"
message={`To view Kubernetes objects, contact your administrator to give you the
'${kubernetesClustersPermission.name}' permission.`}
/>
}
>
<KubernetesClusterErrorProvider>
<ContentGrid />
</KubernetesClusterErrorProvider>
</RequirePermission>
);
};
@@ -1,26 +0,0 @@
/*
* Copyright 2025 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { kubernetesClustersPermission } from '@backstage/plugin-kubernetes-common';
import { usePermission } from '@backstage/plugin-permission-react';
export const useKubernetesClustersPermission = () => {
const kubernetesClustersPermissionResult = usePermission({
permission: kubernetesClustersPermission,
});
return kubernetesClustersPermissionResult.allowed;
};