From 0f5270de06f0566435786de1fc8f6279b5cde89c Mon Sep 17 00:00:00 2001 From: Valentin Yanakiev Date: Wed, 7 Aug 2024 10:52:50 +0300 Subject: [PATCH] filter out orphans for contributions --- package-lock.json | 4 ++-- package.json | 2 +- src/services/api/me/me.service.ts | 38 ++++++++++++++++++++----------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1761e1a26f..e238658aa8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "alkemio-server", - "version": "0.86.0", + "version": "0.86.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "alkemio-server", - "version": "0.86.0", + "version": "0.86.1", "license": "EUPL-1.2", "dependencies": { "@alkemio/matrix-adapter-lib": "^0.4.1", diff --git a/package.json b/package.json index 1449d0056c..a1b1a2ac9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "alkemio-server", - "version": "0.86.0", + "version": "0.86.1", "description": "Alkemio server, responsible for managing the shared Alkemio platform", "author": "Alkemio Foundation", "private": false, diff --git a/src/services/api/me/me.service.ts b/src/services/api/me/me.service.ts index 29bba8f75d..d4660be383 100644 --- a/src/services/api/me/me.service.ts +++ b/src/services/api/me/me.service.ts @@ -12,10 +12,7 @@ import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston'; import { sortSpacesByActivity } from '@domain/space/space/sort.spaces.by.activity'; import { CommunityInvitationResult } from './dto/me.invitation.result'; import { CommunityResolverService } from '@services/infrastructure/entity-resolver/community.resolver.service'; -import { - EntityNotFoundException, - RelationshipNotFoundException, -} from '@common/exceptions'; +import { EntityNotFoundException } from '@common/exceptions'; import { CommunityApplicationResult } from './dto/me.application.result'; import { ContributorService } from '@domain/community/contributor/contributor.service'; import { UserService } from '@domain/community/user/user.service'; @@ -101,25 +98,40 @@ export class MeService { const spaceIds = Array.from(credentialMap.get('spaces')?.keys() ?? []); const allSpaces = await this.spaceService.getSpacesInList(spaceIds); + const validSpaces = this.filterValidSpaces(allSpaces); + const spaceMembershipCollaborationInfo = + this.getSpaceMembershipCollaborationInfo(validSpaces); + const latestActivitiesPerSpace = + await this.activityService.getLatestActivitiesPerSpaceMembership( + agentInfo.userID, + spaceMembershipCollaborationInfo + ); + return sortSpacesByActivity(validSpaces, latestActivitiesPerSpace); + } + + /** + * Function that returns all spaces that are valid (L1 and L2 spaces have parents) + * @param allSpaces all spaces to be filtered out + * @returns spaces that are valid (L1 and L2 spaces have parents). + * Orphaned spaces are logged as warnings and filtered out, also spaces without collaboration are filtered out. + */ + private filterValidSpaces(allSpaces: ISpace[]) { + const validSpaces = []; + for (const space of allSpaces) { if ( (space.level !== SpaceLevel.SPACE && !space.parentSpace) || !space.collaboration ) { - throw new RelationshipNotFoundException( + this.logger.warn( `Space ${space.id} is missing parent space or collaboration`, LogContext.COMMUNITY ); + } else { + validSpaces.push(space); } } - const spaceMembershipCollaborationInfo = - this.getSpaceMembershipCollaborationInfo(allSpaces); - const latestActivitiesPerSpace = - await this.activityService.getLatestActivitiesPerSpaceMembership( - agentInfo.userID, - spaceMembershipCollaborationInfo - ); - return sortSpacesByActivity(allSpaces, latestActivitiesPerSpace); + return validSpaces; } public async getSpaceMembershipsFlat(