diff --git a/.changeset/sour-ways-repeat.md b/.changeset/sour-ways-repeat.md new file mode 100644 index 0000000000..ad6b25bbea --- /dev/null +++ b/.changeset/sour-ways-repeat.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-notifications-backend': patch +--- + +fix: retrieve relations and children when mapping group entities for notifications diff --git a/plugins/notifications-backend/src/service/router.ts b/plugins/notifications-backend/src/service/router.ts index 9f16f45248..ea988d851b 100644 --- a/plugins/notifications-backend/src/service/router.ts +++ b/plugins/notifications-backend/src/service/router.ts @@ -28,6 +28,7 @@ import { isGroupEntity, isUserEntity, RELATION_HAS_MEMBER, + RELATION_PARENT_OF, stringifyEntityRef, } from '@backstage/catalog-model'; import { NotificationProcessor } from '@backstage/plugin-notifications-node'; @@ -102,7 +103,13 @@ export async function createRouter( const entities = await catalogClient.getEntitiesByRefs( { entityRefs: refs, - fields: ['kind', 'metadata.name', 'metadata.namespace'], + fields: [ + 'kind', + 'metadata.name', + 'metadata.namespace', + 'relations', + 'spec.owner', + ], }, { token }, ); @@ -120,10 +127,24 @@ export async function createRouter( relation.type === RELATION_HAS_MEMBER && relation.targetRef, ) .map(r => r.targetRef); + + const childGroupRefs = entity.relations + .filter( + relation => + relation.type === RELATION_PARENT_OF && relation.targetRef, + ) + .map(r => r.targetRef); + const childGroups = await catalogClient.getEntitiesByRefs( { - entityRefs: entity.spec.children, - fields: ['kind', 'metadata.name', 'metadata.namespace'], + entityRefs: childGroupRefs, + fields: [ + 'kind', + 'metadata.name', + 'metadata.namespace', + 'relations', + 'spec.owner', + ], }, { token }, );