Skip to content

Commit

Permalink
Merge branch 'main' into N21-1319-ctl-showing-tool-usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mrikallab committed Nov 20, 2023
2 parents dab99dd + 84c267d commit eb9cf54
Show file tree
Hide file tree
Showing 63 changed files with 1,027 additions and 267 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { BoardModule } from '@modules/board';
import { ToolModule } from '@modules/tool';
import { forwardRef, Module } from '@nestjs/common';
import {
CourseGroupRepo,
CourseRepo,
LessonRepo,
SchoolExternalToolRepo,
LegacySchoolRepo,
SchoolExternalToolRepo,
SubmissionRepo,
TaskRepo,
TeamsRepo,
UserRepo,
} from '@shared/repo';
import { ToolModule } from '@modules/tool';
import { LoggerModule } from '@src/core/logger';
import { BoardModule } from '@modules/board';
import { ReferenceLoader, AuthorizationReferenceService, AuthorizationHelper } from './domain';
import { LessonModule } from '../lesson';
import { AuthorizationModule } from './authorization.module';
import { AuthorizationHelper, AuthorizationReferenceService, ReferenceLoader } from './domain';

/**
* This module is part of an intermediate state. In the future it should be replaced by an AuthorizationApiModule.
Expand All @@ -23,7 +23,13 @@ import { AuthorizationModule } from './authorization.module';
*/
@Module({
// TODO: remove forwardRef to TooModule N21-1055
imports: [AuthorizationModule, forwardRef(() => ToolModule), forwardRef(() => BoardModule), LoggerModule],
imports: [
AuthorizationModule,
LessonModule,
forwardRef(() => ToolModule),
forwardRef(() => BoardModule),
LoggerModule,
],
providers: [
AuthorizationHelper,
ReferenceLoader,
Expand All @@ -32,7 +38,6 @@ import { AuthorizationModule } from './authorization.module';
CourseGroupRepo,
TaskRepo,
LegacySchoolRepo,
LessonRepo,
TeamsRepo,
SubmissionRepo,
SchoolExternalToolRepo,
Expand Down
10 changes: 5 additions & 5 deletions apps/server/src/modules/authorization/authorization.module.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { FeathersModule } from '@infra/feathers';
import { Module } from '@nestjs/common';
import { UserRepo } from '@shared/repo';
import { LoggerModule } from '@src/core/logger';
import { FeathersModule } from '@infra/feathers';
import { AuthorizationHelper, AuthorizationService, RuleManager } from './domain';
import {
BoardDoRule,
ContextExternalToolRule,
CourseGroupRule,
CourseRule,
GroupRule,
LegacySchoolRule,
LessonRule,
SchoolExternalToolRule,
SubmissionRule,
TaskRule,
TeamRule,
UserRule,
UserLoginMigrationRule,
LegacySchoolRule,
GroupRule,
UserRule,
} from './domain/rules';
import { AuthorizationHelper, AuthorizationService, RuleManager } from './domain';
import { FeathersAuthorizationService, FeathersAuthProvider } from './feathers';

@Module({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { ObjectId } from '@mikro-orm/mongodb';
import { BoardDoAuthorizableService } from '@modules/board';
import { ContextExternalToolAuthorizableService } from '@modules/tool';
import { NotImplementedException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { EntityId } from '@shared/domain';
import {
CourseGroupRepo,
CourseRepo,
LessonRepo,
SchoolExternalToolRepo,
LegacySchoolRepo,
SchoolExternalToolRepo,
SubmissionRepo,
TaskRepo,
TeamsRepo,
UserRepo,
} from '@shared/repo';
import { setupEntities, userFactory } from '@shared/testing';
import { BoardDoAuthorizableService } from '@modules/board';
import { ContextExternalToolAuthorizableService } from '@modules/tool/context-external-tool/service/context-external-tool-authorizable.service';
import { ReferenceLoader } from './reference.loader';
import { LessonService } from '@modules/lesson';
import { AuthorizableReferenceType } from '../type';
import { ReferenceLoader } from './reference.loader';

describe('reference.loader', () => {
let service: ReferenceLoader;
Expand All @@ -27,7 +27,7 @@ describe('reference.loader', () => {
let courseGroupRepo: DeepMocked<CourseGroupRepo>;
let taskRepo: DeepMocked<TaskRepo>;
let schoolRepo: DeepMocked<LegacySchoolRepo>;
let lessonRepo: DeepMocked<LessonRepo>;
let lessonService: DeepMocked<LessonService>;
let teamsRepo: DeepMocked<TeamsRepo>;
let submissionRepo: DeepMocked<SubmissionRepo>;
let schoolExternalToolRepo: DeepMocked<SchoolExternalToolRepo>;
Expand Down Expand Up @@ -62,8 +62,8 @@ describe('reference.loader', () => {
useValue: createMock<LegacySchoolRepo>(),
},
{
provide: LessonRepo,
useValue: createMock<LessonRepo>(),
provide: LessonService,
useValue: createMock<LessonService>(),
},
{
provide: TeamsRepo,
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('reference.loader', () => {
courseGroupRepo = await module.get(CourseGroupRepo);
taskRepo = await module.get(TaskRepo);
schoolRepo = await module.get(LegacySchoolRepo);
lessonRepo = await module.get(LessonRepo);
lessonService = await module.get(LessonService);
teamsRepo = await module.get(TeamsRepo);
submissionRepo = await module.get(SubmissionRepo);
schoolExternalToolRepo = await module.get(SchoolExternalToolRepo);
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('reference.loader', () => {
it('should call lessonRepo.findById', async () => {
await service.loadAuthorizableObject(AuthorizableReferenceType.Lesson, entityId);

expect(lessonRepo.findById).toBeCalledWith(entityId);
expect(lessonService.findById).toBeCalledWith(entityId);
});

it('should call teamsRepo.findById', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { BoardDoAuthorizableService } from '@modules/board';
import { ContextExternalToolAuthorizableService } from '@modules/tool';
import { Injectable, NotImplementedException } from '@nestjs/common';
import { BaseDO, EntityId } from '@shared/domain';
import { AuthorizableObject } from '@shared/domain/domain-object';
import {
CourseGroupRepo,
CourseRepo,
LessonRepo,
SchoolExternalToolRepo,
LegacySchoolRepo,
SchoolExternalToolRepo,
SubmissionRepo,
TaskRepo,
TeamsRepo,
UserRepo,
} from '@shared/repo';
import { BoardDoAuthorizableService } from '@modules/board';
import { ContextExternalToolAuthorizableService } from '@modules/tool/context-external-tool/service';
import { LessonService } from '@modules/lesson';
import { AuthorizableReferenceType } from '../type';

type RepoType =
| TaskRepo
| CourseRepo
| UserRepo
| LegacySchoolRepo
| LessonRepo
| TeamsRepo
| CourseGroupRepo
| SubmissionRepo
| SchoolExternalToolRepo
| BoardDoAuthorizableService
| ContextExternalToolAuthorizableService;
| ContextExternalToolAuthorizableService
| LessonService;

interface IRepoLoader {
repo: RepoType;
Expand All @@ -44,7 +44,7 @@ export class ReferenceLoader {
private readonly courseGroupRepo: CourseGroupRepo,
private readonly taskRepo: TaskRepo,
private readonly schoolRepo: LegacySchoolRepo,
private readonly lessonRepo: LessonRepo,
private readonly lessonService: LessonService,
private readonly teamsRepo: TeamsRepo,
private readonly submissionRepo: SubmissionRepo,
private readonly schoolExternalToolRepo: SchoolExternalToolRepo,
Expand All @@ -56,7 +56,7 @@ export class ReferenceLoader {
this.repos.set(AuthorizableReferenceType.CourseGroup, { repo: this.courseGroupRepo });
this.repos.set(AuthorizableReferenceType.User, { repo: this.userRepo });
this.repos.set(AuthorizableReferenceType.School, { repo: this.schoolRepo });
this.repos.set(AuthorizableReferenceType.Lesson, { repo: this.lessonRepo });
this.repos.set(AuthorizableReferenceType.Lesson, { repo: this.lessonService });
this.repos.set(AuthorizableReferenceType.Team, { repo: this.teamsRepo, populate: true });
this.repos.set(AuthorizableReferenceType.Submission, { repo: this.submissionRepo });
this.repos.set(AuthorizableReferenceType.SchoolExternalToolEntity, { repo: this.schoolExternalToolRepo });
Expand Down
14 changes: 8 additions & 6 deletions apps/server/src/modules/authorization/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
export { AuthorizationModule } from './authorization.module';
export {
AuthorizationService,
AuthorizationHelper,
AuthorizationContextBuilder,
ForbiddenLoggableException,
Rule,
AuthorizationContext,
// Action should not be exported, but hard to solve for now. The AuthorizationContextBuilder is the prefared way
Action,
AuthorizableReferenceType,
AuthorizationContext,
AuthorizationContextBuilder,
AuthorizationHelper,
AuthorizationLoaderService,
AuthorizationLoaderServiceGeneric,
AuthorizationReferenceService,
AuthorizationService,
ForbiddenLoggableException,
Rule,
} from './domain';
// Should not used anymore
export { FeathersAuthorizationService } from './feathers';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApiProperty, ApiPropertyOptional, getSchemaPath } from '@nestjs/swagger
import { ContentElementType } from '@shared/domain';
import { InputFormat } from '@shared/domain/types';
import { Type } from 'class-transformer';
import { IsDate, IsEnum, IsMongoId, IsOptional, IsString, IsUrl, ValidateNested } from 'class-validator';
import { IsDate, IsEnum, IsMongoId, IsOptional, IsString, ValidateNested } from 'class-validator';

export abstract class ElementContentBody {
@IsEnum(ContentElementType)
Expand Down Expand Up @@ -34,7 +34,7 @@ export class FileElementContentBody extends ElementContentBody {
}

export class LinkContentBody {
@IsUrl()
@IsString()
@ApiProperty({})
url!: string;

Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/modules/files-storage-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export { FileDto } from './dto';
export * from './files-storage-client.module';
export { IFilesStorageClientConfig } from './interfaces';
export { FileParamBuilder } from './mapper/files-storage-param.builder';
export { CopyFilesService } from './service/copy-files.service';
export * from './service/copy-files.service';
export { FilesStorageClientAdapterService } from './service/files-storage-client.service';
3 changes: 1 addition & 2 deletions apps/server/src/modules/learnroom/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './learnroom.module';
export * from './service/course-copy.service';
export { CourseService } from './service';
export { CommonCartridgeExportService, CourseCopyService, CourseService, RoomsService } from './service';
5 changes: 2 additions & 3 deletions apps/server/src/modules/learnroom/learnroom-api.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Module } from '@nestjs/common';
import { BoardRepo, CourseRepo, DashboardModelMapper, DashboardRepo, LessonRepo, UserRepo } from '@shared/repo';
import { AuthorizationModule } from '@modules/authorization';
import { AuthorizationReferenceModule } from '@modules/authorization/authorization-reference.module';
import { CopyHelperModule } from '@modules/copy-helper';
import { LessonModule } from '@modules/lesson';
import { Module } from '@nestjs/common';
import { BoardRepo, CourseRepo, DashboardModelMapper, DashboardRepo, UserRepo } from '@shared/repo';
import { CourseController } from './controller/course.controller';
import { DashboardController } from './controller/dashboard.controller';
import { RoomsController } from './controller/rooms.controller';
Expand Down Expand Up @@ -42,7 +42,6 @@ import {
CourseRepo,
UserRepo,
BoardRepo,
LessonRepo,
],
})
export class LearnroomApiModule {}
7 changes: 3 additions & 4 deletions apps/server/src/modules/learnroom/learnroom.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Module } from '@nestjs/common';
import { BoardRepo, CourseRepo, DashboardModelMapper, DashboardRepo, LessonRepo, UserRepo } from '@shared/repo';
import { LoggerModule } from '@src/core/logger';
import { BoardModule } from '@modules/board';
import { CopyHelperModule } from '@modules/copy-helper';
import { LessonModule } from '@modules/lesson';
import { TaskModule } from '@modules/task';
import { Module } from '@nestjs/common';
import { BoardRepo, CourseRepo, DashboardModelMapper, DashboardRepo, UserRepo } from '@shared/repo';
import { LoggerModule } from '@src/core/logger';
import {
BoardCopyService,
ColumnBoardTargetService,
Expand All @@ -23,7 +23,6 @@ import {
},
DashboardModelMapper,
CourseRepo,
LessonRepo,
BoardRepo,
UserRepo,
BoardCopyService,
Expand Down
19 changes: 10 additions & 9 deletions apps/server/src/modules/learnroom/service/rooms.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { Configuration } from '@hpi-schul-cloud/commons/lib';
import { IConfig } from '@hpi-schul-cloud/commons/lib/interfaces/IConfig';
import { ObjectId } from '@mikro-orm/mongodb';
import { CardService, ColumnBoardService, ColumnService, ContentElementService } from '@modules/board';
import { LessonService } from '@modules/lesson';
import { TaskService } from '@modules/task';
import { Test, TestingModule } from '@nestjs/testing';
import { BoardExternalReference, BoardExternalReferenceType, EntityId } from '@shared/domain';
import { BoardRepo, LessonRepo } from '@shared/repo';
import { BoardRepo } from '@shared/repo';
import { boardFactory, courseFactory, lessonFactory, setupEntities, taskFactory, userFactory } from '@shared/testing';
import { CardService, ColumnBoardService, ColumnService, ContentElementService } from '@modules/board';
import { TaskService } from '@modules/task/service';
import { ColumnBoardTargetService } from './column-board-target.service';
import { RoomsService } from './rooms.service';

describe('rooms service', () => {
let module: TestingModule;
let roomsService: RoomsService;
let lessonRepo: DeepMocked<LessonRepo>;
let lessonService: DeepMocked<LessonService>;
let taskService: DeepMocked<TaskService>;
let boardRepo: DeepMocked<BoardRepo>;
let columnBoardService: DeepMocked<ColumnBoardService>;
Expand All @@ -32,8 +33,8 @@ describe('rooms service', () => {
providers: [
RoomsService,
{
provide: LessonRepo,
useValue: createMock<LessonRepo>(),
provide: LessonService,
useValue: createMock<LessonService>(),
},
{
provide: TaskService,
Expand Down Expand Up @@ -66,7 +67,7 @@ describe('rooms service', () => {
],
}).compile();
roomsService = module.get(RoomsService);
lessonRepo = module.get(LessonRepo);
lessonService = module.get(LessonService);
taskService = module.get(TaskService);
boardRepo = module.get(BoardRepo);
columnBoardService = module.get(ColumnBoardService);
Expand All @@ -90,7 +91,7 @@ describe('rooms service', () => {
board.syncBoardElementReferences([...tasks, ...lessons]);

const tasksSpy = taskService.findBySingleParent.mockResolvedValue([tasks, 3]);
const lessonsSpy = lessonRepo.findAllByCourseIds.mockResolvedValue([lessons, 3]);
const lessonsSpy = lessonService.findByCourseIds.mockResolvedValue([lessons, 3]);
const syncBoardElementReferencesSpy = jest.spyOn(board, 'syncBoardElementReferences');
const saveSpy = boardRepo.save.mockResolvedValue();

Expand Down Expand Up @@ -134,7 +135,7 @@ describe('rooms service', () => {

describe('for column boards', () => {
const setup = () => {
lessonRepo.findAllByCourseIds.mockResolvedValueOnce([[], 0]);
lessonService.findByCourseIds.mockResolvedValueOnce([[], 0]);
taskService.findBySingleParent.mockResolvedValueOnce([[], 0]);

const user = userFactory.buildWithId();
Expand Down
11 changes: 6 additions & 5 deletions apps/server/src/modules/learnroom/service/rooms.service.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { Configuration } from '@hpi-schul-cloud/commons/lib';
import { ColumnBoardService } from '@modules/board';
import { LessonService } from '@modules/lesson';
import { TaskService } from '@modules/task';
import { Injectable } from '@nestjs/common';
import { Board, BoardExternalReferenceType, ColumnBoardTarget, EntityId } from '@shared/domain';
import { BoardRepo, LessonRepo } from '@shared/repo';
import { ColumnBoardService } from '@modules/board';
import { TaskService } from '@modules/task/service';
import { BoardRepo } from '@shared/repo';
import { ColumnBoardTargetService } from './column-board-target.service';

@Injectable()
export class RoomsService {
constructor(
private readonly taskService: TaskService,
private readonly lessonRepo: LessonRepo,
private readonly lessonService: LessonService,
private readonly boardRepo: BoardRepo,
private readonly columnBoardService: ColumnBoardService,
private readonly columnBoardTargetService: ColumnBoardTargetService
) {}

async updateBoard(board: Board, roomId: EntityId, userId: EntityId): Promise<Board> {
const [courseLessons] = await this.lessonRepo.findAllByCourseIds([roomId]);
const [courseLessons] = await this.lessonService.findByCourseIds([roomId]);
const [courseTasks] = await this.taskService.findBySingleParent(userId, roomId);

const courseColumnBoardTargets = await this.handleColumnBoardIntegration(roomId);
Expand Down
Loading

0 comments on commit eb9cf54

Please sign in to comment.