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

N21-1296 Delete ContextExternalTool when deleting a ExternalToolElement on boards #4507

Merged
merged 6 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions apps/server/src/modules/board/board.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { FilesStorageClientModule } from '@modules/files-storage-client';
import { ContextExternalToolModule } from '@modules/tool/context-external-tool';
import { UserModule } from '@modules/user';
import { Module } from '@nestjs/common';
import { ContentElementFactory } from '@shared/domain';
import { ConsoleWriterModule } from '@shared/infra/console';
import { CourseRepo } from '@shared/repo';
import { LoggerModule } from '@src/core/logger';
import { FilesStorageClientModule } from '../files-storage-client';
import { UserModule } from '../user';
import { BoardDoRepo, BoardNodeRepo } from './repo';
import { RecursiveDeleteVisitor } from './repo/recursive-delete.vistor';
import { BoardDoRepo, BoardNodeRepo, RecursiveDeleteVisitor } from './repo';
import {
BoardDoAuthorizableService,
BoardDoService,
Expand All @@ -21,7 +21,7 @@ import { BoardDoCopyService, SchoolSpecificFileCopyServiceFactory } from './serv
import { ColumnBoardCopyService } from './service/column-board-copy.service';

@Module({
imports: [ConsoleWriterModule, FilesStorageClientModule, LoggerModule, UserModule],
imports: [ConsoleWriterModule, FilesStorageClientModule, LoggerModule, UserModule, ContextExternalToolModule],
providers: [
BoardDoAuthorizableService,
BoardDoRepo,
Expand Down
4 changes: 3 additions & 1 deletion apps/server/src/modules/board/repo/board-do.repo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createMock } from '@golevelup/ts-jest';
import { NotFoundError } from '@mikro-orm/core';
import { EntityManager } from '@mikro-orm/mongodb';
import { FilesStorageClientAdapterService } from '@modules/files-storage-client';
import { ContextExternalToolService } from '@modules/tool/context-external-tool/service';
import { NotFoundException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import {
Expand All @@ -26,7 +28,6 @@ import {
richTextElementFactory,
richTextElementNodeFactory,
} from '@shared/testing';
import { FilesStorageClientAdapterService } from '@modules/files-storage-client';
import { BoardDoRepo } from './board-do.repo';
import { BoardNodeRepo } from './board-node.repo';
import { RecursiveDeleteVisitor } from './recursive-delete.vistor';
Expand All @@ -46,6 +47,7 @@ describe(BoardDoRepo.name, () => {
BoardNodeRepo,
RecursiveDeleteVisitor,
{ provide: FilesStorageClientAdapterService, useValue: createMock<FilesStorageClientAdapterService>() },
{ provide: ContextExternalToolService, useValue: createMock<ContextExternalToolService>() },
],
}).compile();
repo = module.get(BoardDoRepo);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { EntityManager } from '@mikro-orm/mongodb';
import { FileDto, FilesStorageClientAdapterService } from '@modules/files-storage-client';
import { ContextExternalToolService } from '@modules/tool/context-external-tool/service';
import { Test, TestingModule } from '@nestjs/testing';
import { FileRecordParentType } from '@shared/infra/rabbitmq';
import {
columnBoardFactory,
columnFactory,
contextExternalToolFactory,
externalToolElementFactory,
fileElementFactory,
linkElementFactory,
setupEntities,
submissionContainerElementFactory,
submissionItemFactory,
} from '@shared/testing';
import { FileDto, FilesStorageClientAdapterService } from '@modules/files-storage-client';
import { RecursiveDeleteVisitor } from './recursive-delete.vistor';

describe(RecursiveDeleteVisitor.name, () => {
let module: TestingModule;
let service: RecursiveDeleteVisitor;

let em: DeepMocked<EntityManager>;
let filesStorageClientAdapterService: DeepMocked<FilesStorageClientAdapterService>;
let service: RecursiveDeleteVisitor;
let contextExternalToolService: DeepMocked<ContextExternalToolService>;

beforeAll(async () => {
module = await Test.createTestingModule({
providers: [
RecursiveDeleteVisitor,
{ provide: EntityManager, useValue: createMock<EntityManager>() },
{ provide: FilesStorageClientAdapterService, useValue: createMock<FilesStorageClientAdapterService>() },
{ provide: ContextExternalToolService, useValue: createMock<ContextExternalToolService>() },
],
}).compile();

service = module.get(RecursiveDeleteVisitor);
em = module.get(EntityManager);
filesStorageClientAdapterService = module.get(FilesStorageClientAdapterService);
service = module.get(RecursiveDeleteVisitor);
contextExternalToolService = module.get(ContextExternalToolService);

await setupEntities();
});

Expand Down Expand Up @@ -212,14 +219,30 @@ describe(RecursiveDeleteVisitor.name, () => {

describe('visitExternalToolElementAsync', () => {
const setup = () => {
const contextExternalTool = contextExternalToolFactory.buildWithId();
const childExternalToolElement = externalToolElementFactory.build();
const externalToolElement = externalToolElementFactory.build({
children: [childExternalToolElement],
contextExternalToolId: contextExternalTool.id,
});

return { externalToolElement, childExternalToolElement };
contextExternalToolService.findById.mockResolvedValue(contextExternalTool);

return {
externalToolElement,
childExternalToolElement,
contextExternalTool,
};
};

it('should delete the context external tool that is linked to the element', async () => {
const { externalToolElement, contextExternalTool } = setup();

await service.visitExternalToolElementAsync(externalToolElement);

expect(contextExternalToolService.deleteContextExternalTool).toHaveBeenCalledWith(contextExternalTool);
});

it('should call entity remove', async () => {
const { externalToolElement, childExternalToolElement } = setup();

Expand Down
16 changes: 13 additions & 3 deletions apps/server/src/modules/board/repo/recursive-delete.vistor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { EntityManager } from '@mikro-orm/mongodb';
import { FilesStorageClientAdapterService } from '@modules/files-storage-client';
import { ContextExternalTool } from '@modules/tool/context-external-tool/domain';
import { ContextExternalToolService } from '@modules/tool/context-external-tool/service';
import { Injectable } from '@nestjs/common';
import {
AnyBoardDo,
Expand All @@ -14,13 +17,13 @@ import {
SubmissionItem,
} from '@shared/domain';
import { LinkElement } from '@shared/domain/domainobject/board/link-element.do';
import { FilesStorageClientAdapterService } from '@modules/files-storage-client';

@Injectable()
export class RecursiveDeleteVisitor implements BoardCompositeVisitorAsync {
constructor(
private readonly em: EntityManager,
private readonly filesStorageClientAdapterService: FilesStorageClientAdapterService
private readonly filesStorageClientAdapterService: FilesStorageClientAdapterService,
private readonly contextExternalToolService: ContextExternalToolService
) {}

async visitColumnBoardAsync(columnBoard: ColumnBoard): Promise<void> {
Expand Down Expand Up @@ -67,7 +70,14 @@ export class RecursiveDeleteVisitor implements BoardCompositeVisitorAsync {
}

async visitExternalToolElementAsync(externalToolElement: ExternalToolElement): Promise<void> {
// TODO N21-1296: Delete linked ContextExternalTool
if (externalToolElement.contextExternalToolId) {
const linkedTool: ContextExternalTool = await this.contextExternalToolService.findById(
externalToolElement.contextExternalToolId
);

await this.contextExternalToolService.deleteContextExternalTool(linkedTool);
}

this.deleteNode(externalToolElement);

await this.visitChildrenAsync(externalToolElement);
Expand Down
9 changes: 4 additions & 5 deletions apps/server/src/modules/pseudonym/pseudonym.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { forwardRef, Module } from '@nestjs/common';
import { LegacyLogger } from '@src/core/logger';
import { LearnroomModule } from '@modules/learnroom';
import { UserModule } from '@modules/user';
import { ToolModule } from '@modules/tool';
import { AuthorizationModule } from '@modules/authorization';
import { UserModule } from '@modules/user';
import { forwardRef, Module } from '@nestjs/common';
import { LegacyLogger } from '@src/core/logger';
import { ExternalToolPseudonymRepo, PseudonymsRepo } from './repo';
import { FeathersRosterService, PseudonymService } from './service';

@Module({
imports: [UserModule, LearnroomModule, forwardRef(() => ToolModule), forwardRef(() => AuthorizationModule)],
imports: [UserModule, LearnroomModule, forwardRef(() => ToolModule)],
providers: [PseudonymService, PseudonymsRepo, ExternalToolPseudonymRepo, LegacyLogger, FeathersRosterService],
MarvinOehlerkingCap marked this conversation as resolved.
Show resolved Hide resolved
exports: [PseudonymService, FeathersRosterService],
})
Expand Down
7 changes: 3 additions & 4 deletions apps/server/src/modules/task/task.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { forwardRef, Module } from '@nestjs/common';
import { CourseRepo, LessonRepo, SubmissionRepo, TaskRepo } from '@shared/repo';
import { AuthorizationModule } from '@modules/authorization';
import { CopyHelperModule } from '@modules/copy-helper';
import { FilesStorageClientModule } from '@modules/files-storage-client';
import { Module } from '@nestjs/common';
import { CourseRepo, LessonRepo, SubmissionRepo, TaskRepo } from '@shared/repo';
import { SubmissionService, TaskCopyService, TaskService } from './service';

@Module({
imports: [forwardRef(() => AuthorizationModule), FilesStorageClientModule, CopyHelperModule],
imports: [FilesStorageClientModule, CopyHelperModule],
providers: [TaskService, TaskCopyService, SubmissionService, TaskRepo, LessonRepo, CourseRepo, SubmissionRepo],
exports: [TaskService, TaskCopyService, SubmissionService],
})
Expand Down
Loading