Skip to content

Commit

Permalink
fix(rbac): add proper empty page for RBAC plugin (janus-idp#1728)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
ciiay authored Jun 3, 2024
1 parent b39bc17 commit 79e62a6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
15 changes: 15 additions & 0 deletions plugins/rbac/src/components/Router.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jest.mock('./CreateRole/EditRolePage', () => ({
EditRolePage: () => <div>EditRole</div>,
}));

jest.mock('@backstage/core-components', () => ({
ErrorPage: jest.fn().mockImplementation(() => <div>Mocked ErrorPage</div>),
}));

jest.mock('@backstage/plugin-permission-react', () => ({
RequirePermission: jest
.fn()
Expand Down Expand Up @@ -67,6 +71,17 @@ describe('Router component', () => {
expect(screen.queryByText('RBAC')).not.toBeInTheDocument();
});

it('should render ErrorPage when rbac-backend plugin is disabled', () => {
configMock.getOptionalBoolean.mockReturnValueOnce(false);
render(
<MemoryRouter initialEntries={['/']}>
<Router />
</MemoryRouter>,
);

expect(screen.queryByText('Mocked ErrorPage')).toBeInTheDocument();
});

it('renders RoleOverviewPage when path matches roleRouteRef', () => {
render(
<MemoryRouter initialEntries={['/roles/user/testns/testname']}>
Expand Down
9 changes: 8 additions & 1 deletion plugins/rbac/src/components/Router.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Route, Routes } from 'react-router-dom';

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

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

if (!isRBACPluginEnabled) {
return null;
return (
<ErrorPage
status="404"
statusMessage="Enable the RBAC backend plugin to use this feature."
additionalInfo="To enable RBAC, set `permission.enabled` to `true` in the app-config file."
/>
);
}

return (
Expand Down

0 comments on commit 79e62a6

Please sign in to comment.