From 264924a309983fdb7bf319327419dda549ebc952 Mon Sep 17 00:00:00 2001 From: Valentin Yanakiev Date: Wed, 31 Jul 2024 10:55:09 +0300 Subject: [PATCH] 'not initilized' exception fixed while saving Whiteboard (#4331) * fixed "not initialized" bug * decreased data loaded while updating whiteboard content * Minor version bump --------- Co-authored-by: Valentin Yanakiev --- package-lock.json | 4 ++-- package.json | 2 +- .../common/whiteboard/whiteboard.service.ts | 15 ++++++++++-- .../profile.documents.service.ts | 13 +++-------- .../storage-bucket/storage.bucket.service.ts | 23 +++++-------------- 5 files changed, 25 insertions(+), 32 deletions(-) diff --git a/package-lock.json b/package-lock.json index 014fb3e8f3..896f28ffc6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "alkemio-server", - "version": "0.84.9", + "version": "0.84.10", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "alkemio-server", - "version": "0.84.9", + "version": "0.84.10", "license": "EUPL-1.2", "dependencies": { "@alkemio/matrix-adapter-lib": "^0.4.1", diff --git a/package.json b/package.json index 1e67e23da0..2768a55fa2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "alkemio-server", - "version": "0.84.9", + "version": "0.84.10", "description": "Alkemio server, responsible for managing the shared Alkemio platform", "author": "Alkemio Foundation", "private": false, diff --git a/src/domain/common/whiteboard/whiteboard.service.ts b/src/domain/common/whiteboard/whiteboard.service.ts index 90b5d930bb..039b929a02 100644 --- a/src/domain/common/whiteboard/whiteboard.service.ts +++ b/src/domain/common/whiteboard/whiteboard.service.ts @@ -295,15 +295,26 @@ export class WhiteboardService { return whiteboardContent; } + const profile = await this.profileService.getProfileOrFail( + profileIdToCheck, + { + relations: { + storageBucket: { + documents: true, + }, + }, + } + ); + for (const [, file] of files) { if (!file.url) { continue; } const newDocUrl = - await this.profileDocumentsService.reuploadDocumentsToProfile( + await this.profileDocumentsService.reuploadDocumentToProfile( file.url, - profileIdToCheck + profile ); if (!newDocUrl) { diff --git a/src/domain/profile-documents/profile.documents.service.ts b/src/domain/profile-documents/profile.documents.service.ts index 71f3b73685..0517dc582f 100644 --- a/src/domain/profile-documents/profile.documents.service.ts +++ b/src/domain/profile-documents/profile.documents.service.ts @@ -6,6 +6,7 @@ import { StorageBucketService } from '@domain/storage/storage-bucket/storage.buc import { DocumentAuthorizationService } from '@domain/storage/document/document.service.authorization'; import { EntityNotInitializedException } from '@common/exceptions'; import { ProfileService } from '@domain/common/profile/profile.service'; +import { IProfile } from '@domain/common/profile'; @Injectable() export class ProfileDocumentsService { @@ -20,9 +21,9 @@ export class ProfileDocumentsService { * Checks if a document is living under the storage bucket * of a profile and adds it if not there */ - public async reuploadDocumentsToProfile( + public async reuploadDocumentToProfile( fileUrl: string, - profileId: string + profile: IProfile ): Promise { if (!this.documentService.isAlkemioDocumentURL(fileUrl)) { throw new BaseException( @@ -32,14 +33,6 @@ export class ProfileDocumentsService { ); } - const profile = await this.profileService.getProfileOrFail(profileId, { - relations: { - storageBucket: { - documents: true, - }, - }, - }); - const storageBucketToCheck = profile.storageBucket; if (!storageBucketToCheck) { diff --git a/src/domain/storage/storage-bucket/storage.bucket.service.ts b/src/domain/storage/storage-bucket/storage.bucket.service.ts index 8d9ae6efb2..0736ac807a 100644 --- a/src/domain/storage/storage-bucket/storage.bucket.service.ts +++ b/src/domain/storage/storage-bucket/storage.bucket.service.ts @@ -1,7 +1,6 @@ import { AuthorizationPrivilege } from '@common/enums/authorization.privilege'; import { LogContext } from '@common/enums/logging.context'; import { EntityNotFoundException } from '@common/exceptions/entity.not.found.exception'; -import { EntityNotInitializedException } from '@common/exceptions/entity.not.initialized.exception'; import { limitAndShuffle } from '@common/utils/limitAndShuffle'; import { AgentInfo } from '@core/authentication.agent.info/agent.info'; import { AuthorizationService } from '@core/authorization/authorization.service'; @@ -188,9 +187,8 @@ export class StorageBucketService { /* just consume */ } - const document = await this.documentService.createDocument( - createDocumentInput - ); + const document = + await this.documentService.createDocument(createDocumentInput); document.storageBucket = storage; this.logger.verbose?.( @@ -215,9 +213,8 @@ export class StorageBucketService { LogContext.DOCUMENT ); - const documentForReference = await this.documentService.getDocumentFromURL( - uri - ); + const documentForReference = + await this.documentService.getDocumentFromURL(uri); try { const newDocument = await this.uploadFileAsDocument( @@ -255,15 +252,7 @@ export class StorageBucketService { storageBucketId: string, document: IDocument ): Promise | never { - const storage = await this.getStorageBucketOrFail(storageBucketId, { - relations: {}, - }); - if (!storage.documents) { - throw new EntityNotInitializedException( - `StorageBucket (${storage}) not initialised`, - LogContext.STORAGE_BUCKET - ); - } + const storage = await this.getStorageBucketOrFail(storageBucketId); this.validateMimeTypes(storage, document.mimeType); this.validateSize(storage, document.size); @@ -273,7 +262,7 @@ export class StorageBucketService { `Added document '${document.externalID}' on storage bucket: ${storage.id}`, LogContext.STORAGE_BUCKET ); - return await this.documentService.save(document); + return this.documentService.save(document); } public async size(storage: IStorageBucket): Promise {