diff --git a/apps/server/src/modules/authentication/authentication.module.ts b/apps/server/src/modules/authentication/authentication.module.ts index e0fb4570dcd..1cfdca45fde 100644 --- a/apps/server/src/modules/authentication/authentication.module.ts +++ b/apps/server/src/modules/authentication/authentication.module.ts @@ -3,7 +3,7 @@ import { JwtModule, JwtModuleOptions } from '@nestjs/jwt'; import { PassportModule } from '@nestjs/passport'; import { CacheWrapperModule } from '@shared/infra/cache'; import { IdentityManagementModule } from '@shared/infra/identity-management'; -import { SchoolRepo, SystemRepo, UserRepo } from '@shared/repo'; +import { LegacySchoolRepo, SystemRepo, UserRepo } from '@shared/repo'; import { LoggerModule } from '@src/core/logger'; import { AccountModule } from '@src/modules/account'; import { OauthModule } from '@src/modules/oauth/oauth.module'; @@ -70,7 +70,7 @@ const jwtModuleOptions: JwtModuleOptions = { JwtValidationAdapter, UserRepo, SystemRepo, - SchoolRepo, + LegacySchoolRepo, LocalStrategy, AuthenticationService, LdapService, diff --git a/apps/server/src/modules/authentication/strategy/ldap.strategy.spec.ts b/apps/server/src/modules/authentication/strategy/ldap.strategy.spec.ts index 44403b0adaf..4815921ca1b 100644 --- a/apps/server/src/modules/authentication/strategy/ldap.strategy.spec.ts +++ b/apps/server/src/modules/authentication/strategy/ldap.strategy.spec.ts @@ -2,14 +2,13 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { UnauthorizedException } from '@nestjs/common'; import { PassportModule } from '@nestjs/passport'; import { Test, TestingModule } from '@nestjs/testing'; -import { RoleName, System, User } from '@shared/domain'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { SchoolRepo, SystemRepo, UserRepo } from '@shared/repo'; +import { LegacySchoolDo, RoleName, System, User } from '@shared/domain'; +import { LegacySchoolRepo, SystemRepo, UserRepo } from '@shared/repo'; import { accountDtoFactory, defaultTestPassword, defaultTestPasswordHash, - schoolDOFactory, + legacySchoolDoFactory, schoolFactory, setupEntities, systemFactory, @@ -28,7 +27,7 @@ describe('LdapStrategy', () => { let strategy: LdapStrategy; let userRepoMock: DeepMocked; - let schoolRepoMock: DeepMocked; + let schoolRepoMock: DeepMocked; let authenticationServiceMock: DeepMocked; let ldapServiceMock: DeepMocked; let systemRepo: DeepMocked; @@ -53,8 +52,8 @@ describe('LdapStrategy', () => { useValue: createMock(), }, { - provide: SchoolRepo, - useValue: createMock(), + provide: LegacySchoolRepo, + useValue: createMock(), }, { provide: SystemRepo, @@ -69,7 +68,7 @@ describe('LdapStrategy', () => { strategy = module.get(LdapStrategy); authenticationServiceMock = module.get(AuthenticationService); - schoolRepoMock = module.get(SchoolRepo); + schoolRepoMock = module.get(LegacySchoolRepo); userRepoMock = module.get(UserRepo); ldapServiceMock = module.get(LdapService); systemRepo = module.get(SystemRepo); @@ -92,7 +91,7 @@ describe('LdapStrategy', () => { const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: undefined }); - const school: SchoolDO = schoolDOFactory.buildWithId({ systems: [system.id] }, user.school.id); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: [system.id] }, user.school.id); const account: AccountDto = accountDtoFactory.build({ systemId: system.id, @@ -139,7 +138,7 @@ describe('LdapStrategy', () => { const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: 'mockLdapDn' }); - const school: SchoolDO = schoolDOFactory.buildWithId({ systems: [] }, user.school.id); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: [] }, user.school.id); const account: AccountDto = accountDtoFactory.build({ systemId: system.id, @@ -186,7 +185,7 @@ describe('LdapStrategy', () => { const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: 'mockLdapDn' }); - const school: SchoolDO = schoolDOFactory.buildWithId({ systems: undefined }, user.school.id); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: undefined }, user.school.id); const account: AccountDto = accountDtoFactory.build({ systemId: system.id, @@ -233,7 +232,7 @@ describe('LdapStrategy', () => { const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: 'mockLdapDn' }); - const school: SchoolDO = schoolDOFactory.buildWithId({ systems: [system.id] }, user.school.id); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: [system.id] }, user.school.id); const account: AccountDto = accountDtoFactory.build({ systemId: system.id, @@ -280,7 +279,7 @@ describe('LdapStrategy', () => { const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: 'mockLdapDn' }); - const school: SchoolDO = schoolDOFactory.buildWithId({ systems: [system.id] }, user.school.id); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: [system.id] }, user.school.id); const account: AccountDto = accountDtoFactory.build({ systemId: system.id, @@ -332,7 +331,7 @@ describe('LdapStrategy', () => { const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: 'mockLdapDn' }); - const school: SchoolDO = schoolDOFactory.buildWithId({ systems: [system.id] }, user.school.id); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: [system.id] }, user.school.id); const account: AccountDto = accountDtoFactory.build({ systemId: system.id, @@ -389,7 +388,7 @@ describe('LdapStrategy', () => { .withRoleByName(RoleName.STUDENT) .buildWithId({ ldapDn: 'mockLdapDn', school: schoolFactory.buildWithId() }); - const school: SchoolDO = schoolDOFactory.buildWithId( + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId( { systems: [system.id], previousExternalId: undefined }, user.school.id ); @@ -451,7 +450,7 @@ describe('LdapStrategy', () => { .withRoleByName(RoleName.STUDENT) .buildWithId({ ldapDn: 'mockLdapDn', school: schoolFactory.buildWithId() }); - const school: SchoolDO = schoolDOFactory.buildWithId( + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId( { systems: [system.id], previousExternalId: 'previousExternalId' }, user.school.id ); diff --git a/apps/server/src/modules/authentication/strategy/ldap.strategy.ts b/apps/server/src/modules/authentication/strategy/ldap.strategy.ts index 3e5327c62aa..df823592378 100644 --- a/apps/server/src/modules/authentication/strategy/ldap.strategy.ts +++ b/apps/server/src/modules/authentication/strategy/ldap.strategy.ts @@ -1,8 +1,7 @@ import { Injectable, UnauthorizedException } from '@nestjs/common'; import { PassportStrategy } from '@nestjs/passport'; -import { System, User } from '@shared/domain'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { SchoolRepo, SystemRepo, UserRepo } from '@shared/repo'; +import { LegacySchoolDo, System, User } from '@shared/domain'; +import { LegacySchoolRepo, SystemRepo, UserRepo } from '@shared/repo'; import { ErrorLoggable } from '@src/core/error/loggable/error.loggable'; import { Logger } from '@src/core/logger'; import { AccountDto } from '@src/modules/account/services/dto'; @@ -17,7 +16,7 @@ import { LdapService } from '../services/ldap.service'; export class LdapStrategy extends PassportStrategy(Strategy, 'ldap') { constructor( private readonly systemRepo: SystemRepo, - private readonly schoolRepo: SchoolRepo, + private readonly schoolRepo: LegacySchoolRepo, private readonly ldapService: LdapService, private readonly authenticationService: AuthenticationService, private readonly userRepo: UserRepo, @@ -31,7 +30,7 @@ export class LdapStrategy extends PassportStrategy(Strategy, 'ldap') { const system: System = await this.systemRepo.findById(systemId); - const school: SchoolDO = await this.schoolRepo.findById(schoolId); + const school: LegacySchoolDo = await this.schoolRepo.findById(schoolId); if (!school.systems || !school.systems.includes(systemId)) { throw new UnauthorizedException(`School ${schoolId} does not have the selected system ${systemId}`); @@ -84,7 +83,7 @@ export class LdapStrategy extends PassportStrategy(Strategy, 'ldap') { } } - private async loadAccount(username: string, systemId: string, school: SchoolDO): Promise { + private async loadAccount(username: string, systemId: string, school: LegacySchoolDo): Promise { const externalSchoolId = this.checkValue(school.externalId); let account: AccountDto; diff --git a/apps/server/src/modules/authorization/authorization.module.ts b/apps/server/src/modules/authorization/authorization.module.ts index fbb33c0c4ea..c983ee187fd 100644 --- a/apps/server/src/modules/authorization/authorization.module.ts +++ b/apps/server/src/modules/authorization/authorization.module.ts @@ -6,14 +6,14 @@ import { CourseRepo, LessonRepo, SchoolExternalToolRepo, - SchoolRepo, + LegacySchoolRepo, SubmissionRepo, TaskRepo, TeamsRepo, UserRepo, } from '@shared/repo'; import { LoggerModule } from '@src/core/logger'; -import { SchoolModule } from '@src/modules/school'; +import { LegacySchoolModule } from '@src/modules/legacy-school'; import { ToolModule } from '@src/modules/tool'; import { BoardModule } from '../board'; import { AuthorizationHelper } from './authorization.helper'; @@ -24,7 +24,13 @@ import { RuleManager } from './rule-manager'; @Module({ // TODO: remove forwardRef to TooModule N21-1055 - imports: [FeathersModule, LoggerModule, SchoolModule, forwardRef(() => ToolModule), forwardRef(() => BoardModule)], + imports: [ + FeathersModule, + LoggerModule, + LegacySchoolModule, + forwardRef(() => ToolModule), + forwardRef(() => BoardModule), + ], providers: [ FeathersAuthorizationService, FeathersAuthProvider, @@ -35,7 +41,7 @@ import { RuleManager } from './rule-manager'; CourseRepo, CourseGroupRepo, TaskRepo, - SchoolRepo, + LegacySchoolRepo, LessonRepo, TeamsRepo, SubmissionRepo, diff --git a/apps/server/src/modules/authorization/reference.loader.spec.ts b/apps/server/src/modules/authorization/reference.loader.spec.ts index 76501434a4e..9bba78b1880 100644 --- a/apps/server/src/modules/authorization/reference.loader.spec.ts +++ b/apps/server/src/modules/authorization/reference.loader.spec.ts @@ -8,7 +8,7 @@ import { CourseRepo, LessonRepo, SchoolExternalToolRepo, - SchoolRepo, + LegacySchoolRepo, SubmissionRepo, TaskRepo, TeamsRepo, @@ -26,7 +26,7 @@ describe('reference.loader', () => { let courseRepo: DeepMocked; let courseGroupRepo: DeepMocked; let taskRepo: DeepMocked; - let schoolRepo: DeepMocked; + let schoolRepo: DeepMocked; let lessonRepo: DeepMocked; let teamsRepo: DeepMocked; let submissionRepo: DeepMocked; @@ -58,8 +58,8 @@ describe('reference.loader', () => { useValue: createMock(), }, { - provide: SchoolRepo, - useValue: createMock(), + provide: LegacySchoolRepo, + useValue: createMock(), }, { provide: LessonRepo, @@ -93,7 +93,7 @@ describe('reference.loader', () => { courseRepo = await module.get(CourseRepo); courseGroupRepo = await module.get(CourseGroupRepo); taskRepo = await module.get(TaskRepo); - schoolRepo = await module.get(SchoolRepo); + schoolRepo = await module.get(LegacySchoolRepo); lessonRepo = await module.get(LessonRepo); teamsRepo = await module.get(TeamsRepo); submissionRepo = await module.get(SubmissionRepo); diff --git a/apps/server/src/modules/authorization/reference.loader.ts b/apps/server/src/modules/authorization/reference.loader.ts index 550f1f02762..9afe013fd24 100644 --- a/apps/server/src/modules/authorization/reference.loader.ts +++ b/apps/server/src/modules/authorization/reference.loader.ts @@ -6,7 +6,7 @@ import { CourseRepo, LessonRepo, SchoolExternalToolRepo, - SchoolRepo, + LegacySchoolRepo, SubmissionRepo, TaskRepo, TeamsRepo, @@ -21,7 +21,7 @@ type RepoType = | TaskRepo | CourseRepo | UserRepo - | SchoolRepo + | LegacySchoolRepo | LessonRepo | TeamsRepo | CourseGroupRepo @@ -44,7 +44,7 @@ export class ReferenceLoader { private readonly courseRepo: CourseRepo, private readonly courseGroupRepo: CourseGroupRepo, private readonly taskRepo: TaskRepo, - private readonly schoolRepo: SchoolRepo, + private readonly schoolRepo: LegacySchoolRepo, private readonly lessonRepo: LessonRepo, private readonly teamsRepo: TeamsRepo, private readonly submissionRepo: SubmissionRepo, diff --git a/apps/server/src/modules/authorization/rule-manager.spec.ts b/apps/server/src/modules/authorization/rule-manager.spec.ts index f7bd1edde5c..0a2b90c7639 100644 --- a/apps/server/src/modules/authorization/rule-manager.spec.ts +++ b/apps/server/src/modules/authorization/rule-manager.spec.ts @@ -8,7 +8,7 @@ import { CourseRule, LessonRule, SchoolExternalToolRule, - SchoolRule, + LegacySchoolRule, SubmissionRule, TaskRule, TeamRule, @@ -24,7 +24,7 @@ describe('RuleManager', () => { let courseRule: DeepMocked; let courseGroupRule: DeepMocked; let lessonRule: DeepMocked; - let schoolRule: DeepMocked; + let legacySchoolRule: DeepMocked; let userRule: DeepMocked; let taskRule: DeepMocked; let teamRule: DeepMocked; @@ -43,7 +43,7 @@ describe('RuleManager', () => { { provide: CourseRule, useValue: createMock() }, { provide: CourseGroupRule, useValue: createMock() }, { provide: LessonRule, useValue: createMock() }, - { provide: SchoolRule, useValue: createMock() }, + { provide: LegacySchoolRule, useValue: createMock() }, { provide: UserRule, useValue: createMock() }, { provide: TaskRule, useValue: createMock() }, { provide: TeamRule, useValue: createMock() }, @@ -59,7 +59,7 @@ describe('RuleManager', () => { courseRule = await module.get(CourseRule); courseGroupRule = await module.get(CourseGroupRule); lessonRule = await module.get(LessonRule); - schoolRule = await module.get(SchoolRule); + legacySchoolRule = await module.get(LegacySchoolRule); userRule = await module.get(UserRule); taskRule = await module.get(TaskRule); teamRule = await module.get(TeamRule); @@ -89,7 +89,7 @@ describe('RuleManager', () => { courseRule.isApplicable.mockReturnValueOnce(true); courseGroupRule.isApplicable.mockReturnValueOnce(false); lessonRule.isApplicable.mockReturnValueOnce(false); - schoolRule.isApplicable.mockReturnValueOnce(false); + legacySchoolRule.isApplicable.mockReturnValueOnce(false); userRule.isApplicable.mockReturnValueOnce(false); taskRule.isApplicable.mockReturnValueOnce(false); teamRule.isApplicable.mockReturnValueOnce(false); @@ -110,7 +110,7 @@ describe('RuleManager', () => { expect(courseRule.isApplicable).toBeCalled(); expect(courseGroupRule.isApplicable).toBeCalled(); expect(lessonRule.isApplicable).toBeCalled(); - expect(schoolRule.isApplicable).toBeCalled(); + expect(legacySchoolRule.isApplicable).toBeCalled(); expect(userRule.isApplicable).toBeCalled(); expect(taskRule.isApplicable).toBeCalled(); expect(teamRule.isApplicable).toBeCalled(); @@ -139,7 +139,7 @@ describe('RuleManager', () => { courseRule.isApplicable.mockReturnValueOnce(false); courseGroupRule.isApplicable.mockReturnValueOnce(false); lessonRule.isApplicable.mockReturnValueOnce(false); - schoolRule.isApplicable.mockReturnValueOnce(false); + legacySchoolRule.isApplicable.mockReturnValueOnce(false); userRule.isApplicable.mockReturnValueOnce(false); taskRule.isApplicable.mockReturnValueOnce(false); teamRule.isApplicable.mockReturnValueOnce(false); @@ -168,7 +168,7 @@ describe('RuleManager', () => { courseRule.isApplicable.mockReturnValueOnce(true); courseGroupRule.isApplicable.mockReturnValueOnce(true); lessonRule.isApplicable.mockReturnValueOnce(false); - schoolRule.isApplicable.mockReturnValueOnce(false); + legacySchoolRule.isApplicable.mockReturnValueOnce(false); userRule.isApplicable.mockReturnValueOnce(false); taskRule.isApplicable.mockReturnValueOnce(false); teamRule.isApplicable.mockReturnValueOnce(false); diff --git a/apps/server/src/modules/authorization/rule-manager.ts b/apps/server/src/modules/authorization/rule-manager.ts index 8d0fa8a629d..3aece68402a 100644 --- a/apps/server/src/modules/authorization/rule-manager.ts +++ b/apps/server/src/modules/authorization/rule-manager.ts @@ -7,7 +7,7 @@ import { CourseRule, LessonRule, SchoolExternalToolRule, - SchoolRule, + LegacySchoolRule, SubmissionRule, TaskRule, TeamRule, @@ -25,7 +25,7 @@ export class RuleManager { private readonly courseRule: CourseRule, private readonly courseGroupRule: CourseGroupRule, private readonly lessonRule: LessonRule, - private readonly schoolRule: SchoolRule, + private readonly legaySchoolRule: LegacySchoolRule, private readonly taskRule: TaskRule, private readonly userRule: UserRule, private readonly teamRule: TeamRule, @@ -42,7 +42,7 @@ export class RuleManager { this.taskRule, this.teamRule, this.userRule, - this.schoolRule, + this.legaySchoolRule, this.submissionRule, this.schoolExternalToolRule, this.boardDoRule, diff --git a/apps/server/src/modules/index.ts b/apps/server/src/modules/index.ts index 6e0070a7867..111a64d9f33 100644 --- a/apps/server/src/modules/index.ts +++ b/apps/server/src/modules/index.ts @@ -14,7 +14,7 @@ export * from './oauth-provider'; export * from './provisioning'; export * from './rocketchat'; export * from './role'; -export * from './school'; +export * from './legacy-school'; export * from './sharing'; export * from './system'; export * from './task'; diff --git a/apps/server/src/modules/school/controller/dto/index.ts b/apps/server/src/modules/legacy-school/controller/dto/index.ts similarity index 100% rename from apps/server/src/modules/school/controller/dto/index.ts rename to apps/server/src/modules/legacy-school/controller/dto/index.ts diff --git a/apps/server/src/modules/school/controller/dto/migration.body.ts b/apps/server/src/modules/legacy-school/controller/dto/migration.body.ts similarity index 100% rename from apps/server/src/modules/school/controller/dto/migration.body.ts rename to apps/server/src/modules/legacy-school/controller/dto/migration.body.ts diff --git a/apps/server/src/modules/school/controller/dto/migration.response.ts b/apps/server/src/modules/legacy-school/controller/dto/migration.response.ts similarity index 100% rename from apps/server/src/modules/school/controller/dto/migration.response.ts rename to apps/server/src/modules/legacy-school/controller/dto/migration.response.ts diff --git a/apps/server/src/modules/school/controller/dto/school.params.ts b/apps/server/src/modules/legacy-school/controller/dto/school.params.ts similarity index 100% rename from apps/server/src/modules/school/controller/dto/school.params.ts rename to apps/server/src/modules/legacy-school/controller/dto/school.params.ts diff --git a/apps/server/src/modules/school/controller/school.controller.spec.ts b/apps/server/src/modules/legacy-school/controller/legacy-school.controller.spec.ts similarity index 86% rename from apps/server/src/modules/school/controller/school.controller.spec.ts rename to apps/server/src/modules/legacy-school/controller/legacy-school.controller.spec.ts index cd41a61edf0..1777ad02faa 100644 --- a/apps/server/src/modules/school/controller/school.controller.spec.ts +++ b/apps/server/src/modules/legacy-school/controller/legacy-school.controller.spec.ts @@ -4,23 +4,23 @@ import { Test, TestingModule } from '@nestjs/testing'; import { ICurrentUser } from '@src/modules/authentication'; import { MigrationMapper } from '../mapper/migration.mapper'; import { OauthMigrationDto } from '../uc/dto/oauth-migration.dto'; -import { SchoolUc } from '../uc/school.uc'; +import { LegacySchoolUc } from '../uc'; import { MigrationBody, MigrationResponse, SchoolParams } from './dto'; -import { SchoolController } from './school.controller'; +import { LegacySchoolController } from './legacy-school.controller'; -describe('School Controller', () => { +describe('Legacy School Controller', () => { let module: TestingModule; - let controller: SchoolController; - let schoolUc: DeepMocked; + let controller: LegacySchoolController; + let schoolUc: DeepMocked; let mapper: DeepMocked; beforeAll(async () => { module = await Test.createTestingModule({ - controllers: [SchoolController], + controllers: [LegacySchoolController], providers: [ { - provide: SchoolUc, - useValue: createMock(), + provide: LegacySchoolUc, + useValue: createMock(), }, { provide: MigrationMapper, @@ -28,8 +28,8 @@ describe('School Controller', () => { }, ], }).compile(); - controller = module.get(SchoolController); - schoolUc = module.get(SchoolUc); + controller = module.get(LegacySchoolController); + schoolUc = module.get(LegacySchoolUc); mapper = module.get(MigrationMapper); }); diff --git a/apps/server/src/modules/school/controller/school.controller.ts b/apps/server/src/modules/legacy-school/controller/legacy-school.controller.ts similarity index 88% rename from apps/server/src/modules/school/controller/school.controller.ts rename to apps/server/src/modules/legacy-school/controller/legacy-school.controller.ts index e4d3c8c3a7a..a91d8662752 100644 --- a/apps/server/src/modules/school/controller/school.controller.ts +++ b/apps/server/src/modules/legacy-school/controller/legacy-school.controller.ts @@ -10,14 +10,17 @@ import { ICurrentUser } from '@src/modules/authentication'; import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator'; import { MigrationMapper } from '../mapper/migration.mapper'; import { OauthMigrationDto } from '../uc/dto/oauth-migration.dto'; -import { SchoolUc } from '../uc/school.uc'; +import { LegacySchoolUc } from '../uc'; import { MigrationBody, MigrationResponse, SchoolParams } from './dto'; +/** + * @deprecated because it uses the deprecated LegacySchoolDo. + */ @ApiTags('School') @Authenticate('jwt') @Controller('school') -export class SchoolController { - constructor(private readonly schoolUc: SchoolUc, private readonly migrationMapper: MigrationMapper) {} +export class LegacySchoolController { + constructor(private readonly schoolUc: LegacySchoolUc, private readonly migrationMapper: MigrationMapper) {} @Put(':schoolId/migration') @Authenticate('jwt') diff --git a/apps/server/src/modules/school/error/index.ts b/apps/server/src/modules/legacy-school/error/index.ts similarity index 100% rename from apps/server/src/modules/school/error/index.ts rename to apps/server/src/modules/legacy-school/error/index.ts diff --git a/apps/server/src/modules/school/error/school-number-duplicate.loggable-exception.spec.ts b/apps/server/src/modules/legacy-school/error/school-number-duplicate.loggable-exception.spec.ts similarity index 100% rename from apps/server/src/modules/school/error/school-number-duplicate.loggable-exception.spec.ts rename to apps/server/src/modules/legacy-school/error/school-number-duplicate.loggable-exception.spec.ts diff --git a/apps/server/src/modules/school/error/school-number-duplicate.loggable-exception.ts b/apps/server/src/modules/legacy-school/error/school-number-duplicate.loggable-exception.ts similarity index 100% rename from apps/server/src/modules/school/error/school-number-duplicate.loggable-exception.ts rename to apps/server/src/modules/legacy-school/error/school-number-duplicate.loggable-exception.ts diff --git a/apps/server/src/modules/legacy-school/index.ts b/apps/server/src/modules/legacy-school/index.ts new file mode 100644 index 00000000000..8d7162ddf07 --- /dev/null +++ b/apps/server/src/modules/legacy-school/index.ts @@ -0,0 +1,2 @@ +export * from './legacy-school.module'; +export * from './service'; diff --git a/apps/server/src/modules/legacy-school/legacy-school-api.module.ts b/apps/server/src/modules/legacy-school/legacy-school-api.module.ts new file mode 100644 index 00000000000..3072fa8f6ca --- /dev/null +++ b/apps/server/src/modules/legacy-school/legacy-school-api.module.ts @@ -0,0 +1,18 @@ +import { Module } from '@nestjs/common'; +import { AuthorizationModule } from '@src/modules/authorization'; +import { LoggerModule } from '@src/core/logger'; +import { UserLoginMigrationModule } from '@src/modules/user-login-migration'; +import { LegacySchoolUc } from './uc'; +import { LegacySchoolModule } from './legacy-school.module'; +import { LegacySchoolController } from './controller/legacy-school.controller'; +import { MigrationMapper } from './mapper/migration.mapper'; + +/** + * @deprecated because it uses the deprecated LegacySchoolDo. + */ +@Module({ + imports: [LegacySchoolModule, AuthorizationModule, LoggerModule, UserLoginMigrationModule], + controllers: [LegacySchoolController], + providers: [LegacySchoolUc, MigrationMapper], +}) +export class LegacySchoolApiModule {} diff --git a/apps/server/src/modules/legacy-school/legacy-school.module.ts b/apps/server/src/modules/legacy-school/legacy-school.module.ts new file mode 100644 index 00000000000..8547c417055 --- /dev/null +++ b/apps/server/src/modules/legacy-school/legacy-school.module.ts @@ -0,0 +1,23 @@ +import { Module } from '@nestjs/common'; +import { FederalStateRepo, LegacySchoolRepo } from '@shared/repo'; +import { LoggerModule } from '@src/core/logger'; +import { SchoolYearRepo } from './repo'; +import { FederalStateService, LegacySchoolService, SchoolValidationService, SchoolYearService } from './service'; + +/** + * @deprecated because it uses the deprecated LegacySchoolDo. + */ +@Module({ + imports: [LoggerModule], + providers: [ + LegacySchoolRepo, + LegacySchoolService, + SchoolYearService, + SchoolYearRepo, + FederalStateService, + FederalStateRepo, + SchoolValidationService, + ], + exports: [LegacySchoolService, SchoolYearService, FederalStateService], +}) +export class LegacySchoolModule {} diff --git a/apps/server/src/modules/school/mapper/migration.mapper.spec.ts b/apps/server/src/modules/legacy-school/mapper/migration.mapper.spec.ts similarity index 100% rename from apps/server/src/modules/school/mapper/migration.mapper.spec.ts rename to apps/server/src/modules/legacy-school/mapper/migration.mapper.spec.ts diff --git a/apps/server/src/modules/school/mapper/migration.mapper.ts b/apps/server/src/modules/legacy-school/mapper/migration.mapper.ts similarity index 100% rename from apps/server/src/modules/school/mapper/migration.mapper.ts rename to apps/server/src/modules/legacy-school/mapper/migration.mapper.ts diff --git a/apps/server/src/modules/school/repo/index.ts b/apps/server/src/modules/legacy-school/repo/index.ts similarity index 100% rename from apps/server/src/modules/school/repo/index.ts rename to apps/server/src/modules/legacy-school/repo/index.ts diff --git a/apps/server/src/modules/school/repo/schoolyear.repo.integration.spec.ts b/apps/server/src/modules/legacy-school/repo/schoolyear.repo.integration.spec.ts similarity index 100% rename from apps/server/src/modules/school/repo/schoolyear.repo.integration.spec.ts rename to apps/server/src/modules/legacy-school/repo/schoolyear.repo.integration.spec.ts diff --git a/apps/server/src/modules/school/repo/schoolyear.repo.ts b/apps/server/src/modules/legacy-school/repo/schoolyear.repo.ts similarity index 100% rename from apps/server/src/modules/school/repo/schoolyear.repo.ts rename to apps/server/src/modules/legacy-school/repo/schoolyear.repo.ts diff --git a/apps/server/src/modules/school/service/federal-state.service.spec.ts b/apps/server/src/modules/legacy-school/service/federal-state.service.spec.ts similarity index 100% rename from apps/server/src/modules/school/service/federal-state.service.spec.ts rename to apps/server/src/modules/legacy-school/service/federal-state.service.spec.ts diff --git a/apps/server/src/modules/school/service/federal-state.service.ts b/apps/server/src/modules/legacy-school/service/federal-state.service.ts similarity index 100% rename from apps/server/src/modules/school/service/federal-state.service.ts rename to apps/server/src/modules/legacy-school/service/federal-state.service.ts diff --git a/apps/server/src/modules/school/service/index.ts b/apps/server/src/modules/legacy-school/service/index.ts similarity index 72% rename from apps/server/src/modules/school/service/index.ts rename to apps/server/src/modules/legacy-school/service/index.ts index f216df3e8e8..09f01c98215 100644 --- a/apps/server/src/modules/school/service/index.ts +++ b/apps/server/src/modules/legacy-school/service/index.ts @@ -1,4 +1,4 @@ -export * from './school.service'; +export * from './legacy-school.service'; export * from './school-year.service'; export * from './federal-state.service'; export * from './validation'; diff --git a/apps/server/src/modules/school/service/school.service.spec.ts b/apps/server/src/modules/legacy-school/service/legacy-school.service.spec.ts similarity index 80% rename from apps/server/src/modules/school/service/school.service.spec.ts rename to apps/server/src/modules/legacy-school/service/legacy-school.service.spec.ts index 8d303aa0e5b..57cc3c6f1ee 100644 --- a/apps/server/src/modules/school/service/school.service.spec.ts +++ b/apps/server/src/modules/legacy-school/service/legacy-school.service.spec.ts @@ -1,26 +1,25 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; -import { SchoolFeatures } from '@shared/domain'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { SchoolRepo } from '@shared/repo'; -import { schoolDOFactory, setupEntities } from '@shared/testing'; -import { SchoolService } from './school.service'; +import { LegacySchoolDo, SchoolFeatures } from '@shared/domain'; +import { LegacySchoolRepo } from '@shared/repo'; +import { legacySchoolDoFactory, setupEntities } from '@shared/testing'; +import { LegacySchoolService } from './legacy-school.service'; import { SchoolValidationService } from './validation/school-validation.service'; -describe('SchoolService', () => { +describe('LegacySchoolService', () => { let module: TestingModule; - let schoolService: SchoolService; + let schoolService: LegacySchoolService; - let schoolRepo: DeepMocked; + let schoolRepo: DeepMocked; let schoolValidationService: DeepMocked; beforeAll(async () => { module = await Test.createTestingModule({ providers: [ - SchoolService, + LegacySchoolService, { - provide: SchoolRepo, - useValue: createMock(), + provide: LegacySchoolRepo, + useValue: createMock(), }, { provide: SchoolValidationService, @@ -29,8 +28,8 @@ describe('SchoolService', () => { ], }).compile(); - schoolRepo = module.get(SchoolRepo); - schoolService = module.get(SchoolService); + schoolRepo = module.get(LegacySchoolRepo); + schoolService = module.get(LegacySchoolService); schoolValidationService = module.get(SchoolValidationService); await setupEntities(); @@ -42,7 +41,7 @@ describe('SchoolService', () => { const setupOld = () => { const systems: string[] = ['systemId']; - const schoolSaved: SchoolDO = schoolDOFactory.build({ + const schoolSaved: LegacySchoolDo = legacySchoolDoFactory.build({ id: 'testId', name: 'schoolName', externalId: 'externalId', @@ -50,7 +49,7 @@ describe('SchoolService', () => { systems, features: [SchoolFeatures.VIDEOCONFERENCE], }); - const schoolUnsaved: SchoolDO = schoolDOFactory.build({ name: 'school #2}', systems: [] }); + const schoolUnsaved: LegacySchoolDo = legacySchoolDoFactory.build({ name: 'school #2}', systems: [] }); schoolRepo.findById.mockResolvedValue(schoolSaved); schoolRepo.findByExternalId.mockResolvedValue(schoolSaved); schoolRepo.findBySchoolNumber.mockResolvedValue(schoolSaved); @@ -110,7 +109,7 @@ describe('SchoolService', () => { describe('removeFeature', () => { describe('when given schoolFeature exists on school', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.buildWithId({ + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ features: [SchoolFeatures.VIDEOCONFERENCE, SchoolFeatures.OAUTH_PROVISIONING_ENABLED], }); @@ -132,7 +131,7 @@ describe('SchoolService', () => { describe('when school has a feature which should be removed', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.buildWithId({ + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ features: [SchoolFeatures.VIDEOCONFERENCE, SchoolFeatures.OAUTH_PROVISIONING_ENABLED], }); @@ -170,9 +169,9 @@ describe('SchoolService', () => { it('should return a do', async () => { const { schoolSavedId } = setupOld(); - const schoolDO: SchoolDO = await schoolService.getSchoolById(schoolSavedId); + const schoolDO: LegacySchoolDo = await schoolService.getSchoolById(schoolSavedId); - expect(schoolDO).toBeInstanceOf(SchoolDO); + expect(schoolDO).toBeInstanceOf(LegacySchoolDo); }); }); }); @@ -189,16 +188,19 @@ describe('SchoolService', () => { it('should return a do', async () => { const { schoolSavedExternalId, systems } = setupOld(); - const schoolDO: SchoolDO | null = await schoolService.getSchoolByExternalId(schoolSavedExternalId, systems[0]); + const schoolDO: LegacySchoolDo | null = await schoolService.getSchoolByExternalId( + schoolSavedExternalId, + systems[0] + ); - expect(schoolDO).toBeInstanceOf(SchoolDO); + expect(schoolDO).toBeInstanceOf(LegacySchoolDo); }); it('should return null', async () => { const { systems } = setupOld(); schoolRepo.findByExternalId.mockResolvedValue(null); - const schoolDO: SchoolDO | null = await schoolService.getSchoolByExternalId('null', systems[0]); + const schoolDO: LegacySchoolDo | null = await schoolService.getSchoolByExternalId('null', systems[0]); expect(schoolDO).toBeNull(); }); @@ -216,14 +218,14 @@ describe('SchoolService', () => { it('should return a do', async () => { const { schoolSavedNumber } = setupOld(); - const schoolDO: SchoolDO | null = await schoolService.getSchoolBySchoolNumber(schoolSavedNumber); + const schoolDO: LegacySchoolDo | null = await schoolService.getSchoolBySchoolNumber(schoolSavedNumber); - expect(schoolDO).toBeInstanceOf(SchoolDO); + expect(schoolDO).toBeInstanceOf(LegacySchoolDo); }); it('should return null', async () => { schoolRepo.findBySchoolNumber.mockResolvedValue(null); - const schoolDO: SchoolDO | null = await schoolService.getSchoolBySchoolNumber('null'); + const schoolDO: LegacySchoolDo | null = await schoolService.getSchoolBySchoolNumber('null'); expect(schoolDO).toBeNull(); }); @@ -232,7 +234,7 @@ describe('SchoolService', () => { describe('save is called', () => { describe('when validation is deactivated', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.build(); + const school: LegacySchoolDo = legacySchoolDoFactory.build(); schoolRepo.save.mockResolvedValue(school); @@ -252,7 +254,7 @@ describe('SchoolService', () => { it('should return a do', async () => { const { school } = setup(); - const schoolDO: SchoolDO = await schoolService.save(school); + const schoolDO: LegacySchoolDo = await schoolService.save(school); expect(schoolDO).toBeDefined(); }); @@ -269,7 +271,7 @@ describe('SchoolService', () => { describe('when validation is active', () => { describe('when the validation fails', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.build(); + const school: LegacySchoolDo = legacySchoolDoFactory.build(); schoolRepo.save.mockResolvedValueOnce(school); schoolValidationService.validate.mockRejectedValueOnce(new Error()); @@ -306,7 +308,7 @@ describe('SchoolService', () => { describe('when the validation succeeds', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.build(); + const school: LegacySchoolDo = legacySchoolDoFactory.build(); schoolRepo.save.mockResolvedValueOnce(school); @@ -326,7 +328,7 @@ describe('SchoolService', () => { it('should return a do', async () => { const { school } = setup(); - const schoolDO: SchoolDO = await schoolService.save(school, true); + const schoolDO: LegacySchoolDo = await schoolService.save(school, true); expect(schoolDO).toBeDefined(); }); diff --git a/apps/server/src/modules/legacy-school/service/legacy-school.service.ts b/apps/server/src/modules/legacy-school/service/legacy-school.service.ts new file mode 100644 index 00000000000..1ed43fd5f07 --- /dev/null +++ b/apps/server/src/modules/legacy-school/service/legacy-school.service.ts @@ -0,0 +1,56 @@ +import { Injectable } from '@nestjs/common'; +import { EntityId, LegacySchoolDo, SchoolFeatures } from '@shared/domain'; +import { LegacySchoolRepo } from '@shared/repo'; +import { SchoolValidationService } from './validation'; + +/** + * @deprecated because it uses the deprecated LegacySchoolDo. + */ +@Injectable() +export class LegacySchoolService { + constructor( + private readonly schoolRepo: LegacySchoolRepo, + private readonly schoolValidationService: SchoolValidationService + ) {} + + async hasFeature(schoolId: EntityId, feature: SchoolFeatures): Promise { + const entity: LegacySchoolDo = await this.schoolRepo.findById(schoolId); + return entity.features ? entity.features.includes(feature) : false; + } + + async removeFeature(schoolId: EntityId, feature: SchoolFeatures): Promise { + const school: LegacySchoolDo = await this.schoolRepo.findById(schoolId); + if (school.features && school.features.includes(feature)) { + school.features = school.features.filter((f: SchoolFeatures) => f !== feature); + await this.schoolRepo.save(school); + } + } + + async getSchoolById(id: string): Promise { + const schoolDO: LegacySchoolDo = await this.schoolRepo.findById(id); + + return schoolDO; + } + + async getSchoolByExternalId(externalId: string, systemId: string): Promise { + const schoolDO: LegacySchoolDo | null = await this.schoolRepo.findByExternalId(externalId, systemId); + + return schoolDO; + } + + async getSchoolBySchoolNumber(schoolNumber: string): Promise { + const schoolDO: LegacySchoolDo | null = await this.schoolRepo.findBySchoolNumber(schoolNumber); + + return schoolDO; + } + + async save(school: LegacySchoolDo, validate = false): Promise { + if (validate) { + await this.schoolValidationService.validate(school); + } + + const ret: LegacySchoolDo = await this.schoolRepo.save(school); + + return ret; + } +} diff --git a/apps/server/src/modules/school/service/school-year.service.spec.ts b/apps/server/src/modules/legacy-school/service/school-year.service.spec.ts similarity index 100% rename from apps/server/src/modules/school/service/school-year.service.spec.ts rename to apps/server/src/modules/legacy-school/service/school-year.service.spec.ts diff --git a/apps/server/src/modules/school/service/school-year.service.ts b/apps/server/src/modules/legacy-school/service/school-year.service.ts similarity index 100% rename from apps/server/src/modules/school/service/school-year.service.ts rename to apps/server/src/modules/legacy-school/service/school-year.service.ts diff --git a/apps/server/src/modules/school/service/validation/index.ts b/apps/server/src/modules/legacy-school/service/validation/index.ts similarity index 100% rename from apps/server/src/modules/school/service/validation/index.ts rename to apps/server/src/modules/legacy-school/service/validation/index.ts diff --git a/apps/server/src/modules/school/service/validation/school-validation.service.spec.ts b/apps/server/src/modules/legacy-school/service/validation/school-validation.service.spec.ts similarity index 72% rename from apps/server/src/modules/school/service/validation/school-validation.service.spec.ts rename to apps/server/src/modules/legacy-school/service/validation/school-validation.service.spec.ts index 6a283e11374..aa01608fb9f 100644 --- a/apps/server/src/modules/school/service/validation/school-validation.service.spec.ts +++ b/apps/server/src/modules/legacy-school/service/validation/school-validation.service.spec.ts @@ -1,8 +1,8 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; -import { SchoolDO } from '@shared/domain'; -import { SchoolRepo } from '@shared/repo'; -import { schoolDOFactory } from '@shared/testing'; +import { LegacySchoolDo } from '@shared/domain'; +import { LegacySchoolRepo } from '@shared/repo'; +import { legacySchoolDoFactory } from '@shared/testing'; import { SchoolNumberDuplicateLoggableException } from '../../error'; import { SchoolValidationService } from './school-validation.service'; @@ -10,21 +10,21 @@ describe('SchoolValidationService', () => { let module: TestingModule; let service: SchoolValidationService; - let schoolRepo: DeepMocked; + let schoolRepo: DeepMocked; beforeAll(async () => { module = await Test.createTestingModule({ providers: [ SchoolValidationService, { - provide: SchoolRepo, - useValue: createMock(), + provide: LegacySchoolRepo, + useValue: createMock(), }, ], }).compile(); service = module.get(SchoolValidationService); - schoolRepo = module.get(SchoolRepo); + schoolRepo = module.get(LegacySchoolRepo); }); afterAll(async () => { @@ -35,7 +35,7 @@ describe('SchoolValidationService', () => { describe('isSchoolNumberUnique', () => { describe('when a school has no official school number', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.buildWithId({ officialSchoolNumber: undefined }); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ officialSchoolNumber: undefined }); return { school, @@ -51,7 +51,7 @@ describe('SchoolValidationService', () => { describe('when a new school is created and the school number is unique', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.buildWithId({ officialSchoolNumber: '1234' }); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ officialSchoolNumber: '1234' }); schoolRepo.findBySchoolNumber.mockResolvedValue(null); @@ -69,7 +69,7 @@ describe('SchoolValidationService', () => { describe('when an existing school is updated and the school number is unique', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.buildWithId({ officialSchoolNumber: '1234' }); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ officialSchoolNumber: '1234' }); schoolRepo.findBySchoolNumber.mockResolvedValue(school); @@ -87,8 +87,8 @@ describe('SchoolValidationService', () => { describe('when the school number already exists on another school', () => { const setup = () => { - const newSchool: SchoolDO = schoolDOFactory.buildWithId({ officialSchoolNumber: '1234' }); - const existingSchool: SchoolDO = schoolDOFactory.buildWithId({ officialSchoolNumber: '1234' }); + const newSchool: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ officialSchoolNumber: '1234' }); + const existingSchool: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ officialSchoolNumber: '1234' }); schoolRepo.findBySchoolNumber.mockResolvedValue(existingSchool); diff --git a/apps/server/src/modules/school/service/validation/school-validation.service.ts b/apps/server/src/modules/legacy-school/service/validation/school-validation.service.ts similarity index 51% rename from apps/server/src/modules/school/service/validation/school-validation.service.ts rename to apps/server/src/modules/legacy-school/service/validation/school-validation.service.ts index a1dc1a7396d..044e0473ef3 100644 --- a/apps/server/src/modules/school/service/validation/school-validation.service.ts +++ b/apps/server/src/modules/legacy-school/service/validation/school-validation.service.ts @@ -1,24 +1,24 @@ import { Injectable } from '@nestjs/common'; -import { SchoolDO } from '@shared/domain'; -import { SchoolRepo } from '@shared/repo'; +import { LegacySchoolDo } from '@shared/domain'; +import { LegacySchoolRepo } from '@shared/repo'; import { SchoolNumberDuplicateLoggableException } from '../../error'; @Injectable() export class SchoolValidationService { - constructor(private readonly schoolRepo: SchoolRepo) {} + constructor(private readonly schoolRepo: LegacySchoolRepo) {} - public async validate(school: SchoolDO): Promise { + public async validate(school: LegacySchoolDo): Promise { if (!(await this.isSchoolNumberUnique(school))) { throw new SchoolNumberDuplicateLoggableException(school.officialSchoolNumber as string); } } - private async isSchoolNumberUnique(school: SchoolDO): Promise { + private async isSchoolNumberUnique(school: LegacySchoolDo): Promise { if (!school.officialSchoolNumber) { return true; } - const foundSchool: SchoolDO | null = await this.schoolRepo.findBySchoolNumber(school.officialSchoolNumber); + const foundSchool: LegacySchoolDo | null = await this.schoolRepo.findBySchoolNumber(school.officialSchoolNumber); return foundSchool === null || foundSchool.id === school.id; } diff --git a/apps/server/src/modules/school/types/federal-state-names.enum.ts b/apps/server/src/modules/legacy-school/types/federal-state-names.enum.ts similarity index 100% rename from apps/server/src/modules/school/types/federal-state-names.enum.ts rename to apps/server/src/modules/legacy-school/types/federal-state-names.enum.ts diff --git a/apps/server/src/modules/school/types/index.ts b/apps/server/src/modules/legacy-school/types/index.ts similarity index 100% rename from apps/server/src/modules/school/types/index.ts rename to apps/server/src/modules/legacy-school/types/index.ts diff --git a/apps/server/src/modules/school/uc/dto/oauth-migration.dto.ts b/apps/server/src/modules/legacy-school/uc/dto/oauth-migration.dto.ts similarity index 100% rename from apps/server/src/modules/school/uc/dto/oauth-migration.dto.ts rename to apps/server/src/modules/legacy-school/uc/dto/oauth-migration.dto.ts diff --git a/apps/server/src/modules/legacy-school/uc/index.ts b/apps/server/src/modules/legacy-school/uc/index.ts new file mode 100644 index 00000000000..97a341c0458 --- /dev/null +++ b/apps/server/src/modules/legacy-school/uc/index.ts @@ -0,0 +1 @@ +export * from './legacy-school.uc'; diff --git a/apps/server/src/modules/school/uc/school.uc.spec.ts b/apps/server/src/modules/legacy-school/uc/legacy-school.uc.spec.ts similarity index 89% rename from apps/server/src/modules/school/uc/school.uc.spec.ts rename to apps/server/src/modules/legacy-school/uc/legacy-school.uc.spec.ts index e293af1d869..17dc2de5fd0 100644 --- a/apps/server/src/modules/school/uc/school.uc.spec.ts +++ b/apps/server/src/modules/legacy-school/uc/legacy-school.uc.spec.ts @@ -1,12 +1,11 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { UnprocessableEntityException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { UserLoginMigrationDO } from '@shared/domain'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { schoolDOFactory, userLoginMigrationDOFactory } from '@shared/testing/factory'; +import { LegacySchoolDo, UserLoginMigrationDO } from '@shared/domain'; +import { legacySchoolDoFactory, userLoginMigrationDOFactory } from '@shared/testing/factory'; import { AuthorizationService } from '@src/modules/authorization'; -import { SchoolService } from '@src/modules/school/service/school.service'; -import { SchoolUc } from '@src/modules/school/uc/school.uc'; +import { LegacySchoolService } from '@src/modules/legacy-school/service'; +import { LegacySchoolUc } from '@src/modules/legacy-school/uc'; import { SchoolMigrationService, UserLoginMigrationRevertService, @@ -14,11 +13,11 @@ import { } from '@src/modules/user-login-migration'; import { OauthMigrationDto } from './dto/oauth-migration.dto'; -describe('SchoolUc', () => { +describe('LegacySchoolUc', () => { let module: TestingModule; - let schoolUc: SchoolUc; + let schoolUc: LegacySchoolUc; - let schoolService: DeepMocked; + let schoolService: DeepMocked; let authService: DeepMocked; let schoolMigrationService: DeepMocked; let userLoginMigrationService: DeepMocked; @@ -27,10 +26,10 @@ describe('SchoolUc', () => { beforeAll(async () => { module = await Test.createTestingModule({ providers: [ - SchoolUc, + LegacySchoolUc, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: AuthorizationService, @@ -51,9 +50,9 @@ describe('SchoolUc', () => { ], }).compile(); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); authService = module.get(AuthorizationService); - schoolUc = module.get(SchoolUc); + schoolUc = module.get(LegacySchoolUc); schoolMigrationService = module.get(SchoolMigrationService); userLoginMigrationService = module.get(UserLoginMigrationService); userLoginMigrationRevertService = module.get(UserLoginMigrationRevertService); @@ -70,7 +69,7 @@ describe('SchoolUc', () => { describe('setMigration is called', () => { describe('when first starting the migration', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); const userLoginMigration: UserLoginMigrationDO = new UserLoginMigrationDO({ schoolId: 'schoolId', targetSystemId: 'targetSystemId', @@ -98,7 +97,7 @@ describe('SchoolUc', () => { describe('when closing a migration', () => { describe('when there were migrated users', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); const userLoginMigration: UserLoginMigrationDO = userLoginMigrationDOFactory.build({ closedAt: undefined, }); @@ -129,7 +128,7 @@ describe('SchoolUc', () => { describe('when there were no users migrated', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); const userLoginMigration: UserLoginMigrationDO = userLoginMigrationDOFactory.build({ closedAt: undefined, }); @@ -163,7 +162,7 @@ describe('SchoolUc', () => { describe('when restarting a migration', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); const userLoginMigration: UserLoginMigrationDO = new UserLoginMigrationDO({ schoolId: 'schoolId', targetSystemId: 'targetSystemId', @@ -194,7 +193,7 @@ describe('SchoolUc', () => { describe('when trying to start a finished migration after the grace period', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); const userLoginMigration: UserLoginMigrationDO = new UserLoginMigrationDO({ schoolId: 'schoolId', targetSystemId: 'targetSystemId', @@ -230,7 +229,7 @@ describe('SchoolUc', () => { describe('getMigration is called', () => { describe('when the school has a migration', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); const userLoginMigration: UserLoginMigrationDO = new UserLoginMigrationDO({ schoolId: 'schoolId', targetSystemId: 'targetSystemId', @@ -262,7 +261,7 @@ describe('SchoolUc', () => { describe('when the school has no migration', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); userLoginMigrationService.findMigrationBySchool.mockResolvedValue(null); schoolService.getSchoolById.mockResolvedValue(school); diff --git a/apps/server/src/modules/school/uc/school.uc.ts b/apps/server/src/modules/legacy-school/uc/legacy-school.uc.ts similarity index 88% rename from apps/server/src/modules/school/uc/school.uc.ts rename to apps/server/src/modules/legacy-school/uc/legacy-school.uc.ts index 0fc424938a2..2ccc9dc5698 100644 --- a/apps/server/src/modules/school/uc/school.uc.ts +++ b/apps/server/src/modules/legacy-school/uc/legacy-school.uc.ts @@ -1,18 +1,21 @@ import { Injectable } from '@nestjs/common'; -import { Permission, SchoolDO, UserLoginMigrationDO } from '@shared/domain'; +import { Permission, LegacySchoolDo, UserLoginMigrationDO } from '@shared/domain'; import { Action, AuthorizableReferenceType, AuthorizationService } from '@src/modules/authorization'; import { SchoolMigrationService, UserLoginMigrationRevertService, UserLoginMigrationService, } from '@src/modules/user-login-migration'; -import { SchoolService } from '../service'; +import { LegacySchoolService } from '../service'; import { OauthMigrationDto } from './dto/oauth-migration.dto'; +/** + * @deprecated because it uses the deprecated LegacySchoolDo. + */ @Injectable() -export class SchoolUc { +export class LegacySchoolUc { constructor( - private readonly schoolService: SchoolService, + private readonly schoolService: LegacySchoolService, private readonly authService: AuthorizationService, private readonly schoolMigrationService: SchoolMigrationService, private readonly userLoginMigrationService: UserLoginMigrationService, @@ -58,7 +61,7 @@ export class SchoolUc { await this.schoolMigrationService.unmarkOutdatedUsers(schoolId); } - const school: SchoolDO = await this.schoolService.getSchoolById(schoolId); + const school: LegacySchoolDo = await this.schoolService.getSchoolById(schoolId); const migrationDto: OauthMigrationDto = new OauthMigrationDto({ oauthMigrationPossible: !updatedUserLoginMigration.closedAt ? updatedUserLoginMigration.startedAt : undefined, @@ -81,7 +84,7 @@ export class SchoolUc { schoolId ); - const school: SchoolDO = await this.schoolService.getSchoolById(schoolId); + const school: LegacySchoolDo = await this.schoolService.getSchoolById(schoolId); const migrationDto: OauthMigrationDto = new OauthMigrationDto({ oauthMigrationPossible: diff --git a/apps/server/src/modules/oauth/oauth-api.module.ts b/apps/server/src/modules/oauth/oauth-api.module.ts index d97af726250..4bde06ce6a0 100644 --- a/apps/server/src/modules/oauth/oauth-api.module.ts +++ b/apps/server/src/modules/oauth/oauth-api.module.ts @@ -3,7 +3,7 @@ import { LoggerModule } from '@src/core/logger'; import { AuthenticationModule } from '@src/modules/authentication/authentication.module'; import { AuthorizationModule } from '@src/modules/authorization'; import { ProvisioningModule } from '@src/modules/provisioning'; -import { SchoolModule } from '@src/modules/school'; +import { LegacySchoolModule } from '@src/modules/legacy-school'; import { SystemModule } from '@src/modules/system'; import { UserModule } from '@src/modules/user'; import { UserLoginMigrationModule } from '@src/modules/user-login-migration'; @@ -17,7 +17,7 @@ import { HydraOauthUc, OauthUc } from './uc'; AuthenticationModule, AuthorizationModule, ProvisioningModule, - SchoolModule, + LegacySchoolModule, UserLoginMigrationModule, SystemModule, UserModule, diff --git a/apps/server/src/modules/oauth/oauth.module.ts b/apps/server/src/modules/oauth/oauth.module.ts index 78eaec06048..b8519e3eaa2 100644 --- a/apps/server/src/modules/oauth/oauth.module.ts +++ b/apps/server/src/modules/oauth/oauth.module.ts @@ -6,7 +6,7 @@ import { LtiToolRepo } from '@shared/repo'; import { LoggerModule } from '@src/core/logger'; import { AuthorizationModule } from '@src/modules/authorization'; import { ProvisioningModule } from '@src/modules/provisioning'; -import { SchoolModule } from '@src/modules/school'; +import { LegacySchoolModule } from '@src/modules/legacy-school'; import { SystemModule } from '@src/modules/system'; import { UserModule } from '@src/modules/user'; import { UserLoginMigrationModule } from '@src/modules/user-login-migration'; @@ -25,7 +25,7 @@ import { OAuthService } from './service/oauth.service'; SystemModule, UserLoginMigrationModule, CacheWrapperModule, - SchoolModule, + LegacySchoolModule, ], providers: [OAuthService, OauthAdapterService, HydraSsoService, LtiToolRepo], exports: [OAuthService, HydraSsoService], diff --git a/apps/server/src/modules/oauth/service/oauth.service.spec.ts b/apps/server/src/modules/oauth/service/oauth.service.spec.ts index c092987b153..ae54342887f 100644 --- a/apps/server/src/modules/oauth/service/oauth.service.spec.ts +++ b/apps/server/src/modules/oauth/service/oauth.service.spec.ts @@ -1,18 +1,15 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Configuration } from '@hpi-schul-cloud/commons'; import { Test, TestingModule } from '@nestjs/testing'; -import { OauthConfig, SchoolFeatures, System } from '@shared/domain'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; +import { LegacySchoolDo, OauthConfig, SchoolFeatures, System } from '@shared/domain'; import { UserDO } from '@shared/domain/domainobject/user.do'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; import { DefaultEncryptionService, IEncryptionService, SymetricKeyEncryptionService } from '@shared/infra/encryption'; -import { setupEntities, userDoFactory } from '@shared/testing'; -import { schoolDOFactory } from '@shared/testing/factory/domainobject/school.factory'; -import { systemFactory } from '@shared/testing/factory/system.factory'; +import { legacySchoolDoFactory, setupEntities, systemFactory, userDoFactory } from '@shared/testing'; import { LegacyLogger } from '@src/core/logger'; import { ProvisioningDto, ProvisioningService } from '@src/modules/provisioning'; import { ExternalSchoolDto, ExternalUserDto, OauthDataDto, ProvisioningSystemDto } from '@src/modules/provisioning/dto'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { OauthConfigDto } from '@src/modules/system/service'; import { SystemDto } from '@src/modules/system/service/dto/system.dto'; import { SystemService } from '@src/modules/system/service/system.service'; @@ -51,7 +48,7 @@ describe('OAuthService', () => { let userMigrationService: DeepMocked; let oauthAdapterService: DeepMocked; let migrationCheckService: DeepMocked; - let schoolService: DeepMocked; + let schoolService: DeepMocked; let testSystem: System; let testOauthConfig: OauthConfig; @@ -69,8 +66,8 @@ describe('OAuthService', () => { useValue: createMock(), }, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: DefaultEncryptionService, @@ -111,7 +108,7 @@ describe('OAuthService', () => { userMigrationService = module.get(UserMigrationService); oauthAdapterService = module.get(OauthAdapterService); migrationCheckService = module.get(MigrationCheckService); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); }); afterAll(async () => { @@ -427,7 +424,9 @@ describe('OAuthService', () => { officialSchoolNumber: 'officialSchoolNumber', }), }); - const school: SchoolDO = schoolDOFactory.buildWithId({ features: [SchoolFeatures.OAUTH_PROVISIONING_ENABLED] }); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ + features: [SchoolFeatures.OAUTH_PROVISIONING_ENABLED], + }); provisioningService.getData.mockResolvedValue(oauthData); schoolService.getSchoolBySchoolNumber.mockResolvedValue(school); @@ -467,7 +466,7 @@ describe('OAuthService', () => { officialSchoolNumber: 'officialSchoolNumber', }), }); - const school: SchoolDO = schoolDOFactory.buildWithId({ features: [] }); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ features: [] }); provisioningService.getData.mockResolvedValue(oauthData); schoolService.getSchoolBySchoolNumber.mockResolvedValue(school); @@ -513,7 +512,7 @@ describe('OAuthService', () => { officialSchoolNumber: 'officialSchoolNumber', }), }); - const school: SchoolDO = schoolDOFactory.buildWithId({ features: [] }); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ features: [] }); provisioningService.getData.mockResolvedValue(oauthData); schoolService.getSchoolBySchoolNumber.mockResolvedValue(school); diff --git a/apps/server/src/modules/oauth/service/oauth.service.ts b/apps/server/src/modules/oauth/service/oauth.service.ts index bb989486986..afef7f113e5 100644 --- a/apps/server/src/modules/oauth/service/oauth.service.ts +++ b/apps/server/src/modules/oauth/service/oauth.service.ts @@ -1,14 +1,12 @@ import { Configuration } from '@hpi-schul-cloud/commons'; import { Inject } from '@nestjs/common'; import { Injectable } from '@nestjs/common/decorators/core/injectable.decorator'; -import { EntityId, OauthConfig, SchoolFeatures } from '@shared/domain'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { UserDO } from '@shared/domain/domainobject/user.do'; +import { EntityId, LegacySchoolDo, OauthConfig, SchoolFeatures, UserDO } from '@shared/domain'; import { DefaultEncryptionService, IEncryptionService } from '@shared/infra/encryption'; import { LegacyLogger } from '@src/core/logger'; import { ProvisioningService } from '@src/modules/provisioning'; import { OauthDataDto } from '@src/modules/provisioning/dto'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { SystemService } from '@src/modules/system'; import { SystemDto } from '@src/modules/system/service'; import { UserService } from '@src/modules/user'; @@ -31,7 +29,7 @@ export class OAuthService { private readonly systemService: SystemService, private readonly userMigrationService: UserMigrationService, private readonly migrationCheckService: MigrationCheckService, - private readonly schoolService: SchoolService + private readonly schoolService: LegacySchoolService ) { this.logger.setContext(OAuthService.name); } @@ -132,7 +130,7 @@ export class OAuthService { } async isOauthProvisioningEnabledForSchool(officialSchoolNumber: string): Promise { - const school: SchoolDO | null = await this.schoolService.getSchoolBySchoolNumber(officialSchoolNumber); + const school: LegacySchoolDo | null = await this.schoolService.getSchoolBySchoolNumber(officialSchoolNumber); if (!school) { return true; diff --git a/apps/server/src/modules/oauth/uc/oauth.uc.spec.ts b/apps/server/src/modules/oauth/uc/oauth.uc.spec.ts index ca5fa3a5e1e..dba6cca003c 100644 --- a/apps/server/src/modules/oauth/uc/oauth.uc.spec.ts +++ b/apps/server/src/modules/oauth/uc/oauth.uc.spec.ts @@ -1,11 +1,10 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { UnauthorizedException, UnprocessableEntityException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { UserDO } from '@shared/domain/domainobject/user.do'; +import { LegacySchoolDo, UserDO } from '@shared/domain'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; import { ISession } from '@shared/domain/types/session'; -import { schoolDOFactory, setupEntities } from '@shared/testing'; +import { legacySchoolDoFactory, setupEntities } from '@shared/testing'; import { LegacyLogger } from '@src/core/logger'; import { ICurrentUser } from '@src/modules/authentication'; import { AuthenticationService } from '@src/modules/authentication/services/authentication.service'; @@ -13,7 +12,7 @@ import { OAuthSSOError } from '@src/modules/oauth/error/oauth-sso.error'; import { OauthUc } from '@src/modules/oauth/uc/oauth.uc'; import { ProvisioningService } from '@src/modules/provisioning'; import { ExternalUserDto, OauthDataDto, ProvisioningSystemDto } from '@src/modules/provisioning/dto'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { SystemService } from '@src/modules/system'; import { OauthConfigDto, SystemDto } from '@src/modules/system/service'; import { UserService } from '@src/modules/user'; @@ -77,8 +76,8 @@ describe('OAuthUc', () => { useValue: createMock(), }, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: UserMigrationService, @@ -659,7 +658,7 @@ describe('OAuthUc', () => { oauthService.requestToken.mockResolvedValue(tokenDto); provisioningService.getData.mockResolvedValue(oauthData); - const schoolToMigrate: SchoolDO | void = schoolDOFactory.build({ name: 'mockName' }); + const schoolToMigrate: LegacySchoolDo | void = legacySchoolDoFactory.build({ name: 'mockName' }); oauthService.authenticateUser.mockResolvedValue(tokenDto); schoolMigrationService.schoolToMigrate.mockResolvedValue(schoolToMigrate); userMigrationService.migrateUser.mockResolvedValue(userMigrationDto); diff --git a/apps/server/src/modules/oauth/uc/oauth.uc.ts b/apps/server/src/modules/oauth/uc/oauth.uc.ts index c153501e338..e4dd7e68264 100644 --- a/apps/server/src/modules/oauth/uc/oauth.uc.ts +++ b/apps/server/src/modules/oauth/uc/oauth.uc.ts @@ -1,7 +1,5 @@ import { Injectable, UnauthorizedException, UnprocessableEntityException } from '@nestjs/common'; -import { EntityId } from '@shared/domain'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { UserDO } from '@shared/domain/domainobject/user.do'; +import { EntityId, LegacySchoolDo, UserDO } from '@shared/domain'; import { ISession } from '@shared/domain/types/session'; import { LegacyLogger } from '@src/core/logger'; import { ICurrentUser } from '@src/modules/authentication'; @@ -120,7 +118,7 @@ export class OauthUc { const data: OauthDataDto = await this.provisioningService.getData(systemId, tokenDto.idToken, tokenDto.accessToken); if (data.externalSchool) { - const schoolToMigrate: SchoolDO | null = await this.schoolMigrationService.schoolToMigrate( + const schoolToMigrate: LegacySchoolDo | null = await this.schoolMigrationService.schoolToMigrate( currentUserId, data.externalSchool.externalId, data.externalSchool.officialSchoolNumber diff --git a/apps/server/src/modules/provisioning/provisioning.module.ts b/apps/server/src/modules/provisioning/provisioning.module.ts index cc38e3dacf9..854d1834387 100644 --- a/apps/server/src/modules/provisioning/provisioning.module.ts +++ b/apps/server/src/modules/provisioning/provisioning.module.ts @@ -3,7 +3,7 @@ import { Module } from '@nestjs/common'; import { LoggerModule } from '@src/core/logger'; import { AccountModule } from '@src/modules/account/account.module'; import { RoleModule } from '@src/modules/role'; -import { SchoolModule } from '@src/modules/school/school.module'; +import { LegacySchoolModule } from '@src/modules/legacy-school'; import { SystemModule } from '@src/modules/system/system.module'; import { UserModule } from '@src/modules/user'; import { GroupModule } from '@src/modules/group'; @@ -13,7 +13,16 @@ import { OidcProvisioningService } from './strategy/oidc/service/oidc-provisioni import { SanisResponseMapper } from './strategy/sanis/sanis-response.mapper'; @Module({ - imports: [AccountModule, SchoolModule, UserModule, RoleModule, SystemModule, HttpModule, LoggerModule, GroupModule], + imports: [ + AccountModule, + LegacySchoolModule, + UserModule, + RoleModule, + SystemModule, + HttpModule, + LoggerModule, + GroupModule, + ], providers: [ ProvisioningService, SanisResponseMapper, diff --git a/apps/server/src/modules/provisioning/strategy/iserv/iserv-do.mapper.ts b/apps/server/src/modules/provisioning/strategy/iserv/iserv-do.mapper.ts index 63803ac1577..ff2373e3765 100644 --- a/apps/server/src/modules/provisioning/strategy/iserv/iserv-do.mapper.ts +++ b/apps/server/src/modules/provisioning/strategy/iserv/iserv-do.mapper.ts @@ -1,10 +1,8 @@ -import { RoleName } from '@shared/domain'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { UserDO } from '@shared/domain/domainobject/user.do'; +import { LegacySchoolDo, RoleName, UserDO } from '@shared/domain'; import { ExternalSchoolDto, ExternalUserDto } from '../../dto'; export class IservMapper { - static mapToExternalSchoolDto(schoolDO: SchoolDO): ExternalSchoolDto { + static mapToExternalSchoolDto(schoolDO: LegacySchoolDo): ExternalSchoolDto { return new ExternalSchoolDto({ name: schoolDO.name, externalId: schoolDO.externalId || '', diff --git a/apps/server/src/modules/provisioning/strategy/iserv/iserv.strategy.spec.ts b/apps/server/src/modules/provisioning/strategy/iserv/iserv.strategy.spec.ts index e39e489dd56..0926ae7e3a7 100644 --- a/apps/server/src/modules/provisioning/strategy/iserv/iserv.strategy.spec.ts +++ b/apps/server/src/modules/provisioning/strategy/iserv/iserv.strategy.spec.ts @@ -1,14 +1,11 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { ObjectId } from '@mikro-orm/mongodb'; import { Test, TestingModule } from '@nestjs/testing'; -import { RoleName, User } from '@shared/domain'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { UserDO } from '@shared/domain/domainobject/user.do'; +import { LegacySchoolDo, RoleName, User, UserDO } from '@shared/domain'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; -import { schoolFactory, setupEntities, userDoFactory, userFactory } from '@shared/testing'; -import { schoolDOFactory } from '@shared/testing/factory/domainobject/school.factory'; +import { legacySchoolDoFactory, schoolFactory, setupEntities, userDoFactory, userFactory } from '@shared/testing'; import { OAuthSSOError } from '@src/modules/oauth/error/oauth-sso.error'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { UserService } from '@src/modules/user'; import jwt from 'jsonwebtoken'; import { RoleDto } from '../../../role/service/dto/role.dto'; @@ -28,7 +25,7 @@ describe('IservProvisioningStrategy', () => { let module: TestingModule; let strategy: IservProvisioningStrategy; - let schoolService: DeepMocked; + let schoolService: DeepMocked; let userService: DeepMocked; beforeAll(async () => { @@ -41,14 +38,14 @@ describe('IservProvisioningStrategy', () => { useValue: createMock(), }, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, ], }).compile(); strategy = module.get(IservProvisioningStrategy); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); userService = module.get(UserService); }); @@ -92,7 +89,7 @@ describe('IservProvisioningStrategy', () => { const user: UserDO = userDoFactory.withRoles([{ id: 'roleId', name: RoleName.STUDENT }]).buildWithId({ externalId: userUUID, }); - const school: SchoolDO = schoolDOFactory.buildWithId({ externalId: 'schoolExternalId' }); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ externalId: 'schoolExternalId' }); const roleDto: RoleDto = new RoleDto({ name: RoleName.STUDENT, }); diff --git a/apps/server/src/modules/provisioning/strategy/iserv/iserv.strategy.ts b/apps/server/src/modules/provisioning/strategy/iserv/iserv.strategy.ts index 647d03fb92a..71ea2972b54 100644 --- a/apps/server/src/modules/provisioning/strategy/iserv/iserv.strategy.ts +++ b/apps/server/src/modules/provisioning/strategy/iserv/iserv.strategy.ts @@ -1,11 +1,8 @@ import { Injectable } from '@nestjs/common'; -import { RoleName, User } from '@shared/domain'; -import { RoleReference } from '@shared/domain/domainobject'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { UserDO } from '@shared/domain/domainobject/user.do'; +import { LegacySchoolDo, RoleName, RoleReference, User, UserDO } from '@shared/domain'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; import { OAuthSSOError } from '@src/modules/oauth/error/oauth-sso.error'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { UserService } from '@src/modules/user'; import jwt, { JwtPayload } from 'jsonwebtoken'; import { @@ -20,7 +17,7 @@ import { IservMapper } from './iserv-do.mapper'; @Injectable() export class IservProvisioningStrategy extends ProvisioningStrategy { - constructor(private readonly schoolService: SchoolService, private readonly userService: UserService) { + constructor(private readonly schoolService: LegacySchoolService, private readonly userService: UserService) { super(); } @@ -47,7 +44,7 @@ export class IservProvisioningStrategy extends ProvisioningStrategy { ); } - const ldapSchool: SchoolDO = await this.schoolService.getSchoolById(ldapUser.schoolId); + const ldapSchool: LegacySchoolDo = await this.schoolService.getSchoolById(ldapUser.schoolId); const roleNames: RoleName[] = ldapUser.roles.map((roleRef: RoleReference): RoleName => roleRef.name); const externalUser: ExternalUserDto = IservMapper.mapToExternalUserDto(ldapUser, roleNames); diff --git a/apps/server/src/modules/provisioning/strategy/oidc/oidc.strategy.spec.ts b/apps/server/src/modules/provisioning/strategy/oidc/oidc.strategy.spec.ts index 3c1231c3e72..80bdfdf4c88 100644 --- a/apps/server/src/modules/provisioning/strategy/oidc/oidc.strategy.spec.ts +++ b/apps/server/src/modules/provisioning/strategy/oidc/oidc.strategy.spec.ts @@ -1,11 +1,9 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { NotImplementedException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { RoleName } from '@shared/domain'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { UserDO } from '@shared/domain/domainobject/user.do'; +import { LegacySchoolDo, RoleName, UserDO } from '@shared/domain'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; -import { schoolDOFactory, userDoFactory } from '@shared/testing'; +import { legacySchoolDoFactory, userDoFactory } from '@shared/testing'; import { Configuration } from '@hpi-schul-cloud/commons/lib'; import { externalGroupDtoFactory } from '@shared/testing/factory/external-group-dto.factory'; import { @@ -85,7 +83,7 @@ describe('OidcStrategy', () => { schoolId: 'schoolId', externalId: externalUserId, }); - const school: SchoolDO = schoolDOFactory.build({ + const school: LegacySchoolDo = legacySchoolDoFactory.build({ id: schoolId, name: 'schoolName', externalId: externalSchoolId, @@ -137,7 +135,7 @@ describe('OidcStrategy', () => { schoolId: 'schoolId', externalId: externalUserId, }); - const school: SchoolDO = schoolDOFactory.build({ + const school: LegacySchoolDo = legacySchoolDoFactory.build({ id: schoolId, name: 'schoolName', externalId: externalSchoolId, diff --git a/apps/server/src/modules/provisioning/strategy/oidc/oidc.strategy.ts b/apps/server/src/modules/provisioning/strategy/oidc/oidc.strategy.ts index e52bdb497ee..f51fc49abed 100644 --- a/apps/server/src/modules/provisioning/strategy/oidc/oidc.strategy.ts +++ b/apps/server/src/modules/provisioning/strategy/oidc/oidc.strategy.ts @@ -1,7 +1,6 @@ -import { Injectable } from '@nestjs/common'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { UserDO } from '@shared/domain/domainobject/user.do'; import { Configuration } from '@hpi-schul-cloud/commons/lib'; +import { Injectable } from '@nestjs/common'; +import { LegacySchoolDo, UserDO } from '@shared/domain'; import { OauthDataDto, ProvisioningDto } from '../../dto'; import { ProvisioningStrategy } from '../base.strategy'; import { OidcProvisioningService } from './service/oidc-provisioning.service'; @@ -13,7 +12,7 @@ export abstract class OidcProvisioningStrategy extends ProvisioningStrategy { } override async apply(data: OauthDataDto): Promise { - let school: SchoolDO | undefined; + let school: LegacySchoolDo | undefined; if (data.externalSchool) { school = await this.oidcProvisioningService.provisionExternalSchool(data.externalSchool, data.system.systemId); } diff --git a/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.spec.ts b/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.spec.ts index 83a7baff0b8..1084f21bbf4 100644 --- a/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.spec.ts +++ b/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.spec.ts @@ -1,15 +1,14 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { UnprocessableEntityException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { RoleName, SchoolFeatures } from '@shared/domain'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; +import { LegacySchoolDo, RoleName, SchoolFeatures } from '@shared/domain'; import { UserDO } from '@shared/domain/domainobject/user.do'; import { externalGroupDtoFactory, federalStateFactory, groupFactory, roleDtoFactory, - schoolDOFactory, + legacySchoolDoFactory, schoolYearFactory, userDoFactory, } from '@shared/testing'; @@ -19,7 +18,7 @@ import { AccountSaveDto } from '@src/modules/account/services/dto'; import { Group, GroupService } from '@src/modules/group'; import { RoleService } from '@src/modules/role'; import { RoleDto } from '@src/modules/role/service/dto/role.dto'; -import { FederalStateService, SchoolService, SchoolYearService } from '@src/modules/school'; +import { FederalStateService, LegacySchoolService, SchoolYearService } from '@src/modules/legacy-school'; import { UserService } from '@src/modules/user'; import CryptoJS from 'crypto-js'; import { ExternalGroupDto, ExternalSchoolDto, ExternalUserDto } from '../../../dto'; @@ -33,7 +32,7 @@ describe('OidcProvisioningService', () => { let service: OidcProvisioningService; let userService: DeepMocked; - let schoolService: DeepMocked; + let schoolService: DeepMocked; let roleService: DeepMocked; let accountService: DeepMocked; let schoolYearService: DeepMocked; @@ -50,8 +49,8 @@ describe('OidcProvisioningService', () => { useValue: createMock(), }, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: RoleService, @@ -82,7 +81,7 @@ describe('OidcProvisioningService', () => { service = module.get(OidcProvisioningService); userService = module.get(UserService); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); roleService = module.get(RoleService); accountService = module.get(AccountService); schoolYearService = module.get(SchoolYearService); @@ -107,7 +106,7 @@ describe('OidcProvisioningService', () => { name: 'name', officialSchoolNumber: 'officialSchoolNumber', }); - const savedSchoolDO = schoolDOFactory.build({ + const savedSchoolDO = legacySchoolDoFactory.build({ id: 'schoolId', externalId: 'externalId', name: 'name', @@ -115,7 +114,7 @@ describe('OidcProvisioningService', () => { systems: [systemId], features: [SchoolFeatures.OAUTH_PROVISIONING_ENABLED], }); - const existingSchoolDO = schoolDOFactory.build({ + const existingSchoolDO = legacySchoolDoFactory.build({ id: 'schoolId', externalId: 'externalId', name: 'existingName', @@ -141,7 +140,7 @@ describe('OidcProvisioningService', () => { it('should save the new school', async () => { const { systemId, externalSchoolDto, savedSchoolDO } = setup(); - const result: SchoolDO = await service.provisionExternalSchool(externalSchoolDto, systemId); + const result: LegacySchoolDo = await service.provisionExternalSchool(externalSchoolDto, systemId); expect(result).toEqual(savedSchoolDO); }); @@ -153,7 +152,7 @@ describe('OidcProvisioningService', () => { schoolService.getSchoolByExternalId.mockResolvedValue(existingSchoolDO); - const result: SchoolDO = await service.provisionExternalSchool(externalSchoolDto, systemId); + const result: LegacySchoolDo = await service.provisionExternalSchool(externalSchoolDto, systemId); expect(result).toEqual(savedSchoolDO); }); @@ -440,7 +439,7 @@ describe('OidcProvisioningService', () => { const setup = () => { const externalGroupDto: ExternalGroupDto = externalGroupDtoFactory.build(); const systemId = 'systemId'; - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); userService.findByExternalId.mockResolvedValue(null); schoolService.getSchoolByExternalId.mockResolvedValue(school); @@ -465,7 +464,7 @@ describe('OidcProvisioningService', () => { const group: Group = groupFactory.build(); groupService.findByExternalSource.mockResolvedValue(group); - const school: SchoolDO = schoolDOFactory.build({ id: 'schoolId' }); + const school: LegacySchoolDo = legacySchoolDoFactory.build({ id: 'schoolId' }); schoolService.getSchoolByExternalId.mockResolvedValue(school); const student: UserDO = userDoFactory diff --git a/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.ts b/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.ts index cf07810498a..d32fa5a9b06 100644 --- a/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.ts +++ b/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.ts @@ -1,16 +1,14 @@ import { Injectable, UnprocessableEntityException } from '@nestjs/common'; import { EntityId, ExternalSource, FederalState, SchoolFeatures, SchoolYear } from '@shared/domain'; -import { RoleReference } from '@shared/domain/domainobject'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { UserDO } from '@shared/domain/domainobject/user.do'; +import { LegacySchoolDo, RoleReference, UserDO } from '@shared/domain/domainobject'; import { Logger } from '@src/core/logger'; import { AccountService } from '@src/modules/account/services/account.service'; import { AccountSaveDto } from '@src/modules/account/services/dto'; import { Group, GroupService, GroupUser } from '@src/modules/group'; +import { FederalStateService, LegacySchoolService, SchoolYearService } from '@src/modules/legacy-school'; +import { FederalStateNames } from '@src/modules/legacy-school/types'; import { RoleService } from '@src/modules/role'; import { RoleDto } from '@src/modules/role/service/dto/role.dto'; -import { FederalStateService, SchoolService, SchoolYearService } from '@src/modules/school'; -import { FederalStateNames } from '@src/modules/school/types'; import { UserService } from '@src/modules/user'; import { ObjectId } from 'bson'; import CryptoJS from 'crypto-js'; @@ -21,7 +19,7 @@ import { SchoolForGroupNotFoundLoggable, UserForGroupNotFoundLoggable } from '.. export class OidcProvisioningService { constructor( private readonly userService: UserService, - private readonly schoolService: SchoolService, + private readonly schoolService: LegacySchoolService, private readonly groupService: GroupService, private readonly roleService: RoleService, private readonly accountService: AccountService, @@ -30,12 +28,12 @@ export class OidcProvisioningService { private readonly logger: Logger ) {} - async provisionExternalSchool(externalSchool: ExternalSchoolDto, systemId: EntityId): Promise { - const existingSchool: SchoolDO | null = await this.schoolService.getSchoolByExternalId( + async provisionExternalSchool(externalSchool: ExternalSchoolDto, systemId: EntityId): Promise { + const existingSchool: LegacySchoolDo | null = await this.schoolService.getSchoolByExternalId( externalSchool.externalId, systemId ); - let school: SchoolDO; + let school: LegacySchoolDo; if (existingSchool) { school = existingSchool; school.name = externalSchool.name; @@ -51,7 +49,7 @@ export class OidcProvisioningService { FederalStateNames.NIEDERSACHEN ); - school = new SchoolDO({ + school = new LegacySchoolDo({ externalId: externalSchool.externalId, name: externalSchool.name, officialSchoolNumber: externalSchool.officialSchoolNumber, @@ -63,7 +61,7 @@ export class OidcProvisioningService { }); } - const savedSchool: SchoolDO = await this.schoolService.save(school, true); + const savedSchool: LegacySchoolDo = await this.schoolService.save(school, true); return savedSchool; } @@ -131,7 +129,7 @@ export class OidcProvisioningService { let organizationId: string | undefined; if (externalGroup.externalOrganizationId) { - const existingSchool: SchoolDO | null = await this.schoolService.getSchoolByExternalId( + const existingSchool: LegacySchoolDo | null = await this.schoolService.getSchoolByExternalId( externalGroup.externalOrganizationId, systemId ); diff --git a/apps/server/src/modules/school/index.ts b/apps/server/src/modules/school/index.ts deleted file mode 100644 index 49cfd4c9e39..00000000000 --- a/apps/server/src/modules/school/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './school.module'; -export * from './service'; diff --git a/apps/server/src/modules/school/school-api.module.ts b/apps/server/src/modules/school/school-api.module.ts deleted file mode 100644 index 48917e254e2..00000000000 --- a/apps/server/src/modules/school/school-api.module.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Module } from '@nestjs/common'; -import { AuthorizationModule } from '@src/modules/authorization'; -import { LoggerModule } from '@src/core/logger'; -import { UserLoginMigrationModule } from '@src/modules/user-login-migration'; -import { SchoolUc } from './uc/school.uc'; -import { SchoolModule } from './school.module'; -import { SchoolController } from './controller/school.controller'; -import { MigrationMapper } from './mapper/migration.mapper'; - -@Module({ - imports: [SchoolModule, AuthorizationModule, LoggerModule, UserLoginMigrationModule], - controllers: [SchoolController], - providers: [SchoolUc, MigrationMapper], -}) -export class SchoolApiModule {} diff --git a/apps/server/src/modules/school/school.module.ts b/apps/server/src/modules/school/school.module.ts deleted file mode 100644 index f09ddbff769..00000000000 --- a/apps/server/src/modules/school/school.module.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Module } from '@nestjs/common'; -import { FederalStateRepo, SchoolRepo } from '@shared/repo'; -import { LoggerModule } from '@src/core/logger'; -import { SchoolYearRepo } from './repo'; -import { FederalStateService, SchoolService, SchoolValidationService, SchoolYearService } from './service'; - -@Module({ - imports: [LoggerModule], - providers: [ - SchoolRepo, - SchoolService, - SchoolYearService, - SchoolYearRepo, - FederalStateService, - FederalStateRepo, - SchoolValidationService, - ], - exports: [SchoolService, SchoolYearService, FederalStateService], -}) -export class SchoolModule {} diff --git a/apps/server/src/modules/school/service/school.service.ts b/apps/server/src/modules/school/service/school.service.ts deleted file mode 100644 index becf7d58eeb..00000000000 --- a/apps/server/src/modules/school/service/school.service.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { EntityId, SchoolFeatures } from '@shared/domain'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { SchoolRepo } from '@shared/repo'; -import { SchoolValidationService } from './validation'; - -@Injectable() -export class SchoolService { - constructor( - private readonly schoolRepo: SchoolRepo, - private readonly schoolValidationService: SchoolValidationService - ) {} - - async hasFeature(schoolId: EntityId, feature: SchoolFeatures): Promise { - const entity: SchoolDO = await this.schoolRepo.findById(schoolId); - return entity.features ? entity.features.includes(feature) : false; - } - - async removeFeature(schoolId: EntityId, feature: SchoolFeatures): Promise { - const school: SchoolDO = await this.schoolRepo.findById(schoolId); - if (school.features && school.features.includes(feature)) { - school.features = school.features.filter((f: SchoolFeatures) => f !== feature); - await this.schoolRepo.save(school); - } - } - - async getSchoolById(id: string): Promise { - const schoolDO: SchoolDO = await this.schoolRepo.findById(id); - - return schoolDO; - } - - async getSchoolByExternalId(externalId: string, systemId: string): Promise { - const schoolDO: SchoolDO | null = await this.schoolRepo.findByExternalId(externalId, systemId); - - return schoolDO; - } - - async getSchoolBySchoolNumber(schoolNumber: string): Promise { - const schoolDO: SchoolDO | null = await this.schoolRepo.findBySchoolNumber(schoolNumber); - - return schoolDO; - } - - async save(school: SchoolDO, validate = false): Promise { - if (validate) { - await this.schoolValidationService.validate(school); - } - - const ret: SchoolDO = await this.schoolRepo.save(school); - - return ret; - } -} diff --git a/apps/server/src/modules/server/server.module.ts b/apps/server/src/modules/server/server.module.ts index ad338bae642..22997d30f50 100644 --- a/apps/server/src/modules/server/server.module.ts +++ b/apps/server/src/modules/server/server.module.ts @@ -23,7 +23,7 @@ import { NewsModule } from '@src/modules/news'; import { OauthProviderApiModule } from '@src/modules/oauth-provider'; import { OauthApiModule } from '@src/modules/oauth/oauth-api.module'; import { RocketChatModule } from '@src/modules/rocketchat'; -import { SchoolApiModule } from '@src/modules/school/school-api.module'; +import { LegacySchoolApiModule } from '@src/modules/legacy-school/legacy-school-api.module'; import { SharingApiModule } from '@src/modules/sharing/sharing.module'; import { SystemApiModule } from '@src/modules/system/system-api.module'; import { TaskApiModule } from '@src/modules/task/task-api.module'; @@ -65,7 +65,7 @@ const serverModules = [ adminUser: Configuration.get('ROCKET_CHAT_ADMIN_USER') as string, adminPassword: Configuration.get('ROCKET_CHAT_ADMIN_PASSWORD') as string, }), - SchoolApiModule, + LegacySchoolApiModule, VideoConferenceApiModule, OauthProviderApiModule, SharingApiModule, diff --git a/apps/server/src/modules/tool/common/common-tool.module.ts b/apps/server/src/modules/tool/common/common-tool.module.ts index 419385be67d..cc7f5f86f00 100644 --- a/apps/server/src/modules/tool/common/common-tool.module.ts +++ b/apps/server/src/modules/tool/common/common-tool.module.ts @@ -2,12 +2,12 @@ import { forwardRef, Module } from '@nestjs/common'; import { ContextExternalToolRepo, SchoolExternalToolRepo } from '@shared/repo'; import { LoggerModule } from '@src/core/logger'; import { AuthorizationModule } from '@src/modules/authorization'; -import { SchoolModule } from '@src/modules/school'; +import { LegacySchoolModule } from '@src/modules/legacy-school'; import { CommonToolService, CommonToolValidationService } from './service'; import { ToolPermissionHelper } from './uc/tool-permission-helper'; @Module({ - imports: [LoggerModule, forwardRef(() => AuthorizationModule), SchoolModule], + imports: [LoggerModule, forwardRef(() => AuthorizationModule), LegacySchoolModule], // TODO: make deletion of entities cascading, adjust ExternalToolService.deleteExternalTool and remove the repos from here providers: [ CommonToolService, diff --git a/apps/server/src/modules/tool/common/uc/tool-permission-helper.ts b/apps/server/src/modules/tool/common/uc/tool-permission-helper.ts index 6e47f6db97c..dc4f339b4ab 100644 --- a/apps/server/src/modules/tool/common/uc/tool-permission-helper.ts +++ b/apps/server/src/modules/tool/common/uc/tool-permission-helper.ts @@ -1,7 +1,7 @@ import { forwardRef, Inject, Injectable } from '@nestjs/common'; -import { EntityId, SchoolDO, User } from '@shared/domain'; +import { EntityId, LegacySchoolDo, User } from '@shared/domain'; import { AuthorizableReferenceType, AuthorizationContext, AuthorizationService } from '@src/modules/authorization'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { ContextExternalTool } from '../../context-external-tool/domain'; import { SchoolExternalTool } from '../../school-external-tool/domain'; import { ContextTypeMapper } from '../mapper'; @@ -10,7 +10,7 @@ import { ContextTypeMapper } from '../mapper'; export class ToolPermissionHelper { constructor( @Inject(forwardRef(() => AuthorizationService)) private authorizationService: AuthorizationService, - private readonly schoolService: SchoolService + private readonly schoolService: LegacySchoolService ) {} // TODO build interface to get contextDO by contextType @@ -42,7 +42,7 @@ export class ToolPermissionHelper { context: AuthorizationContext ): Promise { const user: User = await this.authorizationService.getUserWithPermissions(userId); - const school: SchoolDO = await this.schoolService.getSchoolById(schoolExternalTool.schoolId); + const school: LegacySchoolDo = await this.schoolService.getSchoolById(schoolExternalTool.schoolId); this.authorizationService.checkPermission(user, school, context); } } diff --git a/apps/server/src/modules/tool/common/uc/tool-permissions-helper.spec.ts b/apps/server/src/modules/tool/common/uc/tool-permissions-helper.spec.ts index a42c1c5cbde..b1567693130 100644 --- a/apps/server/src/modules/tool/common/uc/tool-permissions-helper.spec.ts +++ b/apps/server/src/modules/tool/common/uc/tool-permissions-helper.spec.ts @@ -1,9 +1,14 @@ import { Test, TestingModule } from '@nestjs/testing'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; -import { contextExternalToolFactory, schoolDOFactory, schoolExternalToolFactory, setupEntities } from '@shared/testing'; -import { Permission, SchoolDO } from '@shared/domain'; +import { + contextExternalToolFactory, + legacySchoolDoFactory, + schoolExternalToolFactory, + setupEntities, +} from '@shared/testing'; +import { Permission, LegacySchoolDo } from '@shared/domain'; import { AuthorizationContext, AuthorizationContextBuilder, AuthorizationService } from '@src/modules/authorization'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { ContextExternalTool } from '../../context-external-tool/domain'; import { ToolPermissionHelper } from './tool-permission-helper'; import { SchoolExternalTool } from '../../school-external-tool/domain'; @@ -13,7 +18,7 @@ describe('ToolPermissionHelper', () => { let helper: ToolPermissionHelper; let authorizationService: DeepMocked; - let schoolService: DeepMocked; + let schoolService: DeepMocked; beforeAll(async () => { await setupEntities(); @@ -25,15 +30,15 @@ describe('ToolPermissionHelper', () => { useValue: createMock(), }, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, ], }).compile(); helper = module.get(ToolPermissionHelper); authorizationService = module.get(AuthorizationService); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); }); afterAll(async () => { @@ -79,7 +84,7 @@ describe('ToolPermissionHelper', () => { const userId = 'userId'; const schoolExternalTool: SchoolExternalTool = schoolExternalToolFactory.buildWithId(); const context: AuthorizationContext = AuthorizationContextBuilder.read([Permission.SCHOOL_TOOL_ADMIN]); - const school: SchoolDO = schoolDOFactory.build({ id: schoolExternalTool.schoolId }); + const school: LegacySchoolDo = legacySchoolDoFactory.build({ id: schoolExternalTool.schoolId }); schoolService.getSchoolById.mockResolvedValue(school); diff --git a/apps/server/src/modules/tool/context-external-tool/service/context-external-tool-authorizable.service.spec.ts b/apps/server/src/modules/tool/context-external-tool/service/context-external-tool-authorizable.service.spec.ts index 96828243654..a0698e904a9 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/context-external-tool-authorizable.service.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/context-external-tool-authorizable.service.spec.ts @@ -1,4 +1,4 @@ -import { contextExternalToolFactory, schoolDOFactory, schoolExternalToolFactory } from '@shared/testing'; +import { contextExternalToolFactory, legacySchoolDoFactory, schoolExternalToolFactory } from '@shared/testing'; import { Test, TestingModule } from '@nestjs/testing'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { ContextExternalToolRepo } from '@shared/repo'; @@ -38,7 +38,7 @@ describe('ContextExternalToolAuthorizableService', () => { describe('findById', () => { describe('when id is given', () => { const setup = () => { - const schoolId: string = schoolDOFactory.buildWithId().id as string; + const schoolId: string = legacySchoolDoFactory.buildWithId().id as string; const schoolExternalTool: SchoolExternalTool = schoolExternalToolFactory.build({ schoolId, }); diff --git a/apps/server/src/modules/tool/context-external-tool/service/context-external-tool.service.spec.ts b/apps/server/src/modules/tool/context-external-tool/service/context-external-tool.service.spec.ts index 1f2a1496fac..28cb093ae2d 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/context-external-tool.service.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/context-external-tool.service.spec.ts @@ -4,7 +4,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { ContextExternalToolRepo } from '@shared/repo'; import { contextExternalToolFactory, - schoolDOFactory, + legacySchoolDoFactory, schoolExternalToolFactory, } from '@shared/testing/factory/domainobject'; import { AuthorizationService } from '@src/modules/authorization'; @@ -133,7 +133,7 @@ describe('ContextExternalToolService', () => { describe('getContextExternalToolById', () => { describe('when contextExternalToolId is given', () => { const setup = () => { - const schoolId: string = schoolDOFactory.buildWithId().id as string; + const schoolId: string = legacySchoolDoFactory.buildWithId().id as string; const schoolExternalTool: SchoolExternalTool = schoolExternalToolFactory.build({ schoolId, }); diff --git a/apps/server/src/modules/tool/tool-api.module.ts b/apps/server/src/modules/tool/tool-api.module.ts index a93420b59da..fe775e01fd3 100644 --- a/apps/server/src/modules/tool/tool-api.module.ts +++ b/apps/server/src/modules/tool/tool-api.module.ts @@ -2,7 +2,7 @@ import { Module } from '@nestjs/common'; import { LtiToolRepo } from '@shared/repo'; import { LoggerModule } from '@src/core/logger'; import { AuthorizationModule } from '@src/modules/authorization'; -import { SchoolModule } from '@src/modules/school'; +import { LegacySchoolModule } from '@src/modules/legacy-school'; import { UserModule } from '@src/modules/user'; import { ToolContextController } from './context-external-tool/controller'; import { ContextExternalToolUc } from './context-external-tool/uc'; @@ -26,7 +26,7 @@ import { CommonToolModule } from './common'; UserModule, AuthorizationModule, LoggerModule, - SchoolModule, + LegacySchoolModule, ToolConfigModule, ], controllers: [ diff --git a/apps/server/src/modules/tool/tool-launch/service/strategy/abstract-launch.strategy.spec.ts b/apps/server/src/modules/tool/tool-launch/service/strategy/abstract-launch.strategy.spec.ts index a9514e62de1..7dba13fd2f5 100644 --- a/apps/server/src/modules/tool/tool-launch/service/strategy/abstract-launch.strategy.spec.ts +++ b/apps/server/src/modules/tool/tool-launch/service/strategy/abstract-launch.strategy.spec.ts @@ -2,18 +2,18 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { ObjectId } from '@mikro-orm/mongodb'; import { Injectable } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { Course, EntityId, SchoolDO } from '@shared/domain'; +import { Course, EntityId, LegacySchoolDo } from '@shared/domain'; import { contextExternalToolFactory, courseFactory, customParameterFactory, externalToolFactory, - schoolDOFactory, + legacySchoolDoFactory, schoolExternalToolFactory, setupEntities, } from '@shared/testing'; import { CourseService } from '@src/modules/learnroom/service'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { CustomParameterEntry } from '../../../common/domain'; import { CustomParameterLocation, @@ -73,7 +73,7 @@ describe('AbstractLaunchStrategy', () => { let module: TestingModule; let launchStrategy: TestLaunchStrategy; - let schoolService: DeepMocked; + let schoolService: DeepMocked; let courseService: DeepMocked; beforeAll(async () => { @@ -83,8 +83,8 @@ describe('AbstractLaunchStrategy', () => { providers: [ TestLaunchStrategy, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: CourseService, @@ -94,7 +94,7 @@ describe('AbstractLaunchStrategy', () => { }).compile(); launchStrategy = module.get(TestLaunchStrategy); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); courseService = module.get(CourseService); }); @@ -184,7 +184,7 @@ describe('AbstractLaunchStrategy', () => { }); // Other - const school: SchoolDO = schoolDOFactory.buildWithId( + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId( { officialSchoolNumber: '1234', }, @@ -369,7 +369,7 @@ describe('AbstractLaunchStrategy', () => { parameters: [], }); - const school: SchoolDO = schoolDOFactory.buildWithId({ + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ officialSchoolNumber: undefined, }); diff --git a/apps/server/src/modules/tool/tool-launch/service/strategy/abstract-launch.strategy.ts b/apps/server/src/modules/tool/tool-launch/service/strategy/abstract-launch.strategy.ts index 2a790c99cb8..9004e461ae2 100644 --- a/apps/server/src/modules/tool/tool-launch/service/strategy/abstract-launch.strategy.ts +++ b/apps/server/src/modules/tool/tool-launch/service/strategy/abstract-launch.strategy.ts @@ -1,7 +1,7 @@ import { Injectable } from '@nestjs/common'; -import { Course, EntityId, SchoolDO } from '@shared/domain'; +import { Course, EntityId, LegacySchoolDo } from '@shared/domain'; import { CourseService } from '@src/modules/learnroom/service'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { URLSearchParams } from 'url'; import { CustomParameter, CustomParameterEntry } from '../../../common/domain'; import { @@ -21,7 +21,7 @@ import { IToolLaunchStrategy } from './tool-launch-strategy.interface'; @Injectable() export abstract class AbstractLaunchStrategy implements IToolLaunchStrategy { - constructor(private readonly schoolService: SchoolService, private readonly courseService: CourseService) {} + constructor(private readonly schoolService: LegacySchoolService, private readonly courseService: CourseService) {} public async createLaunchData(userId: EntityId, data: IToolLaunchParams): Promise { const launchData: ToolLaunchData = this.buildToolLaunchDataFromExternalTool(data.externalTool); @@ -226,7 +226,7 @@ export abstract class AbstractLaunchStrategy implements IToolLaunchStrategy { ); } case CustomParameterType.AUTO_SCHOOLNUMBER: { - const school: SchoolDO = await this.schoolService.getSchoolById(schoolExternalTool.schoolId); + const school: LegacySchoolDo = await this.schoolService.getSchoolById(schoolExternalTool.schoolId); return school.officialSchoolNumber; } diff --git a/apps/server/src/modules/tool/tool-launch/service/strategy/basic-tool-launch.strategy.spec.ts b/apps/server/src/modules/tool/tool-launch/service/strategy/basic-tool-launch.strategy.spec.ts index 76cdb6724d0..a18a760b0b3 100644 --- a/apps/server/src/modules/tool/tool-launch/service/strategy/basic-tool-launch.strategy.spec.ts +++ b/apps/server/src/modules/tool/tool-launch/service/strategy/basic-tool-launch.strategy.spec.ts @@ -1,8 +1,8 @@ import { createMock } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; import { contextExternalToolFactory, externalToolFactory, schoolExternalToolFactory } from '@shared/testing'; -import { SchoolService } from '@src/modules/school'; import { CourseService } from '@src/modules/learnroom/service'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { ContextExternalTool } from '../../../context-external-tool/domain'; import { ExternalTool } from '../../../external-tool/domain'; import { SchoolExternalTool } from '../../../school-external-tool/domain'; @@ -19,8 +19,8 @@ describe('BasicToolLaunchStrategy', () => { providers: [ BasicToolLaunchStrategy, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: CourseService, diff --git a/apps/server/src/modules/tool/tool-launch/service/strategy/lti11-tool-launch.strategy.spec.ts b/apps/server/src/modules/tool/tool-launch/service/strategy/lti11-tool-launch.strategy.spec.ts index a711cbce7d5..a0db37651be 100644 --- a/apps/server/src/modules/tool/tool-launch/service/strategy/lti11-tool-launch.strategy.spec.ts +++ b/apps/server/src/modules/tool/tool-launch/service/strategy/lti11-tool-launch.strategy.spec.ts @@ -10,7 +10,7 @@ import { } from '@shared/testing'; import { pseudonymFactory } from '@shared/testing/factory/domainobject/pseudonym.factory'; import { PseudonymService } from '@src/modules/pseudonym/service'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { UserService } from '@src/modules/user'; import { ObjectId } from 'bson'; import { Authorization } from 'oauth-1.0a'; @@ -49,8 +49,8 @@ describe('Lti11ToolLaunchStrategy', () => { useValue: createMock(), }, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: CourseService, diff --git a/apps/server/src/modules/tool/tool-launch/service/strategy/lti11-tool-launch.strategy.ts b/apps/server/src/modules/tool/tool-launch/service/strategy/lti11-tool-launch.strategy.ts index aa2149c8da4..b6ce4ffd55e 100644 --- a/apps/server/src/modules/tool/tool-launch/service/strategy/lti11-tool-launch.strategy.ts +++ b/apps/server/src/modules/tool/tool-launch/service/strategy/lti11-tool-launch.strategy.ts @@ -1,11 +1,11 @@ import { Injectable, InternalServerErrorException, UnprocessableEntityException } from '@nestjs/common'; import { EntityId, LtiPrivacyPermission, Pseudonym, RoleName, UserDO } from '@shared/domain'; import { RoleReference } from '@shared/domain/domainobject'; +import { CourseService } from '@src/modules/learnroom/service'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { PseudonymService } from '@src/modules/pseudonym'; -import { SchoolService } from '@src/modules/school'; import { UserService } from '@src/modules/user'; import { Authorization } from 'oauth-1.0a'; -import { CourseService } from '@src/modules/learnroom/service'; import { LtiRole } from '../../../common/enum'; import { ExternalTool } from '../../../external-tool/domain'; import { LtiRoleMapper } from '../../mapper'; @@ -20,7 +20,7 @@ export class Lti11ToolLaunchStrategy extends AbstractLaunchStrategy { private readonly userService: UserService, private readonly pseudonymService: PseudonymService, private readonly lti11EncryptionService: Lti11EncryptionService, - schoolService: SchoolService, + schoolService: LegacySchoolService, courseService: CourseService ) { super(schoolService, courseService); diff --git a/apps/server/src/modules/tool/tool-launch/service/strategy/oauth2-tool-launch.strategy.spec.ts b/apps/server/src/modules/tool/tool-launch/service/strategy/oauth2-tool-launch.strategy.spec.ts index c206ded9ad5..b49eb4c85de 100644 --- a/apps/server/src/modules/tool/tool-launch/service/strategy/oauth2-tool-launch.strategy.spec.ts +++ b/apps/server/src/modules/tool/tool-launch/service/strategy/oauth2-tool-launch.strategy.spec.ts @@ -1,8 +1,8 @@ import { createMock } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; import { contextExternalToolFactory, externalToolFactory, schoolExternalToolFactory } from '@shared/testing'; -import { SchoolService } from '@src/modules/school'; import { CourseService } from '@src/modules/learnroom/service'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { ContextExternalTool } from '../../../context-external-tool/domain'; import { ExternalTool } from '../../../external-tool/domain'; import { SchoolExternalTool } from '../../../school-external-tool/domain'; @@ -19,8 +19,8 @@ describe('OAuth2ToolLaunchStrategy', () => { providers: [ OAuth2ToolLaunchStrategy, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: CourseService, diff --git a/apps/server/src/modules/tool/tool-launch/tool-launch.module.ts b/apps/server/src/modules/tool/tool-launch/tool-launch.module.ts index 858ab1ff017..6799a50bca2 100644 --- a/apps/server/src/modules/tool/tool-launch/tool-launch.module.ts +++ b/apps/server/src/modules/tool/tool-launch/tool-launch.module.ts @@ -1,8 +1,8 @@ import { Module } from '@nestjs/common'; +import { LearnroomModule } from '@src/modules/learnroom'; +import { LegacySchoolModule } from '@src/modules/legacy-school'; import { PseudonymModule } from '@src/modules/pseudonym'; -import { SchoolModule } from '@src/modules/school'; import { UserModule } from '@src/modules/user'; -import { LearnroomModule } from '@src/modules/learnroom'; import { CommonToolModule } from '../common'; import { ContextExternalToolModule } from '../context-external-tool'; import { ExternalToolModule } from '../external-tool'; @@ -16,7 +16,7 @@ import { BasicToolLaunchStrategy, Lti11ToolLaunchStrategy, OAuth2ToolLaunchStrat ExternalToolModule, SchoolExternalToolModule, ContextExternalToolModule, - SchoolModule, + LegacySchoolModule, UserModule, PseudonymModule, LearnroomModule, diff --git a/apps/server/src/modules/user-import/controller/import-user.controller.spec.ts b/apps/server/src/modules/user-import/controller/import-user.controller.spec.ts index 386a2e874b8..91b1ebc6ec7 100644 --- a/apps/server/src/modules/user-import/controller/import-user.controller.spec.ts +++ b/apps/server/src/modules/user-import/controller/import-user.controller.spec.ts @@ -2,7 +2,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { ImportUserRepo, SystemRepo, UserRepo } from '@shared/repo'; import { AccountService } from '@src/modules/account/services/account.service'; import { AuthorizationService } from '@src/modules/authorization'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { LoggerModule } from '@src/core/logger'; import { ConfigModule } from '@nestjs/config'; import { UserImportUc } from '../uc/user-import.uc'; @@ -34,7 +34,7 @@ describe('ImportUserController', () => { useValue: {}, }, { - provide: SchoolService, + provide: LegacySchoolService, useValue: {}, }, { diff --git a/apps/server/src/modules/user-import/uc/user-import.uc.spec.ts b/apps/server/src/modules/user-import/uc/user-import.uc.spec.ts index 66ce2c32fef..0f2311da1b4 100644 --- a/apps/server/src/modules/user-import/uc/user-import.uc.spec.ts +++ b/apps/server/src/modules/user-import/uc/user-import.uc.spec.ts @@ -2,10 +2,12 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Configuration } from '@hpi-schul-cloud/commons'; import { ObjectId } from '@mikro-orm/mongodb'; import { BadRequestException, ForbiddenException } from '@nestjs/common'; +import { ConfigModule } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { UserAlreadyAssignedToImportUserError } from '@shared/common'; import { ImportUser, + LegacySchoolDo, MatchCreator, MatchCreatorScope, Permission, @@ -14,16 +16,14 @@ import { System, User, } from '@shared/domain'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; import { MongoMemoryDatabaseModule } from '@shared/infra/database'; import { ImportUserRepo, SystemRepo, UserRepo } from '@shared/repo'; import { federalStateFactory, importUserFactory, schoolFactory, userFactory } from '@shared/testing'; import { systemFactory } from '@shared/testing/factory/system.factory'; +import { LoggerModule } from '@src/core/logger'; import { AccountService } from '@src/modules/account/services/account.service'; import { AuthorizationService } from '@src/modules/authorization'; -import { LoggerModule } from '@src/core/logger'; -import { ConfigModule } from '@nestjs/config'; -import { SchoolService } from '../../school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { LdapAlreadyPersistedException, MigrationAlreadyActivatedException, @@ -37,7 +37,7 @@ describe('[ImportUserModule]', () => { let uc: UserImportUc; let accountService: DeepMocked; let importUserRepo: DeepMocked; - let schoolService: DeepMocked; + let schoolService: DeepMocked; let systemRepo: DeepMocked; let userRepo: DeepMocked; let authorizationService: DeepMocked; @@ -61,8 +61,8 @@ describe('[ImportUserModule]', () => { useValue: createMock(), }, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: SystemRepo, @@ -81,7 +81,7 @@ describe('[ImportUserModule]', () => { uc = module.get(UserImportUc); // TODO UserRepo not available in UserUc?! accountService = module.get(AccountService); importUserRepo = module.get(ImportUserRepo); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); systemRepo = module.get(SystemRepo); userRepo = module.get(UserRepo); authorizationService = module.get(AuthorizationService); @@ -114,7 +114,7 @@ describe('[ImportUserModule]', () => { }); }; - const createMockSchoolDo = (school?: School): SchoolDO => { + const createMockSchoolDo = (school?: School): LegacySchoolDo => { const name = school ? school.name : 'testSchool'; const id = school ? school.id : 'someId'; const features = school ? school.features ?? [SchoolFeatures.LDAP_UNIVENTION_MIGRATION] : []; @@ -126,7 +126,7 @@ describe('[ImportUserModule]', () => { school && school.systems.isInitialized() ? school.systems.getItems().map((system: System) => system.id) : []; const federalState = school ? school.federalState : federalStateFactory.build(); - return new SchoolDO({ + return new LegacySchoolDo({ id, name, features, @@ -635,9 +635,11 @@ describe('[ImportUserModule]', () => { }); it('Should save school params', async () => { schoolServiceSaveSpy.mockRestore(); - schoolServiceSaveSpy = schoolService.save.mockImplementation((schoolDo: SchoolDO) => Promise.resolve(schoolDo)); + schoolServiceSaveSpy = schoolService.save.mockImplementation((schoolDo: LegacySchoolDo) => + Promise.resolve(schoolDo) + ); await uc.startSchoolInUserMigration(currentUser.id); - const schoolParams: SchoolDO = { ...createMockSchoolDo(school) }; + const schoolParams: LegacySchoolDo = { ...createMockSchoolDo(school) }; schoolParams.inUserMigration = true; schoolParams.externalId = 'foo'; schoolParams.inMaintenanceSince = currentDate; diff --git a/apps/server/src/modules/user-import/uc/user-import.uc.ts b/apps/server/src/modules/user-import/uc/user-import.uc.ts index 25c002601ef..ef0664c9ed7 100644 --- a/apps/server/src/modules/user-import/uc/user-import.uc.ts +++ b/apps/server/src/modules/user-import/uc/user-import.uc.ts @@ -1,3 +1,4 @@ +import { Configuration } from '@hpi-schul-cloud/commons'; import { BadRequestException, ForbiddenException, Injectable, InternalServerErrorException } from '@nestjs/common'; import { UserAlreadyAssignedToImportUserError } from '@shared/common'; import { @@ -6,8 +7,9 @@ import { EntityId, IFindOptions, IImportUserScope, - INameMatch, ImportUser, + INameMatch, + LegacySchoolDo, MatchCreator, MatchCreatorScope, Permission, @@ -15,15 +17,12 @@ import { System, User, } from '@shared/domain'; - -import { Configuration } from '@hpi-schul-cloud/commons'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; import { ImportUserRepo, SystemRepo, UserRepo } from '@shared/repo'; import { Logger } from '@src/core/logger'; import { AccountService } from '@src/modules/account/services/account.service'; import { AccountDto } from '@src/modules/account/services/dto/account.dto'; import { AuthorizationService } from '@src/modules/authorization'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { MigrationMayBeCompleted, MigrationMayNotBeCompleted, @@ -49,7 +48,7 @@ export class UserImportUc { private readonly accountService: AccountService, private readonly importUserRepo: ImportUserRepo, private readonly authorizationService: AuthorizationService, - private readonly schoolService: SchoolService, + private readonly schoolService: LegacySchoolService, private readonly systemRepo: SystemRepo, private readonly userRepo: UserRepo, private readonly logger: Logger @@ -57,7 +56,7 @@ export class UserImportUc { this.logger.setContext(UserImportUc.name); } - private checkFeatureEnabled(school: SchoolDO): void | never { + private checkFeatureEnabled(school: LegacySchoolDo): void | never { const enabled = Configuration.get('FEATURE_USER_MIGRATION_ENABLED') as boolean; const isLdapPilotSchool = school.features && school.features.includes(SchoolFeatures.LDAP_UNIVENTION_MIGRATION); if (!enabled && !isLdapPilotSchool) { @@ -79,7 +78,7 @@ export class UserImportUc { options?: IFindOptions ): Promise> { const currentUser = await this.getCurrentUser(currentUserId, Permission.SCHOOL_IMPORT_USERS_VIEW); - const school: SchoolDO = await this.schoolService.getSchoolById(currentUser.school.id); + const school: LegacySchoolDo = await this.schoolService.getSchoolById(currentUser.school.id); this.checkFeatureEnabled(school); // TODO Change ImportUserRepo to DO to fix this workaround const countedImportUsers = await this.importUserRepo.findImportUsers(currentUser.school, query, options); @@ -95,7 +94,7 @@ export class UserImportUc { */ async setMatch(currentUserId: EntityId, importUserId: EntityId, userMatchId: EntityId): Promise { const currentUser = await this.getCurrentUser(currentUserId, Permission.SCHOOL_IMPORT_USERS_UPDATE); - const school: SchoolDO = await this.schoolService.getSchoolById(currentUser.school.id); + const school: LegacySchoolDo = await this.schoolService.getSchoolById(currentUser.school.id); this.checkFeatureEnabled(school); const importUser = await this.importUserRepo.findById(importUserId); const userMatch = await this.userRepo.findById(userMatchId, true); @@ -120,7 +119,7 @@ export class UserImportUc { async removeMatch(currentUserId: EntityId, importUserId: EntityId): Promise { const currentUser = await this.getCurrentUser(currentUserId, Permission.SCHOOL_IMPORT_USERS_UPDATE); - const school: SchoolDO = await this.schoolService.getSchoolById(currentUser.school.id); + const school: LegacySchoolDo = await this.schoolService.getSchoolById(currentUser.school.id); this.checkFeatureEnabled(school); const importUser = await this.importUserRepo.findById(importUserId); // check same school @@ -137,7 +136,7 @@ export class UserImportUc { async updateFlag(currentUserId: EntityId, importUserId: EntityId, flagged: boolean): Promise { const currentUser = await this.getCurrentUser(currentUserId, Permission.SCHOOL_IMPORT_USERS_UPDATE); - const school: SchoolDO = await this.schoolService.getSchoolById(currentUser.school.id); + const school: LegacySchoolDo = await this.schoolService.getSchoolById(currentUser.school.id); this.checkFeatureEnabled(school); const importUser = await this.importUserRepo.findById(importUserId); @@ -168,7 +167,7 @@ export class UserImportUc { options?: IFindOptions ): Promise> { const currentUser = await this.getCurrentUser(currentUserId, Permission.SCHOOL_IMPORT_USERS_VIEW); - const school: SchoolDO = await this.schoolService.getSchoolById(currentUser.school.id); + const school: LegacySchoolDo = await this.schoolService.getSchoolById(currentUser.school.id); this.checkFeatureEnabled(school); // TODO Change to UserService to fix this workaround const unmatchedCountedUsers = await this.userRepo.findWithoutImportUser(currentUser.school, query, options); @@ -177,7 +176,7 @@ export class UserImportUc { async saveAllUsersMatches(currentUserId: EntityId): Promise { const currentUser = await this.getCurrentUser(currentUserId, Permission.SCHOOL_IMPORT_USERS_MIGRATE); - const school: SchoolDO = await this.schoolService.getSchoolById(currentUser.school.id); + const school: LegacySchoolDo = await this.schoolService.getSchoolById(currentUser.school.id); this.checkFeatureEnabled(school); const filters: IImportUserScope = { matches: [MatchCreatorScope.MANUAL, MatchCreatorScope.AUTO] }; // TODO batch/paginated import? @@ -219,7 +218,7 @@ export class UserImportUc { private async endSchoolInUserMigration(currentUserId: EntityId): Promise { const currentUser = await this.getCurrentUser(currentUserId, Permission.SCHOOL_IMPORT_USERS_MIGRATE); - const school: SchoolDO = await this.schoolService.getSchoolById(currentUser.school.id); + const school: LegacySchoolDo = await this.schoolService.getSchoolById(currentUser.school.id); this.checkFeatureEnabled(school); if (!school.externalId || school.inUserMigration !== true || !school.inMaintenanceSince) { this.logger.warning(new MigrationMayBeCompleted(school.inUserMigration)); @@ -231,7 +230,7 @@ export class UserImportUc { async startSchoolInUserMigration(currentUserId: EntityId, useCentralLdap = true): Promise { const currentUser = await this.getCurrentUser(currentUserId, Permission.SCHOOL_IMPORT_USERS_MIGRATE); - const school: SchoolDO = await this.schoolService.getSchoolById(currentUser.school.id); + const school: LegacySchoolDo = await this.schoolService.getSchoolById(currentUser.school.id); this.logger.notice(new SchoolInUserMigrationStartLoggable(currentUserId, school.name, useCentralLdap)); this.checkFeatureEnabled(school); this.checkSchoolNumber(school, useCentralLdap); @@ -253,7 +252,7 @@ export class UserImportUc { async endSchoolInMaintenance(currentUserId: EntityId): Promise { const currentUser = await this.getCurrentUser(currentUserId, Permission.SCHOOL_IMPORT_USERS_MIGRATE); - const school: SchoolDO = await this.schoolService.getSchoolById(currentUser.school.id); + const school: LegacySchoolDo = await this.schoolService.getSchoolById(currentUser.school.id); this.checkFeatureEnabled(school); if (school.inUserMigration !== false || !school.inMaintenanceSince || !school.externalId) { this.logger.warning(new MigrationMayNotBeCompleted(school.inUserMigration)); @@ -271,7 +270,10 @@ export class UserImportUc { return currentUser; } - private async updateUserAndAccount(importUser: ImportUser, school: SchoolDO): Promise<[User, Account] | undefined> { + private async updateUserAndAccount( + importUser: ImportUser, + school: LegacySchoolDo + ): Promise<[User, Account] | undefined> { if (!importUser.user || !importUser.loginName || !school.externalId) { return; } @@ -296,7 +298,7 @@ export class UserImportUc { return system; } - private async checkNoExistingLdapBeforeStart(school: SchoolDO): Promise { + private async checkNoExistingLdapBeforeStart(school: LegacySchoolDo): Promise { if (school.systems && school.systems?.length > 0) { for (const systemId of school.systems) { // very unusual to have more than 1 system @@ -309,13 +311,13 @@ export class UserImportUc { } } - private checkSchoolNumber(school: SchoolDO, useCentralLdap: boolean): void | never { + private checkSchoolNumber(school: LegacySchoolDo, useCentralLdap: boolean): void | never { if (useCentralLdap && !school.officialSchoolNumber) { throw new MissingSchoolNumberException(); } } - private checkSchoolNotInMigration(school: SchoolDO): void | never { + private checkSchoolNotInMigration(school: LegacySchoolDo): void | never { if (school.inUserMigration !== undefined && school.inUserMigration !== null) { throw new MigrationAlreadyActivatedException(); } diff --git a/apps/server/src/modules/user-import/user-import.module.ts b/apps/server/src/modules/user-import/user-import.module.ts index af5e4e89fa3..6e881ff5b2f 100644 --- a/apps/server/src/modules/user-import/user-import.module.ts +++ b/apps/server/src/modules/user-import/user-import.module.ts @@ -1,16 +1,16 @@ import { Module } from '@nestjs/common'; -import { ImportUserRepo, SchoolRepo, SystemRepo, UserRepo } from '@shared/repo'; +import { ImportUserRepo, LegacySchoolRepo, SystemRepo, UserRepo } from '@shared/repo'; import { LoggerModule } from '@src/core/logger'; +import { LegacySchoolModule } from '@src/modules/legacy-school'; import { AccountModule } from '../account'; import { AuthorizationModule } from '../authorization'; -import { SchoolModule } from '../school'; import { ImportUserController } from './controller/import-user.controller'; import { UserImportUc } from './uc/user-import.uc'; @Module({ - imports: [LoggerModule, AccountModule, SchoolModule, AuthorizationModule], + imports: [LoggerModule, AccountModule, LegacySchoolModule, AuthorizationModule], controllers: [ImportUserController], - providers: [UserImportUc, ImportUserRepo, SchoolRepo, SystemRepo, UserRepo], + providers: [UserImportUc, ImportUserRepo, LegacySchoolRepo, SystemRepo, UserRepo], exports: [], }) /** diff --git a/apps/server/src/modules/user-login-migration/service/migration-check.service.spec.ts b/apps/server/src/modules/user-login-migration/service/migration-check.service.spec.ts index c5092c9d393..c61382b9f63 100644 --- a/apps/server/src/modules/user-login-migration/service/migration-check.service.spec.ts +++ b/apps/server/src/modules/user-login-migration/service/migration-check.service.spec.ts @@ -1,9 +1,9 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; -import { SchoolDO, UserDO, UserLoginMigrationDO } from '@shared/domain'; +import { LegacySchoolDo, UserDO, UserLoginMigrationDO } from '@shared/domain'; import { UserLoginMigrationRepo } from '@shared/repo'; -import { schoolDOFactory, userDoFactory } from '@shared/testing'; -import { SchoolService } from '@src/modules/school'; +import { legacySchoolDoFactory, userDoFactory } from '@shared/testing'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { UserService } from '@src/modules/user'; import { MigrationCheckService } from './migration-check.service'; @@ -12,7 +12,7 @@ describe('MigrationCheckService', () => { let service: MigrationCheckService; let userService: DeepMocked; - let schoolService: DeepMocked; + let schoolService: DeepMocked; let userLoginMigrationRepo: DeepMocked; beforeAll(async () => { @@ -24,8 +24,8 @@ describe('MigrationCheckService', () => { useValue: createMock(), }, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: UserLoginMigrationRepo, @@ -36,7 +36,7 @@ describe('MigrationCheckService', () => { service = module.get(MigrationCheckService); userService = module.get(UserService); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); userLoginMigrationRepo = module.get(UserLoginMigrationRepo); }); @@ -62,7 +62,7 @@ describe('MigrationCheckService', () => { describe('when a non-migrating school was found', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); const user: UserDO = userDoFactory.buildWithId(); schoolService.getSchoolBySchoolNumber.mockResolvedValue(school); @@ -81,7 +81,7 @@ describe('MigrationCheckService', () => { describe('when a migrating school was found but no user', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); const userLoginMigration: UserLoginMigrationDO = new UserLoginMigrationDO({ schoolId: school.id as string, targetSystemId: 'targetSystemId', @@ -103,7 +103,7 @@ describe('MigrationCheckService', () => { describe('when a migrating school and a user that has not migrated were found', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); const user: UserDO = userDoFactory.buildWithId({ lastLoginSystemChange: undefined }); const userLoginMigration: UserLoginMigrationDO = new UserLoginMigrationDO({ schoolId: school.id as string, @@ -126,7 +126,7 @@ describe('MigrationCheckService', () => { describe('when a migrating school and a user that has migrated were found', () => { const setup = () => { - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); const user: UserDO = userDoFactory.buildWithId({ lastLoginSystemChange: new Date('2023-03-04') }); const userLoginMigration: UserLoginMigrationDO = new UserLoginMigrationDO({ schoolId: school.id as string, diff --git a/apps/server/src/modules/user-login-migration/service/migration-check.service.ts b/apps/server/src/modules/user-login-migration/service/migration-check.service.ts index d2bfc6cc065..7a0596e3599 100644 --- a/apps/server/src/modules/user-login-migration/service/migration-check.service.ts +++ b/apps/server/src/modules/user-login-migration/service/migration-check.service.ts @@ -1,21 +1,19 @@ import { Injectable } from '@nestjs/common'; -import { EntityId, UserLoginMigrationDO } from '@shared/domain'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { UserDO } from '@shared/domain/domainobject/user.do'; +import { EntityId, LegacySchoolDo, UserDO, UserLoginMigrationDO } from '@shared/domain'; import { UserLoginMigrationRepo } from '@shared/repo'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { UserService } from '@src/modules/user'; @Injectable() export class MigrationCheckService { constructor( private readonly userService: UserService, - private readonly schoolService: SchoolService, + private readonly schoolService: LegacySchoolService, private readonly userLoginMigrationRepo: UserLoginMigrationRepo ) {} async shouldUserMigrate(externalUserId: string, systemId: EntityId, officialSchoolNumber: string): Promise { - const school: SchoolDO | null = await this.schoolService.getSchoolBySchoolNumber(officialSchoolNumber); + const school: LegacySchoolDo | null = await this.schoolService.getSchoolBySchoolNumber(officialSchoolNumber); if (school && school.id) { const userLoginMigration: UserLoginMigrationDO | null = await this.userLoginMigrationRepo.findBySchoolId( diff --git a/apps/server/src/modules/user-login-migration/service/school-migration.service.spec.ts b/apps/server/src/modules/user-login-migration/service/school-migration.service.spec.ts index df40d7ff6bb..19841ffb6de 100644 --- a/apps/server/src/modules/user-login-migration/service/school-migration.service.spec.ts +++ b/apps/server/src/modules/user-login-migration/service/school-migration.service.spec.ts @@ -3,16 +3,12 @@ import { ObjectId } from '@mikro-orm/mongodb'; import { UnprocessableEntityException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ValidationError } from '@shared/common'; -import { UserLoginMigrationDO } from '@shared/domain'; -import { Page } from '@shared/domain/domainobject/page'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { UserDO } from '@shared/domain/domainobject/user.do'; +import { LegacySchoolDo, Page, UserDO, UserLoginMigrationDO } from '@shared/domain'; import { UserLoginMigrationRepo } from '@shared/repo/userloginmigration/user-login-migration.repo'; -import { setupEntities, userDoFactory, userLoginMigrationDOFactory } from '@shared/testing'; -import { schoolDOFactory } from '@shared/testing/factory/domainobject/school.factory'; +import { legacySchoolDoFactory, setupEntities, userDoFactory, userLoginMigrationDOFactory } from '@shared/testing'; import { LegacyLogger } from '@src/core/logger'; import { ICurrentUser } from '@src/modules/authentication'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { UserService } from '@src/modules/user'; import { OAuthMigrationError } from '@src/modules/user-login-migration/error/oauth-migration.error'; import { SchoolMigrationService } from './school-migration.service'; @@ -22,7 +18,7 @@ describe('SchoolMigrationService', () => { let service: SchoolMigrationService; let userService: DeepMocked; - let schoolService: DeepMocked; + let schoolService: DeepMocked; let userLoginMigrationRepo: DeepMocked; beforeAll(async () => { @@ -32,8 +28,8 @@ describe('SchoolMigrationService', () => { providers: [ SchoolMigrationService, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: UserService, @@ -51,7 +47,7 @@ describe('SchoolMigrationService', () => { }).compile(); service = module.get(SchoolMigrationService); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); userService = module.get(UserService); userLoginMigrationRepo = module.get(UserLoginMigrationRepo); @@ -122,7 +118,7 @@ describe('SchoolMigrationService', () => { describe('schoolToMigrate is called', () => { describe('when school number is missing', () => { const setup = () => { - const schoolDO: SchoolDO = schoolDOFactory.buildWithId({ + const schoolDO: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ id: 'schoolId', name: 'schoolName', officialSchoolNumber: 'officialSchoolNumber', @@ -159,7 +155,7 @@ describe('SchoolMigrationService', () => { describe('when school could not be found with official school number', () => { const setup = () => { - const schoolDO: SchoolDO = schoolDOFactory.buildWithId({ + const schoolDO: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ id: 'schoolId', name: 'schoolName', officialSchoolNumber: 'officialSchoolNumber', @@ -196,7 +192,7 @@ describe('SchoolMigrationService', () => { describe('when current users school not match with school of to migrate user ', () => { const setup = () => { - const schoolDO: SchoolDO = schoolDOFactory.buildWithId({ + const schoolDO: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ id: 'schoolId', name: 'schoolName', officialSchoolNumber: 'officialSchoolNumber', @@ -236,7 +232,7 @@ describe('SchoolMigrationService', () => { describe('when school was already migrated', () => { const setup = () => { - const schoolDO: SchoolDO = schoolDOFactory.buildWithId({ + const schoolDO: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ id: 'schoolId', name: 'schoolName', officialSchoolNumber: 'officialSchoolNumber', @@ -259,7 +255,7 @@ describe('SchoolMigrationService', () => { schoolService.getSchoolById.mockResolvedValue(schoolDO); schoolService.getSchoolBySchoolNumber.mockResolvedValue(schoolDO); - const result: SchoolDO | null = await service.schoolToMigrate( + const result: LegacySchoolDo | null = await service.schoolToMigrate( currentUserId, externalId, schoolDO.officialSchoolNumber @@ -271,7 +267,7 @@ describe('SchoolMigrationService', () => { describe('when school has to be migrated', () => { const setup = () => { - const schoolDO: SchoolDO = schoolDOFactory.buildWithId({ + const schoolDO: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ id: 'schoolId', name: 'schoolName', officialSchoolNumber: 'officialSchoolNumber', @@ -293,7 +289,7 @@ describe('SchoolMigrationService', () => { schoolService.getSchoolBySchoolNumber.mockResolvedValue(schoolDO); userService.findById.mockResolvedValue(userDO); - const result: SchoolDO | null = await service.schoolToMigrate( + const result: LegacySchoolDo | null = await service.schoolToMigrate( currentUserId, 'newExternalId', schoolDO.officialSchoolNumber @@ -307,7 +303,7 @@ describe('SchoolMigrationService', () => { describe('migrateSchool is called', () => { describe('when school will be migrated', () => { const setup = () => { - const schoolDO: SchoolDO = schoolDOFactory.buildWithId({ + const schoolDO: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ id: 'schoolId', name: 'schoolName', officialSchoolNumber: 'officialSchoolNumber', @@ -329,7 +325,7 @@ describe('SchoolMigrationService', () => { await service.migrateSchool(newExternalId, schoolDO, targetSystemId); expect(schoolService.save).toHaveBeenCalledWith( - expect.objectContaining>({ + expect.objectContaining>({ systems: [targetSystemId], previousExternalId: firstExternalId, externalId: newExternalId, @@ -345,7 +341,7 @@ describe('SchoolMigrationService', () => { await service.migrateSchool('newExternalId', schoolDO, targetSystemId); expect(schoolService.save).toHaveBeenCalledWith( - expect.objectContaining>({ + expect.objectContaining>({ systems: ['existingSystem', targetSystemId], }) ); @@ -360,7 +356,7 @@ describe('SchoolMigrationService', () => { await service.migrateSchool('newExternalId', schoolDO, targetSystemId); expect(schoolService.save).toHaveBeenCalledWith( - expect.objectContaining>({ + expect.objectContaining>({ systems: [targetSystemId], }) ); diff --git a/apps/server/src/modules/user-login-migration/service/school-migration.service.ts b/apps/server/src/modules/user-login-migration/service/school-migration.service.ts index 2636e35c86c..04f3e44b265 100644 --- a/apps/server/src/modules/user-login-migration/service/school-migration.service.ts +++ b/apps/server/src/modules/user-login-migration/service/school-migration.service.ts @@ -1,9 +1,9 @@ import { Injectable, UnprocessableEntityException } from '@nestjs/common'; import { ValidationError } from '@shared/common'; -import { Page, SchoolDO, UserDO, UserLoginMigrationDO } from '@shared/domain'; +import { Page, LegacySchoolDo, UserDO, UserLoginMigrationDO } from '@shared/domain'; import { UserLoginMigrationRepo } from '@shared/repo'; import { LegacyLogger } from '@src/core/logger'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { UserService } from '@src/modules/user'; import { performance } from 'perf_hooks'; import { OAuthMigrationError } from '../error'; @@ -11,7 +11,7 @@ import { OAuthMigrationError } from '../error'; @Injectable() export class SchoolMigrationService { constructor( - private readonly schoolService: SchoolService, + private readonly schoolService: LegacySchoolService, private readonly logger: LegacyLogger, private readonly userService: UserService, private readonly userLoginMigrationRepo: UserLoginMigrationRepo @@ -25,8 +25,8 @@ export class SchoolMigrationService { } } - async migrateSchool(externalId: string, existingSchool: SchoolDO, targetSystemId: string): Promise { - const schoolDOCopy: SchoolDO = new SchoolDO({ ...existingSchool }); + async migrateSchool(externalId: string, existingSchool: LegacySchoolDo, targetSystemId: string): Promise { + const schoolDOCopy: LegacySchoolDo = new LegacySchoolDo({ ...existingSchool }); try { await this.doMigration(externalId, existingSchool, targetSystemId); @@ -44,7 +44,7 @@ export class SchoolMigrationService { currentUserId: string, externalId: string, officialSchoolNumber: string | undefined - ): Promise { + ): Promise { if (!officialSchoolNumber) { throw new OAuthMigrationError( 'Official school number from target migration system is missing', @@ -54,11 +54,13 @@ export class SchoolMigrationService { const userDO: UserDO | null = await this.userService.findById(currentUserId); if (userDO) { - const schoolDO: SchoolDO = await this.schoolService.getSchoolById(userDO.schoolId); + const schoolDO: LegacySchoolDo = await this.schoolService.getSchoolById(userDO.schoolId); this.checkOfficialSchoolNumbersMatch(schoolDO, officialSchoolNumber); } - const existingSchool: SchoolDO | null = await this.schoolService.getSchoolBySchoolNumber(officialSchoolNumber); + const existingSchool: LegacySchoolDo | null = await this.schoolService.getSchoolBySchoolNumber( + officialSchoolNumber + ); if (!existingSchool) { throw new OAuthMigrationError( @@ -125,7 +127,7 @@ export class SchoolMigrationService { this.logger.warn(`restartMigration for schoolId ${schoolId} took ${endTime - startTime} milliseconds`); } - private async doMigration(externalId: string, schoolDO: SchoolDO, targetSystemId: string): Promise { + private async doMigration(externalId: string, schoolDO: LegacySchoolDo, targetSystemId: string): Promise { if (schoolDO.systems) { schoolDO.systems.push(targetSystemId); } else { @@ -136,13 +138,13 @@ export class SchoolMigrationService { await this.schoolService.save(schoolDO); } - private async rollbackMigration(originalSchoolDO: SchoolDO) { + private async rollbackMigration(originalSchoolDO: LegacySchoolDo) { if (originalSchoolDO) { await this.schoolService.save(originalSchoolDO); } } - private checkOfficialSchoolNumbersMatch(schoolDO: SchoolDO, officialExternalSchoolNumber: string): void { + private checkOfficialSchoolNumbersMatch(schoolDO: LegacySchoolDo, officialExternalSchoolNumber: string): void { if (schoolDO.officialSchoolNumber !== officialExternalSchoolNumber) { throw new OAuthMigrationError( 'Current users school is not the same as school found by official school number from target migration system', diff --git a/apps/server/src/modules/user-login-migration/service/user-login-migration-revert.service.spec.ts b/apps/server/src/modules/user-login-migration/service/user-login-migration-revert.service.spec.ts index 66b13122d13..0b677fd8cf6 100644 --- a/apps/server/src/modules/user-login-migration/service/user-login-migration-revert.service.spec.ts +++ b/apps/server/src/modules/user-login-migration/service/user-login-migration-revert.service.spec.ts @@ -1,7 +1,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { SchoolFeatures } from '@shared/domain'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { setupEntities, userLoginMigrationDOFactory } from '@shared/testing'; import { UserLoginMigrationRevertService } from './user-login-migration-revert.service'; import { UserLoginMigrationService } from './user-login-migration.service'; @@ -10,7 +10,7 @@ describe('UserLoginMigrationRevertService', () => { let module: TestingModule; let service: UserLoginMigrationRevertService; - let schoolService: DeepMocked; + let schoolService: DeepMocked; let userLoginMigrationService: DeepMocked; beforeAll(async () => { @@ -24,14 +24,14 @@ describe('UserLoginMigrationRevertService', () => { useValue: createMock(), }, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, ], }).compile(); service = module.get(UserLoginMigrationRevertService); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); userLoginMigrationService = module.get(UserLoginMigrationService); }); diff --git a/apps/server/src/modules/user-login-migration/service/user-login-migration-revert.service.ts b/apps/server/src/modules/user-login-migration/service/user-login-migration-revert.service.ts index 105f546fc0c..88397e0b179 100644 --- a/apps/server/src/modules/user-login-migration/service/user-login-migration-revert.service.ts +++ b/apps/server/src/modules/user-login-migration/service/user-login-migration-revert.service.ts @@ -1,13 +1,13 @@ import { Injectable } from '@nestjs/common'; import { SchoolFeatures, UserLoginMigrationDO } from '@shared/domain'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { UserLoginMigrationService } from './user-login-migration.service'; @Injectable() export class UserLoginMigrationRevertService { constructor( private readonly userLoginMigrationService: UserLoginMigrationService, - private readonly schoolService: SchoolService + private readonly schoolService: LegacySchoolService ) {} async revertUserLoginMigration(userLoginMigration: UserLoginMigrationDO): Promise { diff --git a/apps/server/src/modules/user-login-migration/service/user-login-migration.service.spec.ts b/apps/server/src/modules/user-login-migration/service/user-login-migration.service.spec.ts index 44d402fa46f..0b755b68415 100644 --- a/apps/server/src/modules/user-login-migration/service/user-login-migration.service.spec.ts +++ b/apps/server/src/modules/user-login-migration/service/user-login-migration.service.spec.ts @@ -3,10 +3,10 @@ import { Configuration } from '@hpi-schul-cloud/commons/lib'; import { ObjectId } from '@mikro-orm/mongodb'; import { InternalServerErrorException, UnprocessableEntityException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { EntityId, SchoolDO, SchoolFeatures, UserDO, UserLoginMigrationDO } from '@shared/domain'; +import { EntityId, LegacySchoolDo, SchoolFeatures, UserDO, UserLoginMigrationDO } from '@shared/domain'; import { UserLoginMigrationRepo } from '@shared/repo'; -import { schoolDOFactory, userDoFactory, userLoginMigrationDOFactory } from '@shared/testing'; -import { SchoolService } from '@src/modules/school'; +import { legacySchoolDoFactory, userDoFactory, userLoginMigrationDOFactory } from '@shared/testing'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { SystemService } from '@src/modules/system'; import { SystemDto } from '@src/modules/system/service'; import { UserService } from '@src/modules/user'; @@ -19,7 +19,7 @@ describe('UserLoginMigrationService', () => { let service: UserLoginMigrationService; let userService: DeepMocked; - let schoolService: DeepMocked; + let schoolService: DeepMocked; let systemService: DeepMocked; let userLoginMigrationRepo: DeepMocked; let schoolMigrationService: DeepMocked; @@ -41,8 +41,8 @@ describe('UserLoginMigrationService', () => { useValue: createMock(), }, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: SystemService, @@ -61,7 +61,7 @@ describe('UserLoginMigrationService', () => { service = module.get(UserLoginMigrationService); userService = module.get(UserService); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); systemService = module.get(SystemService); userLoginMigrationRepo = module.get(UserLoginMigrationRepo); schoolMigrationService = module.get(SchoolMigrationService); @@ -165,7 +165,7 @@ describe('UserLoginMigrationService', () => { describe('when the school has no systems', () => { const setup = () => { const schoolId: EntityId = new ObjectId().toHexString(); - const school: SchoolDO = schoolDOFactory.buildWithId(undefined, schoolId); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(undefined, schoolId); const targetSystemId: EntityId = new ObjectId().toHexString(); const system: SystemDto = new SystemDto({ @@ -212,7 +212,7 @@ describe('UserLoginMigrationService', () => { }); const schoolId: EntityId = new ObjectId().toHexString(); - const school: SchoolDO = schoolDOFactory.buildWithId({ systems: [sourceSystemId] }, schoolId); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: [sourceSystemId] }, schoolId); schoolService.getSchoolById.mockResolvedValue(school); systemService.findByType.mockResolvedValue([system]); @@ -246,7 +246,7 @@ describe('UserLoginMigrationService', () => { describe('when the school has a feature', () => { const setup = () => { const schoolId: EntityId = new ObjectId().toHexString(); - const school: SchoolDO = schoolDOFactory.buildWithId(undefined, schoolId); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(undefined, schoolId); const targetSystemId: EntityId = new ObjectId().toHexString(); const system: SystemDto = new SystemDto({ @@ -274,7 +274,7 @@ describe('UserLoginMigrationService', () => { await service.setMigration(schoolId, true, undefined, undefined); expect(schoolService.save).toHaveBeenCalledWith( - expect.objectContaining>({ + expect.objectContaining>({ features: [existingFeature, SchoolFeatures.OAUTH_PROVISIONING_ENABLED], }) ); @@ -284,7 +284,7 @@ describe('UserLoginMigrationService', () => { describe('when the school has no features yet', () => { const setup = () => { const schoolId: EntityId = new ObjectId().toHexString(); - const school: SchoolDO = schoolDOFactory.buildWithId({ features: undefined }, schoolId); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ features: undefined }, schoolId); const targetSystemId: EntityId = new ObjectId().toHexString(); const system: SystemDto = new SystemDto({ @@ -310,7 +310,7 @@ describe('UserLoginMigrationService', () => { await service.setMigration(schoolId, true, undefined, undefined); expect(schoolService.save).toHaveBeenCalledWith( - expect.objectContaining>({ + expect.objectContaining>({ features: [SchoolFeatures.OAUTH_PROVISIONING_ENABLED], }) ); @@ -320,7 +320,7 @@ describe('UserLoginMigrationService', () => { describe('when modifying a migration that does not exist on the school', () => { const setup = () => { const schoolId: EntityId = new ObjectId().toHexString(); - const school: SchoolDO = schoolDOFactory.buildWithId(undefined, schoolId); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(undefined, schoolId); schoolService.getSchoolById.mockResolvedValue(school); userLoginMigrationRepo.findBySchoolId.mockResolvedValue(null); @@ -343,7 +343,7 @@ describe('UserLoginMigrationService', () => { describe('when creating a new migration but the SANIS system does not exist', () => { const setup = () => { const schoolId: EntityId = new ObjectId().toHexString(); - const school: SchoolDO = schoolDOFactory.buildWithId(undefined, schoolId); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(undefined, schoolId); schoolService.getSchoolById.mockResolvedValue(school); systemService.findByType.mockResolvedValue([]); @@ -368,7 +368,7 @@ describe('UserLoginMigrationService', () => { describe('when restarting the migration', () => { const setup = () => { const schoolId: EntityId = new ObjectId().toHexString(); - const school: SchoolDO = schoolDOFactory.buildWithId(undefined, schoolId); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(undefined, schoolId); const targetSystemId: EntityId = new ObjectId().toHexString(); const system: SystemDto = new SystemDto({ @@ -415,7 +415,7 @@ describe('UserLoginMigrationService', () => { describe('when setting the migration to mandatory', () => { const setup = () => { const schoolId: EntityId = new ObjectId().toHexString(); - const school: SchoolDO = schoolDOFactory.buildWithId(undefined, schoolId); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(undefined, schoolId); const targetSystemId: EntityId = new ObjectId().toHexString(); const system: SystemDto = new SystemDto({ @@ -459,7 +459,7 @@ describe('UserLoginMigrationService', () => { describe('when setting the migration back to optional', () => { const setup = () => { const schoolId: EntityId = new ObjectId().toHexString(); - const school: SchoolDO = schoolDOFactory.buildWithId(undefined, schoolId); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(undefined, schoolId); const targetSystemId: EntityId = new ObjectId().toHexString(); const system: SystemDto = new SystemDto({ @@ -504,7 +504,7 @@ describe('UserLoginMigrationService', () => { describe('when closing the migration', () => { const setup = () => { const schoolId: EntityId = new ObjectId().toHexString(); - const school: SchoolDO = schoolDOFactory.buildWithId(undefined, schoolId); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(undefined, schoolId); const targetSystemId: EntityId = new ObjectId().toHexString(); const system: SystemDto = new SystemDto({ @@ -562,7 +562,7 @@ describe('UserLoginMigrationService', () => { describe('when schoolId is given', () => { const setup = () => { const schoolId: EntityId = new ObjectId().toHexString(); - const school: SchoolDO = schoolDOFactory.buildWithId(undefined, schoolId); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(undefined, schoolId); const targetSystemId: EntityId = new ObjectId().toHexString(); const system: SystemDto = new SystemDto({ @@ -625,7 +625,7 @@ describe('UserLoginMigrationService', () => { }); const schoolId: EntityId = new ObjectId().toHexString(); - const school: SchoolDO = schoolDOFactory.buildWithId({ systems: [sourceSystemId] }, schoolId); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: [sourceSystemId] }, schoolId); schoolService.getSchoolById.mockResolvedValue(school); systemService.findByType.mockResolvedValue([system]); @@ -658,7 +658,7 @@ describe('UserLoginMigrationService', () => { describe('when the school has schoolfeatures', () => { const setup = () => { const schoolId: EntityId = new ObjectId().toHexString(); - const school: SchoolDO = schoolDOFactory.buildWithId(undefined, schoolId); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(undefined, schoolId); const targetSystemId: EntityId = new ObjectId().toHexString(); const system: SystemDto = new SystemDto({ @@ -685,7 +685,7 @@ describe('UserLoginMigrationService', () => { await service.startMigration(schoolId); expect(schoolService.save).toHaveBeenCalledWith( - expect.objectContaining>({ + expect.objectContaining>({ features: [existingFeature, SchoolFeatures.OAUTH_PROVISIONING_ENABLED], }) ); @@ -695,7 +695,7 @@ describe('UserLoginMigrationService', () => { describe('when the school has no features yet', () => { const setup = () => { const schoolId: EntityId = new ObjectId().toHexString(); - const school: SchoolDO = schoolDOFactory.buildWithId({ features: undefined }, schoolId); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ features: undefined }, schoolId); const targetSystemId: EntityId = new ObjectId().toHexString(); const system: SystemDto = new SystemDto({ @@ -719,7 +719,7 @@ describe('UserLoginMigrationService', () => { await service.startMigration(schoolId); expect(schoolService.save).toHaveBeenCalledWith( - expect.objectContaining>({ + expect.objectContaining>({ features: [SchoolFeatures.OAUTH_PROVISIONING_ENABLED], }) ); @@ -729,7 +729,7 @@ describe('UserLoginMigrationService', () => { describe('when creating a new migration but the SANIS system does not exist', () => { const setup = () => { const schoolId: EntityId = new ObjectId().toHexString(); - const school: SchoolDO = schoolDOFactory.buildWithId(undefined, schoolId); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(undefined, schoolId); schoolService.getSchoolById.mockResolvedValue(school); systemService.findByType.mockResolvedValue([]); diff --git a/apps/server/src/modules/user-login-migration/service/user-login-migration.service.ts b/apps/server/src/modules/user-login-migration/service/user-login-migration.service.ts index 1f48b814247..f1037997955 100644 --- a/apps/server/src/modules/user-login-migration/service/user-login-migration.service.ts +++ b/apps/server/src/modules/user-login-migration/service/user-login-migration.service.ts @@ -1,8 +1,8 @@ import { Configuration } from '@hpi-schul-cloud/commons/lib'; import { Injectable, InternalServerErrorException, UnprocessableEntityException } from '@nestjs/common'; -import { EntityId, SchoolDO, SchoolFeatures, SystemTypeEnum, UserDO, UserLoginMigrationDO } from '@shared/domain'; +import { EntityId, LegacySchoolDo, SchoolFeatures, SystemTypeEnum, UserDO, UserLoginMigrationDO } from '@shared/domain'; import { UserLoginMigrationRepo } from '@shared/repo'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { SystemDto, SystemService } from '@src/modules/system'; import { UserService } from '@src/modules/user'; import { UserLoginMigrationNotFoundLoggableException } from '../error'; @@ -13,7 +13,7 @@ export class UserLoginMigrationService { constructor( private readonly userService: UserService, private readonly userLoginMigrationRepo: UserLoginMigrationRepo, - private readonly schoolService: SchoolService, + private readonly schoolService: LegacySchoolService, private readonly systemService: SystemService, private readonly schoolMigrationService: SchoolMigrationService ) {} @@ -32,7 +32,7 @@ export class UserLoginMigrationService { oauthMigrationMandatory?: boolean, oauthMigrationFinished?: boolean ): Promise { - const schoolDo: SchoolDO = await this.schoolService.getSchoolById(schoolId); + const schoolDo: LegacySchoolDo = await this.schoolService.getSchoolById(schoolId); const existingUserLoginMigration: UserLoginMigrationDO | null = await this.userLoginMigrationRepo.findBySchoolId( schoolId @@ -80,7 +80,7 @@ export class UserLoginMigrationService { } async startMigration(schoolId: string): Promise { - const schoolDo: SchoolDO = await this.schoolService.getSchoolById(schoolId); + const schoolDo: LegacySchoolDo = await this.schoolService.getSchoolById(schoolId); const userLoginMigrationDO: UserLoginMigrationDO = await this.createNewMigration(schoolDo); @@ -146,7 +146,7 @@ export class UserLoginMigrationService { return userLoginMigration; } - private async createNewMigration(school: SchoolDO): Promise { + private async createNewMigration(school: LegacySchoolDo): Promise { const oauthSystems: SystemDto[] = await this.systemService.findByType(SystemTypeEnum.OAUTH); const sanisSystem: SystemDto | undefined = oauthSystems.find((system: SystemDto) => system.alias === 'SANIS'); @@ -178,7 +178,7 @@ export class UserLoginMigrationService { return userLoginMigration; } - private enableOauthMigrationFeature(schoolDo: SchoolDO) { + private enableOauthMigrationFeature(schoolDo: LegacySchoolDo) { if (schoolDo.features && !schoolDo.features.includes(SchoolFeatures.OAUTH_PROVISIONING_ENABLED)) { schoolDo.features.push(SchoolFeatures.OAUTH_PROVISIONING_ENABLED); } else { diff --git a/apps/server/src/modules/user-login-migration/service/user-migration.service.spec.ts b/apps/server/src/modules/user-login-migration/service/user-migration.service.spec.ts index c4729ec1bc9..24cb59030a5 100644 --- a/apps/server/src/modules/user-login-migration/service/user-migration.service.spec.ts +++ b/apps/server/src/modules/user-login-migration/service/user-migration.service.spec.ts @@ -4,12 +4,12 @@ import { IConfig } from '@hpi-schul-cloud/commons/lib/interfaces/IConfig'; import { ObjectId } from '@mikro-orm/mongodb'; import { BadRequestException, NotFoundException, UnprocessableEntityException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { RoleName, SchoolDO, UserDO } from '@shared/domain'; -import { schoolDOFactory, setupEntities, userDoFactory } from '@shared/testing'; +import { LegacySchoolDo, RoleName, UserDO } from '@shared/domain'; +import { legacySchoolDoFactory, setupEntities, userDoFactory } from '@shared/testing'; import { LegacyLogger } from '@src/core/logger'; import { AccountService } from '@src/modules/account/services/account.service'; import { AccountDto, AccountSaveDto } from '@src/modules/account/services/dto'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { SystemService } from '@src/modules/system'; import { OauthConfigDto } from '@src/modules/system/service/dto/oauth-config.dto'; import { SystemDto } from '@src/modules/system/service/dto/system.dto'; @@ -24,7 +24,7 @@ describe('UserMigrationService', () => { let configBefore: IConfig; let logger: LegacyLogger; - let schoolService: DeepMocked; + let schoolService: DeepMocked; let systemService: DeepMocked; let userService: DeepMocked; let accountService: DeepMocked; @@ -43,8 +43,8 @@ describe('UserMigrationService', () => { providers: [ UserMigrationService, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: SystemService, @@ -66,7 +66,7 @@ describe('UserMigrationService', () => { }).compile(); service = module.get(UserMigrationService); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); systemService = module.get(SystemService); userService = module.get(UserService); accountService = module.get(AccountService); @@ -89,7 +89,7 @@ describe('UserMigrationService', () => { describe('when finding the migration systems', () => { const setup = () => { const officialSchoolNumber = '3'; - const school: SchoolDO = schoolDOFactory.buildWithId({ name: 'schoolName', officialSchoolNumber }); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ name: 'schoolName', officialSchoolNumber }); schoolService.getSchoolBySchoolNumber.mockResolvedValue(school); diff --git a/apps/server/src/modules/user-login-migration/service/user-migration.service.ts b/apps/server/src/modules/user-login-migration/service/user-migration.service.ts index 2de31471a85..a2e999994f5 100644 --- a/apps/server/src/modules/user-login-migration/service/user-migration.service.ts +++ b/apps/server/src/modules/user-login-migration/service/user-migration.service.ts @@ -1,11 +1,11 @@ import { Configuration } from '@hpi-schul-cloud/commons/lib'; import { BadRequestException, Injectable, NotFoundException, UnprocessableEntityException } from '@nestjs/common'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; +import { LegacySchoolDo } from '@shared/domain'; import { UserDO } from '@shared/domain/domainobject/user.do'; import { LegacyLogger } from '@src/core/logger'; import { AccountService } from '@src/modules/account/services/account.service'; import { AccountDto } from '@src/modules/account/services/dto'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { SystemDto, SystemService } from '@src/modules/system/service'; import { UserService } from '@src/modules/user'; import { EntityId } from '@src/shared/domain/types'; @@ -29,7 +29,7 @@ export class UserMigrationService { private readonly loginUrl: string = '/login'; constructor( - private readonly schoolService: SchoolService, + private readonly schoolService: LegacySchoolService, private readonly systemService: SystemService, private readonly userService: UserService, private readonly logger: LegacyLogger, @@ -40,7 +40,7 @@ export class UserMigrationService { } async getMigrationConsentPageRedirect(officialSchoolNumber: string, originSystemId: string): Promise { - const school: SchoolDO | null = await this.schoolService.getSchoolBySchoolNumber(officialSchoolNumber); + const school: LegacySchoolDo | null = await this.schoolService.getSchoolBySchoolNumber(officialSchoolNumber); if (!school || !school.id) { throw new NotFoundException(`School with offical school number ${officialSchoolNumber} does not exist.`); diff --git a/apps/server/src/modules/user-login-migration/uc/restart-user-login-migration.uc.spec.ts b/apps/server/src/modules/user-login-migration/uc/restart-user-login-migration.uc.spec.ts index 74111af89d7..c6e53ab483d 100644 --- a/apps/server/src/modules/user-login-migration/uc/restart-user-login-migration.uc.spec.ts +++ b/apps/server/src/modules/user-login-migration/uc/restart-user-login-migration.uc.spec.ts @@ -1,11 +1,11 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { ForbiddenException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { Permission, SchoolDO, User, UserLoginMigrationDO } from '@shared/domain'; -import { schoolDOFactory, setupEntities, userFactory, userLoginMigrationDOFactory } from '@shared/testing'; +import { Permission, LegacySchoolDo, User, UserLoginMigrationDO } from '@shared/domain'; +import { legacySchoolDoFactory, setupEntities, userFactory, userLoginMigrationDOFactory } from '@shared/testing'; import { Logger } from '@src/core/logger'; import { AuthorizationContextBuilder, AuthorizationService } from '@src/modules/authorization'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { UserLoginMigrationGracePeriodExpiredLoggableException, UserLoginMigrationNotFoundLoggableException, @@ -19,7 +19,7 @@ describe('RestartUserLoginMigrationUc', () => { let userLoginMigrationService: DeepMocked; let authorizationService: DeepMocked; - let schoolService: DeepMocked; + let schoolService: DeepMocked; beforeAll(async () => { module = await Test.createTestingModule({ @@ -34,8 +34,8 @@ describe('RestartUserLoginMigrationUc', () => { useValue: createMock(), }, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: Logger, @@ -47,7 +47,7 @@ describe('RestartUserLoginMigrationUc', () => { uc = module.get(RestartUserLoginMigrationUc); userLoginMigrationService = module.get(UserLoginMigrationService); authorizationService = module.get(AuthorizationService); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); await setupEntities(); }); @@ -70,7 +70,7 @@ describe('RestartUserLoginMigrationUc', () => { const user: User = userFactory.buildWithId(); - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); schoolService.getSchoolById.mockResolvedValueOnce(school); @@ -115,7 +115,7 @@ describe('RestartUserLoginMigrationUc', () => { const user: User = userFactory.buildWithId(); - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); schoolService.getSchoolById.mockResolvedValueOnce(school); @@ -157,7 +157,7 @@ describe('RestartUserLoginMigrationUc', () => { const setup = () => { const user: User = userFactory.buildWithId(); - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); schoolService.getSchoolById.mockResolvedValueOnce(school); @@ -179,7 +179,7 @@ describe('RestartUserLoginMigrationUc', () => { const setup = () => { const user: User = userFactory.buildWithId(); - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); schoolService.getSchoolById.mockResolvedValueOnce(school); @@ -207,7 +207,7 @@ describe('RestartUserLoginMigrationUc', () => { const user: User = userFactory.buildWithId(); - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); schoolService.getSchoolById.mockResolvedValueOnce(school); diff --git a/apps/server/src/modules/user-login-migration/uc/restart-user-login-migration.uc.ts b/apps/server/src/modules/user-login-migration/uc/restart-user-login-migration.uc.ts index a515755830a..514973db20b 100644 --- a/apps/server/src/modules/user-login-migration/uc/restart-user-login-migration.uc.ts +++ b/apps/server/src/modules/user-login-migration/uc/restart-user-login-migration.uc.ts @@ -1,8 +1,8 @@ import { Injectable } from '@nestjs/common/decorators/core/injectable.decorator'; -import { Permission, SchoolDO, User, UserLoginMigrationDO } from '@shared/domain'; +import { Permission, LegacySchoolDo, User, UserLoginMigrationDO } from '@shared/domain'; import { Logger } from '@src/core/logger'; import { AuthorizationContext, AuthorizationContextBuilder, AuthorizationService } from '@src/modules/authorization'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { UserLoginMigrationGracePeriodExpiredLoggableException, UserLoginMigrationNotFoundLoggableException, @@ -15,7 +15,7 @@ export class RestartUserLoginMigrationUc { constructor( private readonly userLoginMigrationService: UserLoginMigrationService, private readonly authorizationService: AuthorizationService, - private readonly schoolService: SchoolService, + private readonly schoolService: LegacySchoolService, private readonly logger: Logger ) { this.logger.setContext(RestartUserLoginMigrationUc.name); @@ -48,7 +48,7 @@ export class RestartUserLoginMigrationUc { async checkPermission(userId: string, schoolId: string): Promise { const user: User = await this.authorizationService.getUserWithPermissions(userId); - const school: SchoolDO = await this.schoolService.getSchoolById(schoolId); + const school: LegacySchoolDo = await this.schoolService.getSchoolById(schoolId); const context: AuthorizationContext = AuthorizationContextBuilder.write([Permission.USER_LOGIN_MIGRATION_ADMIN]); this.authorizationService.checkPermission(user, school, context); diff --git a/apps/server/src/modules/user-login-migration/uc/start-user-login-migration.uc.spec.ts b/apps/server/src/modules/user-login-migration/uc/start-user-login-migration.uc.spec.ts index 24207e57370..e4c7510e684 100644 --- a/apps/server/src/modules/user-login-migration/uc/start-user-login-migration.uc.spec.ts +++ b/apps/server/src/modules/user-login-migration/uc/start-user-login-migration.uc.spec.ts @@ -1,11 +1,11 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { ForbiddenException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { Permission, SchoolDO, User, UserLoginMigrationDO } from '@shared/domain'; -import { schoolDOFactory, setupEntities, userFactory, userLoginMigrationDOFactory } from '@shared/testing'; +import { Permission, LegacySchoolDo, User, UserLoginMigrationDO } from '@shared/domain'; +import { legacySchoolDoFactory, setupEntities, userFactory, userLoginMigrationDOFactory } from '@shared/testing'; import { Logger } from '@src/core/logger'; import { AuthorizationContextBuilder, AuthorizationService } from '@src/modules/authorization'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { SchoolNumberMissingLoggableException, UserLoginMigrationAlreadyClosedLoggableException } from '../error'; import { UserLoginMigrationService } from '../service'; import { StartUserLoginMigrationUc } from './start-user-login-migration.uc'; @@ -16,7 +16,7 @@ describe('StartUserLoginMigrationUc', () => { let userLoginMigrationService: DeepMocked; let authorizationService: DeepMocked; - let schoolService: DeepMocked; + let schoolService: DeepMocked; beforeAll(async () => { module = await Test.createTestingModule({ @@ -31,8 +31,8 @@ describe('StartUserLoginMigrationUc', () => { useValue: createMock(), }, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: Logger, @@ -44,7 +44,7 @@ describe('StartUserLoginMigrationUc', () => { uc = module.get(StartUserLoginMigrationUc); userLoginMigrationService = module.get(UserLoginMigrationService); authorizationService = module.get(AuthorizationService); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); await setupEntities(); }); @@ -64,7 +64,7 @@ describe('StartUserLoginMigrationUc', () => { const user: User = userFactory.buildWithId(); - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); schoolService.getSchoolById.mockResolvedValueOnce(school); @@ -109,7 +109,7 @@ describe('StartUserLoginMigrationUc', () => { const user: User = userFactory.buildWithId(); - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); schoolService.getSchoolById.mockResolvedValueOnce(school); @@ -139,7 +139,7 @@ describe('StartUserLoginMigrationUc', () => { const setup = () => { const user: User = userFactory.buildWithId(); - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); schoolService.getSchoolById.mockResolvedValueOnce(school); @@ -161,7 +161,7 @@ describe('StartUserLoginMigrationUc', () => { const setup = () => { const user: User = userFactory.buildWithId(); - const school: SchoolDO = schoolDOFactory.buildWithId({ officialSchoolNumber: undefined }); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ officialSchoolNumber: undefined }); authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); schoolService.getSchoolById.mockResolvedValueOnce(school); @@ -184,7 +184,7 @@ describe('StartUserLoginMigrationUc', () => { const user: User = userFactory.buildWithId(); - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); schoolService.getSchoolById.mockResolvedValueOnce(school); diff --git a/apps/server/src/modules/user-login-migration/uc/start-user-login-migration.uc.ts b/apps/server/src/modules/user-login-migration/uc/start-user-login-migration.uc.ts index d97fe1d0ff8..8eefd9a85ee 100644 --- a/apps/server/src/modules/user-login-migration/uc/start-user-login-migration.uc.ts +++ b/apps/server/src/modules/user-login-migration/uc/start-user-login-migration.uc.ts @@ -1,8 +1,8 @@ import { Injectable } from '@nestjs/common/decorators/core/injectable.decorator'; -import { Permission, SchoolDO, User, UserLoginMigrationDO } from '@shared/domain'; +import { Permission, LegacySchoolDo, User, UserLoginMigrationDO } from '@shared/domain'; import { Logger } from '@src/core/logger'; import { AuthorizationContext, AuthorizationContextBuilder, AuthorizationService } from '@src/modules/authorization'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { SchoolNumberMissingLoggableException, UserLoginMigrationAlreadyClosedLoggableException } from '../error'; import { UserLoginMigrationStartLoggable } from '../loggable'; import { UserLoginMigrationService } from '../service'; @@ -12,7 +12,7 @@ export class StartUserLoginMigrationUc { constructor( private readonly userLoginMigrationService: UserLoginMigrationService, private readonly authorizationService: AuthorizationService, - private readonly schoolService: SchoolService, + private readonly schoolService: LegacySchoolService, private readonly logger: Logger ) { this.logger.setContext(StartUserLoginMigrationUc.name); @@ -43,7 +43,7 @@ export class StartUserLoginMigrationUc { async checkPreconditions(userId: string, schoolId: string): Promise { const user: User = await this.authorizationService.getUserWithPermissions(userId); - const school: SchoolDO = await this.schoolService.getSchoolById(schoolId); + const school: LegacySchoolDo = await this.schoolService.getSchoolById(schoolId); const context: AuthorizationContext = AuthorizationContextBuilder.write([Permission.USER_LOGIN_MIGRATION_ADMIN]); this.authorizationService.checkPermission(user, school, context); diff --git a/apps/server/src/modules/user-login-migration/uc/toggle-user-login-migration.uc.spec.ts b/apps/server/src/modules/user-login-migration/uc/toggle-user-login-migration.uc.spec.ts index 99cd16eeeba..cd97ad1e4ef 100644 --- a/apps/server/src/modules/user-login-migration/uc/toggle-user-login-migration.uc.spec.ts +++ b/apps/server/src/modules/user-login-migration/uc/toggle-user-login-migration.uc.spec.ts @@ -1,11 +1,11 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { ForbiddenException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { Permission, SchoolDO, User, UserLoginMigrationDO } from '@shared/domain'; -import { schoolDOFactory, setupEntities, userFactory, userLoginMigrationDOFactory } from '@shared/testing'; +import { Permission, LegacySchoolDo, User, UserLoginMigrationDO } from '@shared/domain'; +import { legacySchoolDoFactory, setupEntities, userFactory, userLoginMigrationDOFactory } from '@shared/testing'; import { Logger } from '@src/core/logger'; import { AuthorizationContextBuilder, AuthorizationService } from '@src/modules/authorization'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { UserLoginMigrationAlreadyClosedLoggableException, UserLoginMigrationGracePeriodExpiredLoggableException, @@ -20,7 +20,7 @@ describe('ToggleUserLoginMigrationUc', () => { let userLoginMigrationService: DeepMocked; let authorizationService: DeepMocked; - let schoolService: DeepMocked; + let schoolService: DeepMocked; beforeAll(async () => { module = await Test.createTestingModule({ @@ -35,8 +35,8 @@ describe('ToggleUserLoginMigrationUc', () => { useValue: createMock(), }, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: Logger, @@ -48,7 +48,7 @@ describe('ToggleUserLoginMigrationUc', () => { uc = module.get(ToggleUserLoginMigrationUc); userLoginMigrationService = module.get(UserLoginMigrationService); authorizationService = module.get(AuthorizationService); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); await setupEntities(); }); @@ -71,7 +71,7 @@ describe('ToggleUserLoginMigrationUc', () => { const user: User = userFactory.buildWithId(); - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); schoolService.getSchoolById.mockResolvedValueOnce(school); @@ -119,7 +119,7 @@ describe('ToggleUserLoginMigrationUc', () => { const user: User = userFactory.buildWithId(); - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); schoolService.getSchoolById.mockResolvedValueOnce(school); @@ -162,7 +162,7 @@ describe('ToggleUserLoginMigrationUc', () => { const setup = () => { const user: User = userFactory.buildWithId(); - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); schoolService.getSchoolById.mockResolvedValueOnce(school); @@ -184,7 +184,7 @@ describe('ToggleUserLoginMigrationUc', () => { const setup = () => { const user: User = userFactory.buildWithId(); - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); schoolService.getSchoolById.mockResolvedValueOnce(school); @@ -212,7 +212,7 @@ describe('ToggleUserLoginMigrationUc', () => { const user: User = userFactory.buildWithId(); - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); schoolService.getSchoolById.mockResolvedValueOnce(school); @@ -236,7 +236,7 @@ describe('ToggleUserLoginMigrationUc', () => { const user: User = userFactory.buildWithId(); - const school: SchoolDO = schoolDOFactory.buildWithId(); + const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); schoolService.getSchoolById.mockResolvedValueOnce(school); diff --git a/apps/server/src/modules/user-login-migration/uc/toggle-user-login-migration.uc.ts b/apps/server/src/modules/user-login-migration/uc/toggle-user-login-migration.uc.ts index d54db5c3ff1..d07578e7b23 100644 --- a/apps/server/src/modules/user-login-migration/uc/toggle-user-login-migration.uc.ts +++ b/apps/server/src/modules/user-login-migration/uc/toggle-user-login-migration.uc.ts @@ -1,8 +1,8 @@ import { Injectable } from '@nestjs/common'; -import { Permission, SchoolDO, User, UserLoginMigrationDO } from '@shared/domain'; +import { Permission, LegacySchoolDo, User, UserLoginMigrationDO } from '@shared/domain'; import { Logger } from '@src/core/logger'; import { AuthorizationContext, AuthorizationContextBuilder, AuthorizationService } from '@src/modules/authorization'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { UserLoginMigrationAlreadyClosedLoggableException, UserLoginMigrationGracePeriodExpiredLoggableException, @@ -16,7 +16,7 @@ export class ToggleUserLoginMigrationUc { constructor( private readonly userLoginMigrationService: UserLoginMigrationService, private readonly authorizationService: AuthorizationService, - private readonly schoolService: SchoolService, + private readonly schoolService: LegacySchoolService, private readonly logger: Logger ) {} @@ -50,7 +50,7 @@ export class ToggleUserLoginMigrationUc { async checkPermission(userId: string, schoolId: string): Promise { const user: User = await this.authorizationService.getUserWithPermissions(userId); - const school: SchoolDO = await this.schoolService.getSchoolById(schoolId); + const school: LegacySchoolDo = await this.schoolService.getSchoolById(schoolId); const context: AuthorizationContext = AuthorizationContextBuilder.write([Permission.USER_LOGIN_MIGRATION_ADMIN]); this.authorizationService.checkPermission(user, school, context); diff --git a/apps/server/src/modules/user-login-migration/uc/user-login-migration.uc.spec.ts b/apps/server/src/modules/user-login-migration/uc/user-login-migration.uc.spec.ts index 2ca93a14c1f..3ac2aec3b4e 100644 --- a/apps/server/src/modules/user-login-migration/uc/user-login-migration.uc.spec.ts +++ b/apps/server/src/modules/user-login-migration/uc/user-login-migration.uc.spec.ts @@ -2,10 +2,10 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { ForbiddenException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { NotFoundLoggableException } from '@shared/common/loggable-exception'; -import { Page, Permission, SchoolDO, System, User, UserLoginMigrationDO } from '@shared/domain'; +import { Page, Permission, LegacySchoolDo, System, User, UserLoginMigrationDO } from '@shared/domain'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; import { - schoolDOFactory, + legacySchoolDoFactory, setupEntities, systemFactory, userFactory, @@ -18,7 +18,7 @@ import { OAuthTokenDto } from '@src/modules/oauth'; import { OAuthService } from '@src/modules/oauth/service/oauth.service'; import { ProvisioningService } from '@src/modules/provisioning'; import { ExternalSchoolDto, ExternalUserDto, OauthDataDto, ProvisioningSystemDto } from '@src/modules/provisioning/dto'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { Oauth2MigrationParams } from '../controller/dto/oauth2-migration.params'; import { OAuthMigrationError, SchoolMigrationError, UserLoginMigrationError } from '../error'; import { PageTypes } from '../interface/page-types.enum'; @@ -74,8 +74,8 @@ describe('UserLoginMigrationUc', () => { useValue: createMock(), }, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: LegacyLogger, @@ -304,7 +304,7 @@ describe('UserLoginMigrationUc', () => { .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.SANIS }); - const schoolDO: SchoolDO = schoolDOFactory.buildWithId({ + const schoolDO: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: [sourceSystem.id], officialSchoolNumber: 'officialSchoolNumber', externalId: 'oldSchoolExternalId', @@ -419,7 +419,7 @@ describe('UserLoginMigrationUc', () => { .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.SANIS }); - const schoolDO: SchoolDO = schoolDOFactory.buildWithId({ + const schoolDO: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: [sourceSystem.id], officialSchoolNumber: 'officialSchoolNumber', externalId: 'oldSchoolExternalId', @@ -483,7 +483,7 @@ describe('UserLoginMigrationUc', () => { .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.SANIS }); - const schoolDO: SchoolDO = schoolDOFactory.buildWithId({ + const schoolDO: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: [sourceSystem.id], officialSchoolNumber: 'officialSchoolNumber', externalId: 'oldSchoolExternalId', @@ -619,7 +619,7 @@ describe('UserLoginMigrationUc', () => { .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.SANIS }); - const schoolDO: SchoolDO = schoolDOFactory.buildWithId({ + const schoolDO: LegacySchoolDo = legacySchoolDoFactory.buildWithId({ systems: [sourceSystem.id], officialSchoolNumber: 'officialSchoolNumber', externalId: 'oldSchoolExternalId', diff --git a/apps/server/src/modules/user-login-migration/uc/user-login-migration.uc.ts b/apps/server/src/modules/user-login-migration/uc/user-login-migration.uc.ts index 121e236cea8..bfbce03c9ca 100644 --- a/apps/server/src/modules/user-login-migration/uc/user-login-migration.uc.ts +++ b/apps/server/src/modules/user-login-migration/uc/user-login-migration.uc.ts @@ -1,6 +1,6 @@ import { ForbiddenException, Injectable } from '@nestjs/common'; import { NotFoundLoggableException } from '@shared/common/loggable-exception'; -import { EntityId, Page, Permission, SchoolDO, User, UserLoginMigrationDO } from '@shared/domain'; +import { EntityId, Page, Permission, LegacySchoolDo, User, UserLoginMigrationDO } from '@shared/domain'; import { LegacyLogger } from '@src/core/logger'; import { AuthenticationService } from '@src/modules/authentication/services/authentication.service'; import { Action, AuthorizationService } from '@src/modules/authorization'; @@ -95,7 +95,7 @@ export class UserLoginMigrationUc { this.logMigrationInformation(currentUserId, undefined, data, targetSystemId); if (data.externalSchool) { - let schoolToMigrate: SchoolDO | null; + let schoolToMigrate: LegacySchoolDo | null; // TODO: N21-820 after fully switching to the new client login flow, try/catch will be obsolete and schoolToMigrate should throw correct errors try { schoolToMigrate = await this.schoolMigrationService.schoolToMigrate( @@ -157,7 +157,7 @@ export class UserLoginMigrationUc { text?: string, oauthData?: OauthDataDto, targetSystemId?: string, - school?: SchoolDO + school?: LegacySchoolDo ) { let message = `MIGRATION (userId: ${userId}): ${text ?? ''}`; if (!school && oauthData) { diff --git a/apps/server/src/modules/user-login-migration/user-login-migration-api.module.ts b/apps/server/src/modules/user-login-migration/user-login-migration-api.module.ts index 5b85a235aab..4556103658d 100644 --- a/apps/server/src/modules/user-login-migration/user-login-migration-api.module.ts +++ b/apps/server/src/modules/user-login-migration/user-login-migration-api.module.ts @@ -4,7 +4,7 @@ import { AuthenticationModule } from '@src/modules/authentication/authentication import { AuthorizationModule } from '@src/modules/authorization'; import { OauthModule } from '@src/modules/oauth'; import { ProvisioningModule } from '@src/modules/provisioning'; -import { SchoolModule } from '@src/modules/school'; +import { LegacySchoolModule } from '@src/modules/legacy-school'; import { UserLoginMigrationController } from './controller/user-login-migration.controller'; import { UserMigrationController } from './controller/user-migration.controller'; import { PageContentMapper } from './mapper'; @@ -25,7 +25,7 @@ import { UserLoginMigrationModule } from './user-login-migration.module'; AuthenticationModule, AuthorizationModule, LoggerModule, - SchoolModule, + LegacySchoolModule, ], providers: [ UserLoginMigrationUc, diff --git a/apps/server/src/modules/user-login-migration/user-login-migration.module.ts b/apps/server/src/modules/user-login-migration/user-login-migration.module.ts index c18274f9d69..40e965a4df3 100644 --- a/apps/server/src/modules/user-login-migration/user-login-migration.module.ts +++ b/apps/server/src/modules/user-login-migration/user-login-migration.module.ts @@ -2,7 +2,7 @@ import { Module } from '@nestjs/common'; import { UserLoginMigrationRepo } from '@shared/repo'; import { LoggerModule } from '@src/core/logger'; import { AccountModule } from '@src/modules/account'; -import { SchoolModule } from '@src/modules/school'; +import { LegacySchoolModule } from '@src/modules/legacy-school'; import { SystemModule } from '@src/modules/system'; import { UserModule } from '@src/modules/user'; import { @@ -14,7 +14,7 @@ import { } from './service'; @Module({ - imports: [UserModule, SchoolModule, LoggerModule, AccountModule, SystemModule], + imports: [UserModule, LegacySchoolModule, LoggerModule, AccountModule, SystemModule], providers: [ UserMigrationService, SchoolMigrationService, diff --git a/apps/server/src/modules/user/user.module.ts b/apps/server/src/modules/user/user.module.ts index 6d1dfde6fef..8b462c8ca20 100644 --- a/apps/server/src/modules/user/user.module.ts +++ b/apps/server/src/modules/user/user.module.ts @@ -4,11 +4,11 @@ import { UserDORepo } from '@shared/repo/user/user-do.repo'; import { LoggerModule } from '@src/core/logger'; import { AccountModule } from '@src/modules/account'; import { RoleModule } from '@src/modules/role/role.module'; -import { SchoolModule } from '@src/modules/school/school.module'; +import { LegacySchoolModule } from '@src/modules/legacy-school'; import { UserService } from './service/user.service'; @Module({ - imports: [SchoolModule, RoleModule, AccountModule, LoggerModule], + imports: [LegacySchoolModule, RoleModule, AccountModule, LoggerModule], providers: [UserRepo, UserDORepo, UserService], exports: [UserService, UserRepo], }) diff --git a/apps/server/src/modules/video-conference/service/video-conference.service.spec.ts b/apps/server/src/modules/video-conference/service/video-conference.service.spec.ts index 221ee21943e..4da2b8278ae 100644 --- a/apps/server/src/modules/video-conference/service/video-conference.service.spec.ts +++ b/apps/server/src/modules/video-conference/service/video-conference.service.spec.ts @@ -19,7 +19,7 @@ import { AuthorizationContextBuilder, AuthorizationService, } from '@src/modules/authorization'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { UserService } from '@src/modules/user'; import { courseFactory, roleFactory, setupEntities, userDoFactory } from '@shared/testing'; import { videoConferenceDOFactory } from '@shared/testing/factory/video-conference.do.factory'; @@ -39,7 +39,7 @@ describe('VideoConferenceService', () => { let courseService: DeepMocked; let calendarService: DeepMocked; let authorizationService: DeepMocked; - let schoolService: DeepMocked; + let schoolService: DeepMocked; let teamsRepo: DeepMocked; let userService: DeepMocked; let videoConferenceRepo: DeepMocked; @@ -68,8 +68,8 @@ describe('VideoConferenceService', () => { useValue: createMock(), }, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, { provide: TeamsRepo, @@ -90,7 +90,7 @@ describe('VideoConferenceService', () => { courseService = module.get(CourseService); calendarService = module.get(CalendarService); authorizationService = module.get(AuthorizationService); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); teamsRepo = module.get(TeamsRepo); userService = module.get(UserService); videoConferenceRepo = module.get(VideoConferenceRepo); diff --git a/apps/server/src/modules/video-conference/service/video-conference.service.ts b/apps/server/src/modules/video-conference/service/video-conference.service.ts index c6716661473..e0de64e6cb3 100644 --- a/apps/server/src/modules/video-conference/service/video-conference.service.ts +++ b/apps/server/src/modules/video-conference/service/video-conference.service.ts @@ -22,7 +22,7 @@ import { AuthorizationService, } from '@src/modules/authorization'; import { CourseService } from '@src/modules/learnroom/service'; -import { SchoolService } from '@src/modules/school'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { UserService } from '@src/modules/user'; import { BBBRole } from '../bbb'; import { ErrorStatus } from '../error/error-status.enum'; @@ -37,7 +37,7 @@ export class VideoConferenceService { private readonly courseService: CourseService, private readonly calendarService: CalendarService, private readonly authorizationService: AuthorizationService, - private readonly schoolService: SchoolService, + private readonly schoolService: LegacySchoolService, private readonly teamsRepo: TeamsRepo, private readonly userService: UserService, private readonly videoConferenceRepo: VideoConferenceRepo diff --git a/apps/server/src/modules/video-conference/uc/video-conference-deprecated.uc.spec.ts b/apps/server/src/modules/video-conference/uc/video-conference-deprecated.uc.spec.ts index 3d9c9a12560..3680c4519da 100644 --- a/apps/server/src/modules/video-conference/uc/video-conference-deprecated.uc.spec.ts +++ b/apps/server/src/modules/video-conference/uc/video-conference-deprecated.uc.spec.ts @@ -19,7 +19,7 @@ import { CalendarEventDto } from '@shared/infra/calendar/dto/calendar-event.dto' import { TeamsRepo, VideoConferenceRepo } from '@shared/repo'; import { roleFactory, setupEntities, userDoFactory } from '@shared/testing'; import { teamFactory } from '@shared/testing/factory/team.factory'; -import { AuthorizationService, SchoolService, UserService } from '@src/modules'; +import { AuthorizationService, LegacySchoolService, UserService } from '@src/modules'; import { ICurrentUser } from '@src/modules/authentication'; import { CourseService } from '@src/modules/learnroom/service'; import { IScopeInfo, VideoConference, VideoConferenceJoin, VideoConferenceState } from './dto'; @@ -69,7 +69,7 @@ describe('VideoConferenceUc', () => { let courseService: DeepMocked; let userService: DeepMocked; let calendarService: DeepMocked; - let schoolService: DeepMocked; + let schoolService: DeepMocked; const hostUrl = 'https://localhost:4000'; const course: Course = { id: 'courseId', name: 'courseName' } as Course; @@ -142,13 +142,13 @@ describe('VideoConferenceUc', () => { useValue: createMock(), }, { - provide: SchoolService, - useValue: createMock(), + provide: LegacySchoolService, + useValue: createMock(), }, ], }).compile(); useCase = module.get(VideoConferenceDeprecatedUcSpec); - schoolService = module.get(SchoolService); + schoolService = module.get(LegacySchoolService); authorizationService = module.get(AuthorizationService); courseService = module.get(CourseService); calendarService = module.get(CalendarService); diff --git a/apps/server/src/modules/video-conference/uc/video-conference-deprecated.uc.ts b/apps/server/src/modules/video-conference/uc/video-conference-deprecated.uc.ts index 4389879cf08..7bce5b2f5a4 100644 --- a/apps/server/src/modules/video-conference/uc/video-conference-deprecated.uc.ts +++ b/apps/server/src/modules/video-conference/uc/video-conference-deprecated.uc.ts @@ -24,10 +24,9 @@ import { AuthorizationContextBuilder, AuthorizationService, } from '@src/modules/authorization'; -import { SchoolService } from '@src/modules/school/service/school.service'; import { CourseService } from '@src/modules/learnroom/service'; +import { LegacySchoolService } from '@src/modules/legacy-school'; import { UserService } from '@src/modules/user'; -import { IScopeInfo, VideoConference, VideoConferenceInfo, VideoConferenceJoin, VideoConferenceState } from './dto'; import { BBBBaseMeetingConfig, BBBBaseResponse, @@ -40,8 +39,9 @@ import { BBBService, GuestPolicy, } from '../bbb'; -import { defaultVideoConferenceOptions, VideoConferenceOptions } from '../interface'; import { ErrorStatus } from '../error/error-status.enum'; +import { defaultVideoConferenceOptions, VideoConferenceOptions } from '../interface'; +import { IScopeInfo, VideoConference, VideoConferenceInfo, VideoConferenceJoin, VideoConferenceState } from './dto'; const PermissionMapping = { [BBBRole.MODERATOR]: Permission.START_MEETING, @@ -68,7 +68,7 @@ export class VideoConferenceDeprecatedUc { private readonly courseService: CourseService, private readonly userService: UserService, private readonly calendarService: CalendarService, - private readonly schoolService: SchoolService + private readonly schoolService: LegacySchoolService ) { this.hostURL = Configuration.get('HOST') as string; } diff --git a/apps/server/src/modules/video-conference/video-conference.module.ts b/apps/server/src/modules/video-conference/video-conference.module.ts index 21ea09201b9..70a999437c0 100644 --- a/apps/server/src/modules/video-conference/video-conference.module.ts +++ b/apps/server/src/modules/video-conference/video-conference.module.ts @@ -4,7 +4,7 @@ import { CalendarModule } from '@shared/infra/calendar'; import { VideoConferenceRepo } from '@shared/repo/videoconference/video-conference.repo'; import { AuthorizationModule } from '@src/modules/authorization'; import { TeamsRepo } from '@shared/repo'; -import { SchoolModule } from '@src/modules/school/school.module'; +import { LegacySchoolModule } from '@src/modules/legacy-school'; import { LoggerModule } from '@src/core/logger'; import { ConverterUtil } from '@shared/common'; import { UserModule } from '@src/modules/user'; @@ -21,7 +21,7 @@ import { LearnroomModule } from '../learnroom'; AuthorizationModule, CalendarModule, HttpModule, - SchoolModule, + LegacySchoolModule, LoggerModule, UserModule, LearnroomModule, diff --git a/apps/server/src/shared/domain/domainobject/index.ts b/apps/server/src/shared/domain/domainobject/index.ts index b8c862ad23b..46e88212097 100644 --- a/apps/server/src/shared/domain/domainobject/index.ts +++ b/apps/server/src/shared/domain/domainobject/index.ts @@ -3,7 +3,7 @@ export * from './pseudonym.do'; export * from './video-conference.do'; export * from './board'; export * from './user-login-migration.do'; -export * from './school.do'; +export * from './legacy-school.do'; export * from './user.do'; export * from './page'; export * from './role-reference'; diff --git a/apps/server/src/shared/domain/domainobject/school.do.ts b/apps/server/src/shared/domain/domainobject/legacy-school.do.ts similarity index 88% rename from apps/server/src/shared/domain/domainobject/school.do.ts rename to apps/server/src/shared/domain/domainobject/legacy-school.do.ts index 6ea0cffb7a4..5ac496a04c4 100644 --- a/apps/server/src/shared/domain/domainobject/school.do.ts +++ b/apps/server/src/shared/domain/domainobject/legacy-school.do.ts @@ -2,7 +2,10 @@ import { FederalState, SchoolFeatures, SchoolYear } from '@shared/domain/entity' import { EntityId } from '@shared/domain/types'; import { BaseDO } from './base.do'; -export class SchoolDO extends BaseDO { +/** + * @deprecated because it extends the deprecated BaseDO. + */ +export class LegacySchoolDo extends BaseDO { externalId?: string; inMaintenanceSince?: Date; @@ -27,7 +30,7 @@ export class SchoolDO extends BaseDO { // TODO: N21-990 Refactoring: Create domain objects for schoolYear and federalState federalState: FederalState; - constructor(params: SchoolDO) { + constructor(params: LegacySchoolDo) { super(); this.id = params.id; this.externalId = params.externalId; diff --git a/apps/server/src/shared/domain/rules/index.ts b/apps/server/src/shared/domain/rules/index.ts index ea72f8b4d0a..888b2ee8501 100644 --- a/apps/server/src/shared/domain/rules/index.ts +++ b/apps/server/src/shared/domain/rules/index.ts @@ -4,7 +4,7 @@ import { CourseGroupRule } from './course-group.rule'; import { CourseRule } from './course.rule'; import { LessonRule } from './lesson.rule'; import { SchoolExternalToolRule } from './school-external-tool.rule'; -import { SchoolRule } from './school.rule'; +import { LegacySchoolRule } from './legacy-school.rule'; import { SubmissionRule } from './submission.rule'; import { TaskRule } from './task.rule'; import { TeamRule } from './team.rule'; @@ -16,7 +16,7 @@ export * from './course-group.rule'; export * from './course.rule'; export * from './lesson.rule'; export * from './school-external-tool.rule'; -export * from './school.rule'; +export * from './legacy-school.rule'; export * from './submission.rule'; export * from './task.rule'; export * from './team.rule'; @@ -27,7 +27,7 @@ export const ALL_RULES = [ LessonRule, CourseRule, CourseGroupRule, - SchoolRule, + LegacySchoolRule, SubmissionRule, TaskRule, TeamRule, diff --git a/apps/server/src/shared/domain/rules/legacy-school.rule.spec.ts b/apps/server/src/shared/domain/rules/legacy-school.rule.spec.ts new file mode 100644 index 00000000000..c547f772de5 --- /dev/null +++ b/apps/server/src/shared/domain/rules/legacy-school.rule.spec.ts @@ -0,0 +1,71 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { Permission } from '@shared/domain/interface'; +import { roleFactory, legacySchoolDoFactory, setupEntities, userFactory } from '@shared/testing'; +import { AuthorizationHelper } from '@src/modules/authorization/authorization.helper'; +import { Action } from '@src/modules/authorization/types'; +import { ObjectID } from 'bson'; +import { LegacySchoolRule } from './legacy-school.rule'; + +describe('LegacySchoolRule', () => { + let service: LegacySchoolRule; + let authorizationHelper: AuthorizationHelper; + const permissionA = 'a' as Permission; + const permissionB = 'b' as Permission; + const permissionC = 'c' as Permission; + + beforeAll(async () => { + await setupEntities(); + + const module: TestingModule = await Test.createTestingModule({ + providers: [AuthorizationHelper, LegacySchoolRule], + }).compile(); + + service = await module.get(LegacySchoolRule); + authorizationHelper = await module.get(AuthorizationHelper); + }); + + const setupSchoolAndUser = () => { + const school = legacySchoolDoFactory.build({ id: new ObjectID().toString() }); + const role = roleFactory.build({ permissions: [permissionA, permissionB] }); + const user = userFactory.build({ + roles: [role], + school: { id: school.id }, + }); + + return { school, user }; + }; + + it('should call hasAllPermissions on AuthorizationHelper', () => { + const { school, user } = setupSchoolAndUser(); + const spy = jest.spyOn(authorizationHelper, 'hasAllPermissions'); + + service.hasPermission(user, school, { action: Action.read, requiredPermissions: [] }); + + expect(spy).toBeCalledWith(user, []); + }); + + it('should return "true" if user in scope', () => { + const { school, user } = setupSchoolAndUser(); + + const res = service.hasPermission(user, school, { action: Action.read, requiredPermissions: [] }); + + expect(res).toBe(true); + }); + + it('should return "false" if user has not permission', () => { + const { school, user } = setupSchoolAndUser(); + + const res = service.hasPermission(user, school, { action: Action.read, requiredPermissions: [permissionC] }); + + expect(res).toBe(false); + }); + + it('should return "false" if user has not same school', () => { + const { user } = setupSchoolAndUser(); + const school = legacySchoolDoFactory.build(); + + const res = service.hasPermission(user, school, { action: Action.read, requiredPermissions: [permissionA] }); + + expect(res).toBe(false); + }); +}); diff --git a/apps/server/src/shared/domain/rules/legacy-school.rule.ts b/apps/server/src/shared/domain/rules/legacy-school.rule.ts new file mode 100644 index 00000000000..5068d327c35 --- /dev/null +++ b/apps/server/src/shared/domain/rules/legacy-school.rule.ts @@ -0,0 +1,27 @@ +import { Injectable } from '@nestjs/common'; +import { BaseDO, LegacySchoolDo } from '@shared/domain'; +import { User } from '@shared/domain/entity'; +import { AuthorizationHelper } from '@src/modules/authorization/authorization.helper'; +import { AuthorizationContext, Rule } from '@src/modules/authorization/types'; +import { AuthorizableObject } from '../domain-object'; + +/** + * @deprecated because it uses the deprecated LegacySchoolDo. + */ +@Injectable() +export class LegacySchoolRule implements Rule { + constructor(private readonly authorizationHelper: AuthorizationHelper) {} + + public isApplicable(user: User, object: AuthorizableObject | BaseDO): boolean { + const isMatched = object instanceof LegacySchoolDo; + + return isMatched; + } + + public hasPermission(user: User, entity: LegacySchoolDo, context: AuthorizationContext): boolean { + const hasPermission = + this.authorizationHelper.hasAllPermissions(user, context.requiredPermissions) && user.school.id === entity.id; + + return hasPermission; + } +} diff --git a/apps/server/src/shared/domain/rules/school.rule.spec.ts b/apps/server/src/shared/domain/rules/school.rule.spec.ts deleted file mode 100644 index 74e017ce4a4..00000000000 --- a/apps/server/src/shared/domain/rules/school.rule.spec.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { Role, School, User } from '@shared/domain/entity'; -import { Permission } from '@shared/domain/interface'; -import { roleFactory, schoolDOFactory, schoolFactory, setupEntities, userFactory } from '@shared/testing'; -import { AuthorizationHelper } from '@src/modules/authorization/authorization.helper'; -import { Action } from '@src/modules/authorization/types'; -import { SchoolRule } from './school.rule'; - -describe('SchoolRule', () => { - let service: SchoolRule; - let authorizationHelper: AuthorizationHelper; - let user: User; - let entity: School | SchoolDO; - let role: Role; - const permissionA = 'a' as Permission; - const permissionB = 'b' as Permission; - const permissionC = 'c' as Permission; - - beforeAll(async () => { - await setupEntities(); - - const module: TestingModule = await Test.createTestingModule({ - providers: [AuthorizationHelper, SchoolRule], - }).compile(); - - service = await module.get(SchoolRule); - authorizationHelper = await module.get(AuthorizationHelper); - }); - - beforeEach(() => { - role = roleFactory.build({ permissions: [permissionA, permissionB] }); - user = userFactory.build({ roles: [role] }); - }); - - it('should call hasAllPermissions on AuthorizationHelper', () => { - entity = schoolFactory.build(); - user = userFactory.build({ roles: [role], school: entity }); - const spy = jest.spyOn(authorizationHelper, 'hasAllPermissions'); - service.hasPermission(user, entity, { action: Action.read, requiredPermissions: [] }); - expect(spy).toBeCalledWith(user, []); - }); - - it('should return "true" if user in scope', () => { - entity = schoolFactory.build(); - user = userFactory.build({ roles: [role], school: entity }); - const res = service.hasPermission(user, entity, { action: Action.read, requiredPermissions: [] }); - expect(res).toBe(true); - }); - - it('should return "false" if user has not permission', () => { - entity = schoolFactory.build(); - user = userFactory.build({ roles: [role], school: entity }); - const res = service.hasPermission(user, entity, { action: Action.read, requiredPermissions: [permissionC] }); - expect(res).toBe(false); - }); - - it('should return "false" if user has not some school', () => { - entity = schoolDOFactory.build({ name: 'testschool', id: 'invalidId' }); - user = userFactory.build({ roles: [role] }); - const res = service.hasPermission(user, entity, { action: Action.read, requiredPermissions: [permissionA] }); - expect(res).toBe(false); - }); -}); diff --git a/apps/server/src/shared/domain/rules/school.rule.ts b/apps/server/src/shared/domain/rules/school.rule.ts deleted file mode 100644 index 358d549885c..00000000000 --- a/apps/server/src/shared/domain/rules/school.rule.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; -import { School, User } from '@shared/domain/entity'; -import { AuthorizationHelper } from '@src/modules/authorization/authorization.helper'; -import { AuthorizationContext, Rule } from '@src/modules/authorization/types'; - -@Injectable() -export class SchoolRule implements Rule { - constructor(private readonly authorizationHelper: AuthorizationHelper) {} - - public isApplicable(user: User, entity: School | SchoolDO): boolean { - const isMatched: boolean = entity instanceof School || entity instanceof SchoolDO; - - return isMatched; - } - - public hasPermission(user: User, entity: School | SchoolDO, context: AuthorizationContext): boolean { - const hasPermission: boolean = - this.authorizationHelper.hasAllPermissions(user, context.requiredPermissions) && user.school.id === entity.id; - - return hasPermission; - } -} diff --git a/apps/server/src/shared/repo/school/index.ts b/apps/server/src/shared/repo/school/index.ts index 89e46f27b72..602b003d013 100644 --- a/apps/server/src/shared/repo/school/index.ts +++ b/apps/server/src/shared/repo/school/index.ts @@ -1 +1 @@ -export * from './school.repo'; +export * from './legacy-school.repo'; diff --git a/apps/server/src/shared/repo/school/school.repo.integration.spec.ts b/apps/server/src/shared/repo/school/legacy-school.repo.integration.spec.ts similarity index 87% rename from apps/server/src/shared/repo/school/school.repo.integration.spec.ts rename to apps/server/src/shared/repo/school/legacy-school.repo.integration.spec.ts index ab4fd5e1f17..5cd81119d20 100644 --- a/apps/server/src/shared/repo/school/school.repo.integration.spec.ts +++ b/apps/server/src/shared/repo/school/legacy-school.repo.integration.spec.ts @@ -5,6 +5,7 @@ import { InternalServerErrorException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ISchoolProperties, + LegacySchoolDo, School, SchoolRolePermission, SchoolRoles, @@ -12,32 +13,34 @@ import { System, UserLoginMigration, } from '@shared/domain'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; import { MongoMemoryDatabaseModule } from '@shared/infra/database'; -import { schoolFactory, systemFactory } from '@shared/testing'; -import { schoolDOFactory } from '@shared/testing/factory/domainobject/school.factory'; -import { schoolYearFactory } from '@shared/testing/factory/schoolyear.factory'; +import { + legacySchoolDoFactory, + schoolFactory, + schoolYearFactory, + systemFactory, + userLoginMigrationFactory, +} from '@shared/testing'; import { LegacyLogger } from '@src/core/logger'; -import { userLoginMigrationFactory } from '@shared/testing/factory/user-login-migration.factory'; -import { SchoolRepo } from '..'; +import { LegacySchoolRepo } from '..'; -describe('SchoolRepo', () => { +describe('LegacySchoolRepo', () => { let module: TestingModule; - let repo: SchoolRepo; + let repo: LegacySchoolRepo; let em: EntityManager; beforeAll(async () => { module = await Test.createTestingModule({ imports: [MongoMemoryDatabaseModule.forRoot()], providers: [ - SchoolRepo, + LegacySchoolRepo, { provide: LegacyLogger, useValue: createMock(), }, ], }).compile(); - repo = module.get(SchoolRepo); + repo = module.get(LegacySchoolRepo); em = module.get(EntityManager); }); @@ -59,7 +62,7 @@ describe('SchoolRepo', () => { describe('save is called', () => { describe('when saving only required fields', () => { function setupDO() { - const domainObject: SchoolDO = schoolDOFactory.build(); + const domainObject: LegacySchoolDo = legacySchoolDoFactory.build(); return { domainObject, }; @@ -70,7 +73,7 @@ describe('SchoolRepo', () => { const { id, ...expected } = domainObject; expected.systems = []; - const result: SchoolDO = await repo.save(domainObject); + const result: LegacySchoolDo = await repo.save(domainObject); expect(result).toMatchObject(expected); expect(result.id).toBeDefined(); @@ -117,7 +120,7 @@ describe('SchoolRepo', () => { await em.persistAndFlush(schoolEntity); - const result: SchoolDO | null = await repo.findByExternalId( + const result: LegacySchoolDo | null = await repo.findByExternalId( schoolEntity.externalId as string, schoolEntity.systems[0].id ); @@ -126,7 +129,7 @@ describe('SchoolRepo', () => { }); it('should return null when no school is found', async () => { - const result: SchoolDO | null = await repo.findByExternalId( + const result: LegacySchoolDo | null = await repo.findByExternalId( new ObjectId().toHexString(), new ObjectId().toHexString() ); @@ -141,13 +144,13 @@ describe('SchoolRepo', () => { await em.persistAndFlush(schoolEntity); - const result: SchoolDO | null = await repo.findBySchoolNumber(schoolEntity.officialSchoolNumber as string); + const result: LegacySchoolDo | null = await repo.findBySchoolNumber(schoolEntity.officialSchoolNumber as string); expect(result?.officialSchoolNumber).toEqual(schoolEntity.officialSchoolNumber); }); it('should return null when no school is found', async () => { - const result: SchoolDO | null = await repo.findBySchoolNumber('fail'); + const result: LegacySchoolDo | null = await repo.findBySchoolNumber('fail'); expect(result).toBeNull(); }); @@ -185,7 +188,7 @@ describe('SchoolRepo', () => { const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.build({ school: schoolEntity }); schoolEntity.userLoginMigration = userLoginMigration; - const schoolDO: SchoolDO = repo.mapEntityToDO(schoolEntity); + const schoolDO: LegacySchoolDo = repo.mapEntityToDO(schoolEntity); expect(schoolDO).toEqual( expect.objectContaining({ @@ -223,7 +226,7 @@ describe('SchoolRepo', () => { await em.persistAndFlush([userLoginMigration, system1, system2]); - const entityDO: SchoolDO = schoolDOFactory.build({ + const entityDO: LegacySchoolDo = legacySchoolDoFactory.build({ systems: [system1.id, system2.id], userLoginMigrationId: userLoginMigration.id, }); @@ -262,7 +265,7 @@ describe('SchoolRepo', () => { describe('when there are no systems', () => { it('should not call the entity manager to get the system object', () => { - const entityDO: SchoolDO = schoolDOFactory.build({ systems: undefined }); + const entityDO: LegacySchoolDo = legacySchoolDoFactory.build({ systems: undefined }); const emGetReferenceSpy = jest.spyOn(em, 'getReference'); repo.mapDOToEntityProperties(entityDO); @@ -273,7 +276,7 @@ describe('SchoolRepo', () => { describe('when there is no userLoginMigration', () => { it('should not call the entity manager to get the user login migration reference', () => { - const entityDO: SchoolDO = schoolDOFactory.build({ userLoginMigrationId: undefined }); + const entityDO: LegacySchoolDo = legacySchoolDoFactory.build({ userLoginMigrationId: undefined }); const emGetReferenceSpy = jest.spyOn(em, 'getReference'); repo.mapDOToEntityProperties(entityDO); diff --git a/apps/server/src/shared/repo/school/school.repo.ts b/apps/server/src/shared/repo/school/legacy-school.repo.ts similarity index 77% rename from apps/server/src/shared/repo/school/school.repo.ts rename to apps/server/src/shared/repo/school/legacy-school.repo.ts index 485c8551dd6..f305d145125 100644 --- a/apps/server/src/shared/repo/school/school.repo.ts +++ b/apps/server/src/shared/repo/school/legacy-school.repo.ts @@ -1,13 +1,15 @@ import { EntityName } from '@mikro-orm/core'; import { EntityManager } from '@mikro-orm/mongodb'; import { Injectable, InternalServerErrorException } from '@nestjs/common'; -import { EntityId, ISchoolProperties, School, System, UserLoginMigration } from '@shared/domain'; -import { SchoolDO } from '@shared/domain/domainobject/school.do'; +import { EntityId, ISchoolProperties, LegacySchoolDo, School, System, UserLoginMigration } from '@shared/domain'; import { LegacyLogger } from '@src/core/logger'; import { BaseDORepo } from '../base.do.repo'; +/** + * @deprecated because it uses the deprecated LegacySchoolDo. + */ @Injectable() -export class SchoolRepo extends BaseDORepo { +export class LegacySchoolRepo extends BaseDORepo { constructor(protected readonly _em: EntityManager, protected readonly logger: LegacyLogger) { super(_em, logger); } @@ -16,20 +18,20 @@ export class SchoolRepo extends BaseDORepo return School; } - async findByExternalId(externalId: string, systemId: string): Promise { + async findByExternalId(externalId: string, systemId: string): Promise { const school: School | null = await this._em.findOne(School, { externalId, systems: systemId }); - const schoolDo: SchoolDO | null = school ? this.mapEntityToDO(school) : null; + const schoolDo: LegacySchoolDo | null = school ? this.mapEntityToDO(school) : null; return schoolDo; } - async findBySchoolNumber(officialSchoolNumber: string): Promise { + async findBySchoolNumber(officialSchoolNumber: string): Promise { const [schools, count] = await this._em.findAndCount(School, { officialSchoolNumber }); if (count > 1) { throw new InternalServerErrorException(`Multiple schools found for officialSchoolNumber ${officialSchoolNumber}`); } - const schoolDo: SchoolDO | null = schools[0] ? this.mapEntityToDO(schools[0]) : null; + const schoolDo: LegacySchoolDo | null = schools[0] ? this.mapEntityToDO(schools[0]) : null; return schoolDo; } @@ -37,8 +39,8 @@ export class SchoolRepo extends BaseDORepo return new School(props); } - mapEntityToDO(entity: School): SchoolDO { - return new SchoolDO({ + mapEntityToDO(entity: School): LegacySchoolDo { + return new LegacySchoolDo({ id: entity.id, externalId: entity.externalId, features: entity.features, @@ -54,7 +56,7 @@ export class SchoolRepo extends BaseDORepo }); } - mapDOToEntityProperties(entityDO: SchoolDO): ISchoolProperties { + mapDOToEntityProperties(entityDO: LegacySchoolDo): ISchoolProperties { return { externalId: entityDO.externalId, features: entityDO.features, diff --git a/apps/server/src/shared/testing/factory/domainobject/index.ts b/apps/server/src/shared/testing/factory/domainobject/index.ts index c1d814b9ca7..8e02c37399c 100644 --- a/apps/server/src/shared/testing/factory/domainobject/index.ts +++ b/apps/server/src/shared/testing/factory/domainobject/index.ts @@ -2,8 +2,8 @@ export * from './board'; export * from './tool'; export * from './groups'; export * from './do-base.factory'; +export * from './legacy-school.factory'; export * from './domain-object.factory'; -export * from './school.factory'; export * from './user-login-migration-do.factory'; export * from './lti-tool.factory'; export * from './pseudonym.factory'; diff --git a/apps/server/src/shared/testing/factory/domainobject/school.factory.ts b/apps/server/src/shared/testing/factory/domainobject/legacy-school.factory.ts similarity index 73% rename from apps/server/src/shared/testing/factory/domainobject/school.factory.ts rename to apps/server/src/shared/testing/factory/domainobject/legacy-school.factory.ts index 3b81247f585..9859721c9a5 100644 --- a/apps/server/src/shared/testing/factory/domainobject/school.factory.ts +++ b/apps/server/src/shared/testing/factory/domainobject/legacy-school.factory.ts @@ -1,11 +1,11 @@ -import { SchoolDO } from '@shared/domain/domainobject/school.do'; +import { LegacySchoolDo } from '@shared/domain'; import { federalStateFactory } from '../federal-state.factory'; import { schoolYearFactory } from '../schoolyear.factory'; import { DoBaseFactory } from './do-base.factory'; -class SchoolFactory extends DoBaseFactory {} +class LegacySchoolFactory extends DoBaseFactory {} -export const schoolDOFactory = SchoolFactory.define(SchoolDO, ({ sequence }) => { +export const legacySchoolDoFactory = LegacySchoolFactory.define(LegacySchoolDo, ({ sequence }) => { return { name: `schoolName-${sequence}`, externalId: '123',