Merge pull request #10205 from backstage/freben/optional-memberof

This commit is contained in:
Fredrik Adelöw
2022-03-15 16:34:52 +01:00
committed by GitHub
9 changed files with 35 additions and 7 deletions
+8
View File
@@ -0,0 +1,8 @@
---
'@backstage/plugin-catalog-backend-module-github': patch
'@backstage/plugin-catalog-backend-module-ldap': patch
'@backstage/plugin-catalog-backend-module-msgraph': patch
'@backstage/plugin-org': patch
---
Updated the code to handle User kind `spec.memberOf` now being optional.
+14
View File
@@ -0,0 +1,14 @@
---
'@backstage/catalog-model': minor
---
**BREAKING**: The User kind has an updated TypeScript type where `spec.memberOf`
is optional.
**NOTE HOWEVER**, that this only applies to the TypeScript types `UserEntity`
and `UserEntityV1alpha1`. The catalog validation still requires the field to be
set, even if it's in the form of an empty array. If you try to ingest data that
stops producing this field, those entities _will be rejected_ by the catalog.
The reason for these choices is that consumers will get a long grace period
where old code still can rely on the underlying data being present, giving users
ample time to update before actual breakages could happen.
+1 -1
View File
@@ -447,7 +447,7 @@ interface UserEntityV1alpha1 extends Entity {
email?: string;
picture?: string;
};
memberOf: string[];
memberOf?: string[];
};
}
export { UserEntityV1alpha1 as UserEntity };
@@ -32,7 +32,7 @@ export interface UserEntityV1alpha1 extends Entity {
email?: string;
picture?: string;
};
memberOf: string[];
memberOf?: string[];
};
}
@@ -58,7 +58,10 @@ export function assignGroupsToUsers(
for (const [groupName, userNames] of groupMemberUsers.entries()) {
for (const userName of userNames) {
const user = usersByName.get(userName);
if (user && !user.spec.memberOf.includes(groupName)) {
if (user && !user.spec.memberOf?.includes(groupName)) {
if (!user.spec.memberOf) {
user.spec.memberOf = [];
}
user.spec.memberOf.push(groupName);
}
}
@@ -74,7 +77,7 @@ export function buildMemberOf(groups: GroupEntity[], users: UserEntity[]) {
const transitiveMemberOf = new Set<string>();
const todo = [
...user.spec.memberOf,
...(user.spec.memberOf ?? []),
...groups
.filter(g => g.spec.members?.includes(user.metadata.name))
.map(g => g.metadata.name),
@@ -61,7 +61,7 @@ export function buildMemberOf(groups: GroupEntity[], users: UserEntity[]) {
const transitiveMemberOf = new Set<string>();
const todo = [
...user.spec.memberOf,
...(user.spec.memberOf ?? []),
...groups
.filter(g => g.spec.members?.includes(user.metadata.name))
.map(g => g.metadata.name),
@@ -61,7 +61,7 @@ export function buildMemberOf(groups: GroupEntity[], users: UserEntity[]) {
const transitiveMemberOf = new Set<string>();
const todo = [
...user.spec.memberOf,
...(user.spec.memberOf ?? []),
...groups
.filter(g => g.spec.members?.includes(user.metadata.name))
.map(g => g.metadata.name),
@@ -507,6 +507,9 @@ export function resolveRelations(
retrieveItems(groupMemberOf, id).forEach(p => {
const parentGroup = groupMap.get(p);
if (parentGroup) {
if (!user.spec.memberOf) {
user.spec.memberOf = [];
}
user.spec.memberOf.push(stringifyEntityRef(parentGroup));
}
});
@@ -118,7 +118,7 @@ const getQueryParams = (
};
if (owner.kind === 'User') {
const user = owner as UserEntity;
filters.owners = [...filters.owners, ...user.spec.memberOf];
filters.owners = [...filters.owners, ...(user.spec.memberOf ?? [])];
}
const queryParams = qs.stringify(
{