From 38ce7fcc7090a3d39d296d6161bcb8e9482b40ac Mon Sep 17 00:00:00 2001 From: Michael Linares Date: Mon, 27 Nov 2023 12:06:14 +0100 Subject: [PATCH] Added filterOutNeXboardFromCopyStatus. --- .../learnroom/service/course-copy.service.ts | 15 ++++++++++-- .../lesson/service/lesson-copy.service.ts | 23 +++++++++++++------ config/default.schema.json | 5 ++++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/apps/server/src/modules/learnroom/service/course-copy.service.ts b/apps/server/src/modules/learnroom/service/course-copy.service.ts index 51f98bb436b..14006989c92 100644 --- a/apps/server/src/modules/learnroom/service/course-copy.service.ts +++ b/apps/server/src/modules/learnroom/service/course-copy.service.ts @@ -1,4 +1,5 @@ import { Injectable } from '@nestjs/common'; +import { Configuration } from '@hpi-schul-cloud/commons'; import { Course, EntityId, User } from '@shared/domain'; import { BoardRepo, CourseRepo, UserRepo } from '@shared/repo'; import { CopyElementType, CopyHelperService, CopyStatus, CopyStatusEnum } from '@modules/copy-helper'; @@ -32,6 +33,7 @@ export class CourseCopyService { newName?: string | undefined; }): Promise { const user: User = await this.userRepo.findById(userId, true); + const copyNexboardEnabled = Configuration.get('FEATURE_COPY_NEXBOARD_ENABLED') as boolean; // fetch original course and board const originalCourse = await this.courseRepo.findById(courseId); @@ -46,13 +48,22 @@ export class CourseCopyService { // copy course and board const courseCopy = await this.copyCourseEntity({ user, originalCourse, copyName }); const boardStatus = await this.boardCopyService.copyBoard({ originalBoard, destinationCourse: courseCopy, user }); + const filteredBoardStatus = this.filterOutNeXboardFromCopyStatus(boardStatus, copyNexboardEnabled); const finishedCourseCopy = await this.finishCourseCopying(courseCopy); - - const courseStatus = this.deriveCourseStatus(originalCourse, finishedCourseCopy, boardStatus); + const courseStatus = this.deriveCourseStatus(originalCourse, finishedCourseCopy, filteredBoardStatus); return courseStatus; } + private filterOutNeXboardFromCopyStatus(boardStatus: CopyStatus, copyNexboardEnabled: boolean): CopyStatus { + if (!copyNexboardEnabled && boardStatus.elements) { + boardStatus.elements = boardStatus.elements.filter( + (elementStatus) => elementStatus.type !== CopyElementType.LESSON_CONTENT_NEXBOARD + ); + } + return boardStatus; + } + private async copyCourseEntity(params: CourseCopyParams): Promise { const { originalCourse, user, copyName } = params; const courseCopy = new Course({ diff --git a/apps/server/src/modules/lesson/service/lesson-copy.service.ts b/apps/server/src/modules/lesson/service/lesson-copy.service.ts index 00cf3cee8b9..9f2caef7b03 100644 --- a/apps/server/src/modules/lesson/service/lesson-copy.service.ts +++ b/apps/server/src/modules/lesson/service/lesson-copy.service.ts @@ -167,6 +167,7 @@ export class LessonCopyService { }> { const etherpadEnabled = Configuration.get('FEATURE_ETHERPAD_ENABLED') as boolean; const nexboardEnabled = Configuration.get('FEATURE_NEXBOARD_ENABLED') as boolean; + const copyNexboardEnabled = Configuration.get('FEATURE_COPY_NEXBOARD_ENABLED') as boolean; const copiedContent: ComponentProperties[] = []; const copiedContentStatus: CopyStatus[] = []; for (let i = 0; i < content.length; i += 1) { @@ -224,17 +225,25 @@ export class LessonCopyService { copiedContentStatus.push(embeddedTaskStatus); } if (element.component === ComponentType.NEXBOARD && nexboardEnabled) { - // eslint-disable-next-line no-await-in-loop - const nexboardContent = await this.copyNexboard(element, params); - const nexboardStatus = { + let nexboardStatus = { title: element.title, type: CopyElementType.LESSON_CONTENT_NEXBOARD, status: CopyStatusEnum.PARTIAL, }; - if (nexboardContent) { - copiedContent.push(nexboardContent); - } else { - nexboardStatus.status = CopyStatusEnum.FAIL; + if (!copyNexboardEnabled) { + nexboardStatus.status = CopyStatusEnum.NOT_DOING; + } + if (nexboardStatus.status === CopyStatusEnum.PARTIAL) { + try { + const nexboardContent = await this.copyNexboard(element, params); + if (nexboardContent) { + copiedContent.push(nexboardContent); + } else { + nexboardStatus.status = CopyStatusEnum.NOT_DOING; + } + } catch (error) { + nexboardStatus.status = CopyStatusEnum.NOT_DOING; + } } copiedContentStatus.push(nexboardStatus); } diff --git a/config/default.schema.json b/config/default.schema.json index d57355c8c0f..e68cbeb00a2 100644 --- a/config/default.schema.json +++ b/config/default.schema.json @@ -579,6 +579,11 @@ "default": false, "description": "Enable nexboard" }, + "FEATURE_COPY_NEXBOARD_ENABLED": { + "type": "boolean", + "default": false, + "description": "Enable nexboard on copy course." + }, "FEATURE_MULTIPLE_S3_PROVIDERS_ENABLED": { "type": "boolean", "default": true,