Fix review comments

This commit is contained in:
Dominik Henneke
2020-11-30 21:54:55 +01:00
parent 6e2290a630
commit 811ca4bbb2
3 changed files with 14 additions and 15 deletions
@@ -25,7 +25,7 @@ describe('isOwnerOf', () => {
it('should be owned by user', () => {
const ownerEntity = {
kind: 'User',
metadata: { name: 'user' },
metadata: { name: 'User', namespace: 'Default' },
} as Entity;
const ownedEntity = {
relations: [
+2 -2
View File
@@ -39,8 +39,8 @@ export function isOwnerOf(owner: Entity, owned: Entity) {
possibleOwners.find(
o =>
owner.kind.toLowerCase() === o.kind.toLowerCase() &&
owner.namespace === o.namespace &&
owner.name === o.name,
owner.namespace.toLowerCase() === o.namespace.toLowerCase() &&
owner.name.toLowerCase() === o.name.toLowerCase(),
) !== undefined
) {
return true;
+11 -12
View File
@@ -16,26 +16,25 @@
import { UserEntity } from '@backstage/catalog-model';
import { useAsync } from 'react-use';
import { AsyncState } from 'react-use/lib/useAsync';
import { identityApiRef, useApi } from '@backstage/core';
import { catalogApiRef } from '../plugin';
/**
* Get the group memberships of the logged-in user.
*/
export function useOwnUser(): {
value?: UserEntity;
loading: boolean;
error?: Error;
} {
export function useOwnUser(): AsyncState<UserEntity> {
const catalogApi = useApi(catalogApiRef);
const identityApi = useApi(identityApiRef);
// TODO: get the full entity (or at least the full entity name) from the identityApi
return useAsync(async () => {
return (await catalogApi.getEntityByName({
kind: 'User',
namespace: 'default',
name: identityApi.getUserId(),
})) as UserEntity;
}, [catalogApi, identityApi]);
return useAsync(
() =>
catalogApi.getEntityByName({
kind: 'User',
namespace: 'default',
name: identityApi.getUserId(),
}) as Promise<UserEntity>,
[catalogApi, identityApi],
);
}