Skip to content

Commit

Permalink
Merge pull request #5177 from backstage/freben/group-members
Browse files Browse the repository at this point in the history
Make sure that Group  is taken into account when filling out an org hierarchy
  • Loading branch information
benjdlambert committed Mar 30, 2021
2 parents e3f7335 + 29e1789 commit ee01dcf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/old-hounds-doubt.md
@@ -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
18 changes: 18 additions & 0 deletions plugins/catalog-backend/src/ingestion/processors/util/org.test.ts
Expand Up @@ -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']));
});
});
8 changes: 7 additions & 1 deletion plugins/catalog-backend/src/ingestion/processors/util/org.ts
Expand Up @@ -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) {
Expand Down

0 comments on commit ee01dcf

Please sign in to comment.