From 976fa19b0192b4efe1f6fdbb9344ff770e8abfe2 Mon Sep 17 00:00:00 2001 From: Igor Richter Date: Fri, 29 Sep 2023 03:53:47 +0200 Subject: [PATCH] orchestration removal of group and groupUsers --- .../oidc/service/oidc-provisioning.service.ts | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.ts b/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.ts index 179af9eb370..ec6d17e0e61 100644 --- a/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.ts +++ b/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.ts @@ -193,11 +193,30 @@ export class OidcProvisioningService { ): Promise { const existingGroupsOfUser: Group[] = await this.groupService.findByUserId(externalUserId); // TODO implement service and repo function - const groupsWithoutUser: Group[] = await Promise.all( - existingGroupsOfUser.map(async (existingGroup: Group): Promise => { - // TODO check for existingGroup not in externalGroups[] and remove user from this group + const externalGroupsExternalSources: ExternalSource[] = externalGroups.forEach( + (externalGroup: ExternalGroupDto): ExternalSource => { + const externalGroupId: ExternalSource = { externalId: externalGroup.externalId, systemId }; + + return externalGroupId; + } + ); + + await Promise.all( + existingGroupsOfUser.map(async (existingGroup: Group): Promise => { + if (existingGroup.externalSource) { + const isGroupWithoutUser = !externalGroupsExternalSources.includes(existingGroup.externalSource); + + if (isGroupWithoutUser) { + await this.groupService.deleteUserFromGroup(externalUserId, existingGroup.externalSource); // TODO implement service and repo function + + const groupUsers: GroupUser[] = await this.groupService.getUsersOfGroup(existingGroup.externalSource); // TODO implement service and repo function + + if (groupUsers.length === 0) { + await this.groupService.deleteGroup(existingGroup.externalSource); // TODO implement service and repo function + } + } + } }) ); - // TODO remove all groupsWithoutUser.length === 0 } }