Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rbac): add proper empty page for RBAC plugin #1728

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading