Skip to content

Commit

Permalink
Cleaning pr.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaellinaresxk committed Dec 4, 2023
1 parent 3164f26 commit ec827c8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
15 changes: 13 additions & 2 deletions apps/server/src/modules/learnroom/service/course-copy.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -33,6 +34,7 @@ export class CourseCopyService {
newName?: string | undefined;
}): Promise<CopyStatus> {
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);
Expand All @@ -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<Course> {
const { originalCourse, user, copyName } = params;
const courseCopy = new Course({
Expand Down
17 changes: 10 additions & 7 deletions apps/server/src/modules/lesson/service/lesson-copy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions config/default.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ec827c8

Please sign in to comment.