Merge pull request #9728 from backstage/jhaals/delete-loadIdentityOwnerRefs

catalog-react: Delete loadIdentityOwnerRefs, deprecate loadCatalogOwn…
This commit is contained in:
Johan Haals
2022-02-23 14:15:40 +01:00
committed by GitHub
6 changed files with 15 additions and 57 deletions
+7
View File
@@ -0,0 +1,7 @@
---
'@backstage/plugin-catalog-react': minor
---
**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.
+1 -7
View File
@@ -15,7 +15,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';
@@ -475,17 +474,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<string[]>;
// @public @deprecated
export function loadIdentityOwnerRefs(
identityApi: IdentityApi,
): Promise<string[]>;
// @public (undocumented)
export const MockEntityListContextProvider: ({
children,
+1 -5
View File
@@ -42,10 +42,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';
@@ -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<Pick<IdentityApi, 'getBackstageIdentity'>>;
@@ -101,18 +97,6 @@ describe('useEntityOwnership', () => {
jest.resetAllMocks();
});
describe('loadIdentityOwnerRefs', () => {
it('passes through the ownershipEntityRefs', async () => {
const refs = new Array<string>();
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);
@@ -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<string[]> {
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,
@@ -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