Skip to content

Commit 79e62a6

Browse files
authored
fix(rbac): add proper empty page for RBAC plugin (#1728)
* fix(rbac): add proper empty page for RBAC plugin Signed-off-by: Yi Cai <[email protected]> * Updated unite test Signed-off-by: Yi Cai <[email protected]> * Updated error message Signed-off-by: Yi Cai <[email protected]> --------- Signed-off-by: Yi Cai <[email protected]>
1 parent b39bc17 commit 79e62a6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

plugins/rbac/src/components/Router.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ jest.mock('./CreateRole/EditRolePage', () => ({
3232
EditRolePage: () => <div>EditRole</div>,
3333
}));
3434

35+
jest.mock('@backstage/core-components', () => ({
36+
ErrorPage: jest.fn().mockImplementation(() => <div>Mocked ErrorPage</div>),
37+
}));
38+
3539
jest.mock('@backstage/plugin-permission-react', () => ({
3640
RequirePermission: jest
3741
.fn()
@@ -67,6 +71,17 @@ describe('Router component', () => {
6771
expect(screen.queryByText('RBAC')).not.toBeInTheDocument();
6872
});
6973

74+
it('should render ErrorPage when rbac-backend plugin is disabled', () => {
75+
configMock.getOptionalBoolean.mockReturnValueOnce(false);
76+
render(
77+
<MemoryRouter initialEntries={['/']}>
78+
<Router />
79+
</MemoryRouter>,
80+
);
81+
82+
expect(screen.queryByText('Mocked ErrorPage')).toBeInTheDocument();
83+
});
84+
7085
it('renders RoleOverviewPage when path matches roleRouteRef', () => {
7186
render(
7287
<MemoryRouter initialEntries={['/roles/user/testns/testname']}>

plugins/rbac/src/components/Router.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { Route, Routes } from 'react-router-dom';
33

4+
import { ErrorPage } from '@backstage/core-components';
45
import { configApiRef, useApi } from '@backstage/core-plugin-api';
56
import { RequirePermission } from '@backstage/plugin-permission-react';
67

@@ -25,7 +26,13 @@ export const Router = ({ useHeader = true }: { useHeader?: boolean }) => {
2526
const isRBACPluginEnabled = config.getOptionalBoolean('permission.enabled');
2627

2728
if (!isRBACPluginEnabled) {
28-
return null;
29+
return (
30+
<ErrorPage
31+
status="404"
32+
statusMessage="Enable the RBAC backend plugin to use this feature."
33+
additionalInfo="To enable RBAC, set `permission.enabled` to `true` in the app-config file."
34+
/>
35+
);
2936
}
3037

3138
return (

0 commit comments

Comments
 (0)