diff --git a/plugins/catalog-react/src/utils/isOwnerOf.ts b/plugins/catalog-react/src/utils/isOwnerOf.ts index e62a0db1ba..38ad90e4a6 100644 --- a/plugins/catalog-react/src/utils/isOwnerOf.ts +++ b/plugins/catalog-react/src/utils/isOwnerOf.ts @@ -16,10 +16,10 @@ import { Entity, - EntityName, getEntityName, RELATION_MEMBER_OF, RELATION_OWNED_BY, + stringifyEntityRef, } from '@backstage/catalog-model'; import { getEntityRelations } from './getEntityRelations'; @@ -27,22 +27,19 @@ import { getEntityRelations } from './getEntityRelations'; * Get the related entity references. */ export function isOwnerOf(owner: Entity, owned: Entity) { - const possibleOwners: EntityName[] = [ - ...getEntityRelations(owner, RELATION_MEMBER_OF, { kind: 'group' }), - ...(owner ? [getEntityName(owner)] : []), - ]; + const possibleOwners = new Set( + [ + ...getEntityRelations(owner, RELATION_MEMBER_OF, { kind: 'group' }), + ...(owner ? [getEntityName(owner)] : []), + ].map(stringifyEntityRef), + ); - const owners = getEntityRelations(owned, RELATION_OWNED_BY); + const owners = getEntityRelations(owned, RELATION_OWNED_BY).map( + stringifyEntityRef, + ); for (const ownerItem of owners) { - if ( - possibleOwners.find( - o => - ownerItem.kind.toLowerCase() === o.kind.toLowerCase() && - ownerItem.namespace.toLowerCase() === o.namespace.toLowerCase() && - ownerItem.name.toLowerCase() === o.name.toLowerCase(), - ) !== undefined - ) { + if (possibleOwners.has(ownerItem)) { return true; } }