Skip to content

Commit

Permalink
'not initilized' exception fixed while saving Whiteboard (#4331)
Browse files Browse the repository at this point in the history
* fixed "not initialized" bug

* decreased data loaded while updating whiteboard content

* Minor version bump

---------

Co-authored-by: Valentin Yanakiev <[email protected]>
  • Loading branch information
valentinyanakiev committed Jul 31, 2024
1 parent 6a7e89a commit 264924a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 32 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
15 changes: 13 additions & 2 deletions src/domain/common/whiteboard/whiteboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 3 additions & 10 deletions src/domain/profile-documents/profile.documents.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<string | undefined> {
if (!this.documentService.isAlkemioDocumentURL(fileUrl)) {
throw new BaseException(
Expand All @@ -32,14 +33,6 @@ export class ProfileDocumentsService {
);
}

const profile = await this.profileService.getProfileOrFail(profileId, {
relations: {
storageBucket: {
documents: true,
},
},
});

const storageBucketToCheck = profile.storageBucket;

if (!storageBucketToCheck) {
Expand Down
23 changes: 6 additions & 17 deletions src/domain/storage/storage-bucket/storage.bucket.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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?.(
Expand All @@ -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(
Expand Down Expand Up @@ -255,15 +252,7 @@ export class StorageBucketService {
storageBucketId: string,
document: IDocument
): Promise<IDocument> | 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);
Expand All @@ -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<number> {
Expand Down

0 comments on commit 264924a

Please sign in to comment.