Merge pull request #23990 from marleypowell/patch-2

fix: retrieve relations when mapping group entities for notifications
This commit is contained in:
Fredrik Adelöw
2024-04-09 14:04:58 +02:00
committed by GitHub
2 changed files with 29 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-notifications-backend': patch
---
fix: retrieve relations and children when mapping group entities for notifications
@@ -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 },
);