Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-6070-Remove tldraw and column board on deletion scenario. #4677

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/server/src/apps/server.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
/* eslint-disable no-console */
import { MikroORM } from '@mikro-orm/core';
import { AccountService } from '@modules/account';
import { AccountValidationService } from '@modules/account/services/account.validation.service';

Check warning on line 7 in apps/server/src/apps/server.app.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'@modules/account/services/account.validation.service' import is restricted from being used by a pattern. Do not deep import from a module
import { AccountUc } from '@modules/account/uc/account.uc';

Check warning on line 8 in apps/server/src/apps/server.app.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'@modules/account/uc/account.uc' import is restricted from being used by a pattern. Do not deep import from a module
import { SystemRule } from '@modules/authorization/domain/rules';

Check warning on line 9 in apps/server/src/apps/server.app.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'@modules/authorization/domain/rules' import is restricted from being used by a pattern. Do not deep import from a module
import { CollaborativeStorageUc } from '@modules/collaborative-storage/uc/collaborative-storage.uc';

Check warning on line 10 in apps/server/src/apps/server.app.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'@modules/collaborative-storage/uc/collaborative-storage.uc' import is restricted from being used by a pattern. Do not deep import from a module
import { GroupService } from '@modules/group';
import { FeathersRosterService } from '@modules/pseudonym';
import { RocketChatService } from '@modules/rocketchat';
import { ServerModule } from '@modules/server';
import { TeamService } from '@modules/teams/service/team.service';

Check warning on line 15 in apps/server/src/apps/server.app.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'@modules/teams/service/team.service' import is restricted from being used by a pattern. Do not deep import from a module
import { NestFactory } from '@nestjs/core';
import { ExpressAdapter } from '@nestjs/platform-express';
import { enableOpenApiDocs } from '@shared/controller/swagger';
Expand All @@ -23,6 +23,7 @@
// register source-map-support for debugging
import { install as sourceMapInstall } from 'source-map-support';

import { ColumnBoardService } from '@modules/board';
import { AppStartLoggable } from './helpers/app-start-loggable';
import {
addPrometheusMetricsMiddlewaresIfEnabled,
Expand Down Expand Up @@ -87,6 +88,8 @@
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
feathersExpress.services['nest-group-service'] = nestApp.get(GroupService);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
feathersExpress.services['nest-column-board-service'] = nestApp.get(ColumnBoardService);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
feathersExpress.services['nest-system-rule'] = nestApp.get(SystemRule);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
feathersExpress.services['nest-orm'] = orm;
Expand Down
27 changes: 25 additions & 2 deletions apps/server/src/modules/board/service/column-board.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ describe(ColumnBoardService.name, () => {
const board = columnBoardFactory.build();
const boardId = board.id;
const column = columnFactory.build();
const courseId = new ObjectId().toHexString();
const externalReference: BoardExternalReference = {
id: new ObjectId().toHexString(),
id: courseId,
type: BoardExternalReferenceType.Course,
};

return { board, boardId, column, externalReference };
return { board, boardId, column, courseId, externalReference };
};

describe('findById', () => {
Expand Down Expand Up @@ -239,6 +240,28 @@ describe(ColumnBoardService.name, () => {
});
});

describe('deleteByCourseId', () => {
describe('when deleting by courseId', () => {
it('should call boardDoRepo.findIdsByExternalReference to find the board ids', async () => {
const { boardId, courseId, externalReference } = setup();

boardDoRepo.findIdsByExternalReference.mockResolvedValue([boardId]);

await service.deleteByCourseId(courseId);

expect(boardDoRepo.findIdsByExternalReference).toHaveBeenCalledWith(externalReference);
});

it('should call boardDoService.deleteWithDescendants to delete the board', async () => {
const { board, courseId } = setup();

await service.deleteByCourseId(courseId);

expect(boardDoService.deleteWithDescendants).toHaveBeenCalledWith(board);
});
});
});

describe('updateTitle', () => {
describe('when updating the title', () => {
it('should call the service', async () => {
Expand Down
20 changes: 20 additions & 0 deletions apps/server/src/modules/board/service/column-board.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NotFoundLoggableException } from '@shared/common/loggable-exception';
import {
AnyBoardDo,
BoardExternalReference,
BoardExternalReferenceType,
Card,
Column,
ColumnBoard,
Expand Down Expand Up @@ -73,6 +74,25 @@ export class ColumnBoardService {
await this.boardDoService.deleteWithDescendants(board);
}

async deleteByCourseId(courseId: EntityId): Promise<void> {
const columnBoardsId = await this.findIdsByExternalReference({
type: BoardExternalReferenceType.Course,
id: courseId,
});

const deletePromises = columnBoardsId.map((columnBoardId) => this.deleteColumnBoardById(columnBoardId));

await Promise.all(deletePromises);
}

private async deleteColumnBoardById(id: EntityId): Promise<void> {
const columnBoardToDeletion = await this.boardDoRepo.findByClassAndId(ColumnBoard, id);

if (columnBoardToDeletion) {
await this.boardDoService.deleteWithDescendants(columnBoardToDeletion);
}
}

async updateTitle(board: ColumnBoard, title: string): Promise<void> {
board.title = title;
await this.boardDoRepo.save(board);
Expand Down
6 changes: 6 additions & 0 deletions src/services/user-group/hooks/courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ const deleteWholeClassFromCourse = (hook) => {
});
};

const removeColumnBoard = async (context) => {
const courseId = context.id;
await context.app.service('nest-column-board-service').deleteByCourseId(courseId);
};

/**
* remove all substitution teacher which are also teachers
* @param hook - contains and request body
Expand Down Expand Up @@ -185,6 +190,7 @@ const restrictChangesToArchivedCourse = async (context) => {
module.exports = {
addWholeClassToCourse,
deleteWholeClassFromCourse,
removeColumnBoard,
removeSubstitutionDuplicates,
courseInviteHook,
patchPermissionHook,
Expand Down
3 changes: 2 additions & 1 deletion src/services/user-group/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const restrictToUsersOwnCourses = globalHooks.ifNotLocal(globalHooks.restrictToU
const {
addWholeClassToCourse,
deleteWholeClassFromCourse,
removeColumnBoard,
courseInviteHook,
patchPermissionHook,
restrictChangesToArchivedCourse,
Expand Down Expand Up @@ -63,5 +64,5 @@ exports.after = {
create: [addWholeClassToCourse],
update: [],
patch: [addWholeClassToCourse],
remove: [],
remove: [removeColumnBoard],
};
3 changes: 2 additions & 1 deletion src/services/user-group/services/courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const restrictToUsersOwnCoursesIfNotLocal = ifNotLocal(restrictToUsersOwnCourses
const {
addWholeClassToCourse,
deleteWholeClassFromCourse,
removeColumnBoard,
courseInviteHook,
patchPermissionHook,
restrictChangesToArchivedCourse,
Expand Down Expand Up @@ -134,7 +135,7 @@ const courseHooks = {
create: [addWholeClassToCourse],
update: [],
patch: [addWholeClassToCourse],
remove: [],
remove: [removeColumnBoard],
},
};

Expand Down
Loading