Skip to content

Commit

Permalink
Added filterOutNeXboardFromCopyStatus.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaellinaresxk committed Nov 27, 2023
1 parent 537571d commit 38ce7fc
Show file tree
Hide file tree
Showing 3 changed files with 34 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,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';
Expand Down Expand Up @@ -32,6 +33,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 @@ -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<Course> {
const { originalCourse, user, copyName } = params;
const courseCopy = new Course({
Expand Down
23 changes: 16 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,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 = {

Check failure on line 228 in apps/server/src/modules/lesson/service/lesson-copy.service.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'nexboardStatus' is never reassigned. Use 'const' instead
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);

Check failure on line 238 in apps/server/src/modules/lesson/service/lesson-copy.service.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Unexpected `await` inside a loop
if (nexboardContent) {
copiedContent.push(nexboardContent);
} else {
nexboardStatus.status = CopyStatusEnum.NOT_DOING;
}
} catch (error) {
nexboardStatus.status = CopyStatusEnum.NOT_DOING;
}
}
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 @@ -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,
Expand Down

0 comments on commit 38ce7fc

Please sign in to comment.