diff --git a/.changeset/clever-meals-drop.md b/.changeset/clever-meals-drop.md new file mode 100644 index 0000000000..63ceb1a4d3 --- /dev/null +++ b/.changeset/clever-meals-drop.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-api-docs': patch +--- + +Add permission check to Register Existing API button diff --git a/plugins/api-docs/package.json b/plugins/api-docs/package.json index 84e563655b..8f4db504f6 100644 --- a/plugins/api-docs/package.json +++ b/plugins/api-docs/package.json @@ -38,7 +38,9 @@ "@backstage/core-components": "workspace:^", "@backstage/core-plugin-api": "workspace:^", "@backstage/plugin-catalog": "workspace:^", + "@backstage/plugin-catalog-common": "workspace:^", "@backstage/plugin-catalog-react": "workspace:^", + "@backstage/plugin-permission-react": "workspace:^", "@graphiql/react": "^0.20.0", "@material-ui/core": "^4.12.2", "@material-ui/icons": "^4.9.1", diff --git a/plugins/api-docs/src/components/ApiExplorerPage/DefaultApiExplorerPage.test.tsx b/plugins/api-docs/src/components/ApiExplorerPage/DefaultApiExplorerPage.test.tsx index 6d0b191d68..7938770c4c 100644 --- a/plugins/api-docs/src/components/ApiExplorerPage/DefaultApiExplorerPage.test.tsx +++ b/plugins/api-docs/src/components/ApiExplorerPage/DefaultApiExplorerPage.test.tsx @@ -32,6 +32,7 @@ import { starredEntitiesApiRef, } from '@backstage/plugin-catalog-react'; import { + MockPermissionApi, MockStorageApi, TestApiProvider, renderInTestApp, @@ -41,6 +42,7 @@ import { screen, waitFor } from '@testing-library/react'; import React from 'react'; import { apiDocsConfigRef } from '../../config'; import { DefaultApiExplorerPage } from './DefaultApiExplorerPage'; +import { permissionApiRef } from '@backstage/plugin-permission-react'; describe('DefaultApiExplorerPage', () => { const catalogApi: Partial = { @@ -98,6 +100,7 @@ describe('DefaultApiExplorerPage', () => { new DefaultStarredEntitiesApi({ storageApi }), ], [apiDocsConfigRef, apiDocsConfig], + [permissionApiRef, new MockPermissionApi()], ]} > {children} diff --git a/plugins/api-docs/src/components/ApiExplorerPage/DefaultApiExplorerPage.tsx b/plugins/api-docs/src/components/ApiExplorerPage/DefaultApiExplorerPage.tsx index ad43205c5f..dc83c2528d 100644 --- a/plugins/api-docs/src/components/ApiExplorerPage/DefaultApiExplorerPage.tsx +++ b/plugins/api-docs/src/components/ApiExplorerPage/DefaultApiExplorerPage.tsx @@ -38,6 +38,8 @@ import { } from '@backstage/plugin-catalog-react'; import React from 'react'; import { registerComponentRouteRef } from '../../routes'; +import { usePermission } from '@backstage/plugin-permission-react'; +import { catalogEntityCreatePermission } from '@backstage/plugin-catalog-common/alpha'; const defaultColumns: TableColumn[] = [ CatalogTable.columns.createTitleColumn({ hidden: true }), @@ -72,6 +74,9 @@ export const DefaultApiExplorerPage = (props: DefaultApiExplorerPageProps) => { configApi.getOptionalString('organization.name') ?? 'Backstage' } API Explorer`; const registerComponentLink = useRouteRef(registerComponentRouteRef); + const { allowed } = usePermission({ + permission: catalogEntityCreatePermission, + }); return ( { > - + {allowed && ( + + )} All your APIs diff --git a/yarn.lock b/yarn.lock index 03478d5b50..6be53d3402 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4554,7 +4554,9 @@ __metadata: "@backstage/core-plugin-api": "workspace:^" "@backstage/dev-utils": "workspace:^" "@backstage/plugin-catalog": "workspace:^" + "@backstage/plugin-catalog-common": "workspace:^" "@backstage/plugin-catalog-react": "workspace:^" + "@backstage/plugin-permission-react": "workspace:^" "@backstage/test-utils": "workspace:^" "@graphiql/react": ^0.20.0 "@material-ui/core": ^4.12.2