From ec827c857bed60f828acbb6a83ba643ff0ffe27b Mon Sep 17 00:00:00 2001 From: Michael Linares Date: Mon, 4 Dec 2023 13:14:49 +0100 Subject: [PATCH] Cleaning pr. --- .../learnroom/service/course-copy.service.ts | 15 +++++++++++++-- .../lesson/service/lesson-copy.service.ts | 17 ++++++++++------- config/default.schema.json | 5 +++++ 3 files changed, 28 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 65dc598d237..f29d5b74f42 100644 --- a/apps/server/src/modules/learnroom/service/course-copy.service.ts +++ b/apps/server/src/modules/learnroom/service/course-copy.service.ts @@ -1,3 +1,4 @@ +import { Configuration } from '@hpi-schul-cloud/commons'; import { CopyElementType, CopyHelperService, CopyStatus, CopyStatusEnum } from '@modules/copy-helper'; import { Injectable } from '@nestjs/common'; import { Course, User } from '@shared/domain/entity'; @@ -33,6 +34,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); @@ -47,13 +49,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 9e9be810e0a..3f7fca93441 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,19 @@ 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 = { title: element.title, type: CopyElementType.LESSON_CONTENT_NEXBOARD, - status: CopyStatusEnum.PARTIAL, + status: copyNexboardEnabled ? CopyStatusEnum.PARTIAL : CopyStatusEnum.NOT_DOING, }; - if (nexboardContent) { - copiedContent.push(nexboardContent); - } else { - nexboardStatus.status = CopyStatusEnum.FAIL; + if (copyNexboardEnabled) { + // eslint-disable-next-line no-await-in-loop + const nexboardContent = await this.copyNexboard(element, params); + if (nexboardContent) { + copiedContent.push(nexboardContent); + } else { + nexboardStatus.status = CopyStatusEnum.FAIL; + } } copiedContentStatus.push(nexboardStatus); } diff --git a/config/default.schema.json b/config/default.schema.json index bcf9fe7de4e..828279b6bf9 100644 --- a/config/default.schema.json +++ b/config/default.schema.json @@ -574,6 +574,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,