Make sure that Group is taken into account when filling out an org hierarchy

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2021-03-30 09:31:25 +02:00
parent 23a7ffc960
commit 29e1789e1d
3 changed files with 30 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend': patch
---
Make sure that Group `spec.members` is taken into account when filling out an org hierarchy
@@ -73,4 +73,22 @@ describe('buildMemberOf', () => {
buildMemberOf(groups, [u]);
expect(u.spec.memberOf).toEqual(expect.arrayContaining(['a', 'b', 'c']));
});
it('takes group spec.members into account', () => {
const a = g('a', undefined, []);
const b = g('b', 'a', []);
const c = g('c', 'b', []);
c.spec.members = ['n'];
const u: UserEntity = {
apiVersion: 'backstage.io/v1alpha1',
kind: 'User',
metadata: { name: 'n' },
spec: { profile: {}, memberOf: [] },
};
const groups = [a, b, c];
buildOrgHierarchy(groups);
buildMemberOf(groups, [u]);
expect(u.spec.memberOf).toEqual(expect.arrayContaining(['a', 'b', 'c']));
});
});
@@ -57,7 +57,13 @@ export function buildMemberOf(groups: GroupEntity[], users: UserEntity[]) {
users.forEach(user => {
const transitiveMemberOf = new Set<string>();
const todo = [...user.spec.memberOf];
const todo = [
...user.spec.memberOf,
...groups
.filter(g => g.spec.members?.includes(user.metadata.name))
.map(g => g.metadata.name),
];
for (;;) {
const current = todo.pop();
if (!current) {