From c4276915c07776881a4a11bee6f9fba53a2919ca Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Tue, 22 Feb 2022 14:47:14 +0100 Subject: [PATCH 1/2] catalog-react: Delete loadIdentityOwnerRefs, deprecate loadCatalogOwnerRefs Signed-off-by: Johan Haals --- .changeset/moody-elephants-float.md | 7 ++++++ plugins/catalog-react/api-report.md | 8 +----- plugins/catalog-react/src/hooks/index.ts | 6 +---- .../src/hooks/useEntityOwnership.test.tsx | 18 +------------ .../src/hooks/useEntityOwnership.ts | 25 ++----------------- .../src/hooks/useOwnedEntities.ts | 8 +++--- 6 files changed, 15 insertions(+), 57 deletions(-) create mode 100644 .changeset/moody-elephants-float.md diff --git a/.changeset/moody-elephants-float.md b/.changeset/moody-elephants-float.md new file mode 100644 index 0000000000..c637a870ec --- /dev/null +++ b/.changeset/moody-elephants-float.md @@ -0,0 +1,7 @@ +--- +'@backstage/plugin-catalog-react': minor +--- + +Deleted the deprecated `loadIdentityOwnerRefs` function which is replaced by `ownershipEntityRefs` from `identityApi.getBackstageIdentity()`. + +Deprecated the `loadCatalogOwnerRefs` hook as membership references should be added as `ent` inside `claims` sections of the `SignInResolver` when issuing tokens. See https://backstage.io/docs/auth/identity-resolver for more details on how to prepare your `SignInResolver` if not done already. Usage of the `loadCatalogOwnerRefs` hook should be replaced by `ownershipEntityRefs` from `identityApi.getBackstageIdentity()` instead. diff --git a/plugins/catalog-react/api-report.md b/plugins/catalog-react/api-report.md index 0a7bbbfc9e..ef5802aa52 100644 --- a/plugins/catalog-react/api-report.md +++ b/plugins/catalog-react/api-report.md @@ -16,7 +16,6 @@ import { Entity } from '@backstage/catalog-model'; import { EntityName } from '@backstage/catalog-model'; import { GetEntitiesResponse } from '@backstage/catalog-client'; import { IconButton } from '@material-ui/core'; -import { IdentityApi } from '@backstage/core-plugin-api'; import { LinkProps } from '@backstage/core-components'; import { Observable } from '@backstage/types'; import { Overrides } from '@material-ui/core/styles/overrides'; @@ -479,17 +478,12 @@ export function InspectEntityDialog(props: { // @public export function isOwnerOf(owner: Entity, owned: Entity): boolean; -// @public +// @public @deprecated export function loadCatalogOwnerRefs( catalogApi: CatalogApi, identityOwnerRefs: string[], ): Promise; -// @public @deprecated -export function loadIdentityOwnerRefs( - identityApi: IdentityApi, -): Promise; - // @public (undocumented) export const MockEntityListContextProvider: ({ children, diff --git a/plugins/catalog-react/src/hooks/index.ts b/plugins/catalog-react/src/hooks/index.ts index 170ea37394..a1d3cfac62 100644 --- a/plugins/catalog-react/src/hooks/index.ts +++ b/plugins/catalog-react/src/hooks/index.ts @@ -43,10 +43,6 @@ export { useOwnUser } from './useOwnUser'; export { useRelatedEntities } from './useRelatedEntities'; export { useStarredEntities } from './useStarredEntities'; export { useStarredEntity } from './useStarredEntity'; -export { - loadCatalogOwnerRefs, - useEntityOwnership, - loadIdentityOwnerRefs, -} from './useEntityOwnership'; +export { loadCatalogOwnerRefs, useEntityOwnership } from './useEntityOwnership'; export { useOwnedEntities } from './useOwnedEntities'; export { useEntityPermission } from './useEntityPermission'; diff --git a/plugins/catalog-react/src/hooks/useEntityOwnership.test.tsx b/plugins/catalog-react/src/hooks/useEntityOwnership.test.tsx index 7f838163a2..55d0d9299b 100644 --- a/plugins/catalog-react/src/hooks/useEntityOwnership.test.tsx +++ b/plugins/catalog-react/src/hooks/useEntityOwnership.test.tsx @@ -26,11 +26,7 @@ import { TestApiProvider } from '@backstage/test-utils'; import { renderHook } from '@testing-library/react-hooks'; import React from 'react'; import { catalogApiRef } from '../api'; -import { - loadCatalogOwnerRefs, - loadIdentityOwnerRefs, - useEntityOwnership, -} from './useEntityOwnership'; +import { loadCatalogOwnerRefs, useEntityOwnership } from './useEntityOwnership'; describe('useEntityOwnership', () => { type MockIdentityApi = jest.Mocked>; @@ -101,18 +97,6 @@ describe('useEntityOwnership', () => { jest.resetAllMocks(); }); - describe('loadIdentityOwnerRefs', () => { - it('passes through the ownershipEntityRefs', async () => { - const refs = new Array(); - mockIdentityApi.getBackstageIdentity.mockResolvedValueOnce({ - type: 'user', - userEntityRef: 'user:default/guest', - ownershipEntityRefs: refs, - }); - await expect(loadIdentityOwnerRefs(identityApi)).resolves.toBe(refs); - }); - }); - describe('loadCatalogOwnerRefs', () => { it('loads the first user from the catalog', async () => { mockCatalogApi.getEntityByName.mockResolvedValueOnce(user2Entity); diff --git a/plugins/catalog-react/src/hooks/useEntityOwnership.ts b/plugins/catalog-react/src/hooks/useEntityOwnership.ts index 1138dada1f..77f6c4bf24 100644 --- a/plugins/catalog-react/src/hooks/useEntityOwnership.ts +++ b/plugins/catalog-react/src/hooks/useEntityOwnership.ts @@ -23,34 +23,12 @@ import { RELATION_OWNED_BY, stringifyEntityRef, } from '@backstage/catalog-model'; -import { - IdentityApi, - identityApiRef, - useApi, -} from '@backstage/core-plugin-api'; +import { identityApiRef, useApi } from '@backstage/core-plugin-api'; import { useMemo } from 'react'; import useAsync from 'react-use/lib/useAsync'; import { catalogApiRef } from '../api'; import { getEntityRelations } from '../utils/getEntityRelations'; -/** - * Takes the relevant parts of the Backstage identity, and translates them into - * a list of entity refs on string form that represent the user's ownership - * connections. - * - * @public - * @deprecated Use `ownershipEntityRefs` from `identityApi.getBackstageIdentity()` instead. - * - * @param identityApi - The IdentityApi implementation - * @returns IdentityOwner refs as a string array - */ -export async function loadIdentityOwnerRefs( - identityApi: IdentityApi, -): Promise { - const identity = await identityApi.getBackstageIdentity(); - return identity.ownershipEntityRefs; -} - /** * Takes the relevant parts of the User entity corresponding to the Backstage * identity, and translates them into a list of entity refs on string form that @@ -61,6 +39,7 @@ export async function loadIdentityOwnerRefs( * @param catalogApi - The Catalog API implementation * @param identityOwnerRefs - List of identity owner refs as strings * @returns OwnerRefs as a string array + * @deprecated Use `ownershipEntityRefs` from `identityApi.getBackstageIdentity()` instead. */ export async function loadCatalogOwnerRefs( catalogApi: CatalogApi, diff --git a/plugins/catalog-react/src/hooks/useOwnedEntities.ts b/plugins/catalog-react/src/hooks/useOwnedEntities.ts index dad73740c1..dbbd499d13 100644 --- a/plugins/catalog-react/src/hooks/useOwnedEntities.ts +++ b/plugins/catalog-react/src/hooks/useOwnedEntities.ts @@ -14,10 +14,7 @@ * limitations under the License. */ import { catalogApiRef } from './../api'; -import { - loadCatalogOwnerRefs, - loadIdentityOwnerRefs, -} from './useEntityOwnership'; +import { loadCatalogOwnerRefs } from './useEntityOwnership'; import { identityApiRef, useApi } from '@backstage/core-plugin-api'; import { RELATION_OWNED_BY } from '@backstage/catalog-model'; import { GetEntitiesResponse } from '@backstage/catalog-client'; @@ -41,7 +38,8 @@ export function useOwnedEntities(allowedKinds?: string[]): { const catalogApi = useApi(catalogApiRef); const { loading, value: refs } = useAsync(async () => { - const identityRefs = await loadIdentityOwnerRefs(identityApi); + const identity = await identityApi.getBackstageIdentity(); + const identityRefs = identity.ownershipEntityRefs; const catalogRefs = await loadCatalogOwnerRefs(catalogApi, identityRefs); const catalogs = await catalogApi.getEntities( allowedKinds From 8286e40f1320b97d863c1801e0fae29d4b31ce1b Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Tue, 22 Feb 2022 16:00:16 +0100 Subject: [PATCH 2/2] prefix with breaking Signed-off-by: Johan Haals --- .changeset/moody-elephants-float.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/moody-elephants-float.md b/.changeset/moody-elephants-float.md index c637a870ec..4fbe1afa18 100644 --- a/.changeset/moody-elephants-float.md +++ b/.changeset/moody-elephants-float.md @@ -2,6 +2,6 @@ '@backstage/plugin-catalog-react': minor --- -Deleted the deprecated `loadIdentityOwnerRefs` function which is replaced by `ownershipEntityRefs` from `identityApi.getBackstageIdentity()`. +**BREAKING**: Deleted the deprecated `loadIdentityOwnerRefs` function which is replaced by `ownershipEntityRefs` from `identityApi.getBackstageIdentity()`. Deprecated the `loadCatalogOwnerRefs` hook as membership references should be added as `ent` inside `claims` sections of the `SignInResolver` when issuing tokens. See https://backstage.io/docs/auth/identity-resolver for more details on how to prepare your `SignInResolver` if not done already. Usage of the `loadCatalogOwnerRefs` hook should be replaced by `ownershipEntityRefs` from `identityApi.getBackstageIdentity()` instead.