Skip to content

Commit

Permalink
BC-4964 Rename and update existing classes in school module (#4370)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyedwiper authored Sep 1, 2023
1 parent 04646bb commit 1013581
Show file tree
Hide file tree
Showing 81 changed files with 669 additions and 652 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -70,7 +70,7 @@ const jwtModuleOptions: JwtModuleOptions = {
JwtValidationAdapter,
UserRepo,
SystemRepo,
SchoolRepo,
LegacySchoolRepo,
LocalStrategy,
AuthenticationService,
LdapService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,7 +27,7 @@ describe('LdapStrategy', () => {
let strategy: LdapStrategy;

let userRepoMock: DeepMocked<UserRepo>;
let schoolRepoMock: DeepMocked<SchoolRepo>;
let schoolRepoMock: DeepMocked<LegacySchoolRepo>;
let authenticationServiceMock: DeepMocked<AuthenticationService>;
let ldapServiceMock: DeepMocked<LdapService>;
let systemRepo: DeepMocked<SystemRepo>;
Expand All @@ -53,8 +52,8 @@ describe('LdapStrategy', () => {
useValue: createMock<UserRepo>(),
},
{
provide: SchoolRepo,
useValue: createMock<SchoolRepo>(),
provide: LegacySchoolRepo,
useValue: createMock<LegacySchoolRepo>(),
},
{
provide: SystemRepo,
Expand All @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down
11 changes: 5 additions & 6 deletions apps/server/src/modules/authentication/strategy/ldap.strategy.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -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}`);
Expand Down Expand Up @@ -84,7 +83,7 @@ export class LdapStrategy extends PassportStrategy(Strategy, 'ldap') {
}
}

private async loadAccount(username: string, systemId: string, school: SchoolDO): Promise<AccountDto> {
private async loadAccount(username: string, systemId: string, school: LegacySchoolDo): Promise<AccountDto> {
const externalSchoolId = this.checkValue(school.externalId);

let account: AccountDto;
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/modules/authorization/authorization.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
CourseRepo,
LessonRepo,
SchoolExternalToolRepo,
SchoolRepo,
LegacySchoolRepo,
SubmissionRepo,
TaskRepo,
TeamsRepo,
Expand Down Expand Up @@ -35,7 +35,7 @@ import { RuleManager } from './rule-manager';
CourseRepo,
CourseGroupRepo,
TaskRepo,
SchoolRepo,
LegacySchoolRepo,
LessonRepo,
TeamsRepo,
SubmissionRepo,
Expand Down
10 changes: 5 additions & 5 deletions apps/server/src/modules/authorization/reference.loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
CourseRepo,
LessonRepo,
SchoolExternalToolRepo,
SchoolRepo,
LegacySchoolRepo,
SubmissionRepo,
TaskRepo,
TeamsRepo,
Expand All @@ -26,7 +26,7 @@ describe('reference.loader', () => {
let courseRepo: DeepMocked<CourseRepo>;
let courseGroupRepo: DeepMocked<CourseGroupRepo>;
let taskRepo: DeepMocked<TaskRepo>;
let schoolRepo: DeepMocked<SchoolRepo>;
let schoolRepo: DeepMocked<LegacySchoolRepo>;
let lessonRepo: DeepMocked<LessonRepo>;
let teamsRepo: DeepMocked<TeamsRepo>;
let submissionRepo: DeepMocked<SubmissionRepo>;
Expand Down Expand Up @@ -58,8 +58,8 @@ describe('reference.loader', () => {
useValue: createMock<TaskRepo>(),
},
{
provide: SchoolRepo,
useValue: createMock<SchoolRepo>(),
provide: LegacySchoolRepo,
useValue: createMock<LegacySchoolRepo>(),
},
{
provide: LessonRepo,
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/modules/authorization/reference.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
CourseRepo,
LessonRepo,
SchoolExternalToolRepo,
SchoolRepo,
LegacySchoolRepo,
SubmissionRepo,
TaskRepo,
TeamsRepo,
Expand All @@ -21,7 +21,7 @@ type RepoType =
| TaskRepo
| CourseRepo
| UserRepo
| SchoolRepo
| LegacySchoolRepo
| LessonRepo
| TeamsRepo
| CourseGroupRepo
Expand All @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions apps/server/src/modules/authorization/rule-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
CourseRule,
LessonRule,
SchoolExternalToolRule,
SchoolRule,
LegacySchoolRule,
SubmissionRule,
TaskRule,
TeamRule,
Expand All @@ -24,7 +24,7 @@ describe('RuleManager', () => {
let courseRule: DeepMocked<CourseRule>;
let courseGroupRule: DeepMocked<CourseGroupRule>;
let lessonRule: DeepMocked<LessonRule>;
let schoolRule: DeepMocked<SchoolRule>;
let legacySchoolRule: DeepMocked<LegacySchoolRule>;
let userRule: DeepMocked<UserRule>;
let taskRule: DeepMocked<TaskRule>;
let teamRule: DeepMocked<TeamRule>;
Expand All @@ -43,7 +43,7 @@ describe('RuleManager', () => {
{ provide: CourseRule, useValue: createMock<CourseRule>() },
{ provide: CourseGroupRule, useValue: createMock<CourseGroupRule>() },
{ provide: LessonRule, useValue: createMock<LessonRule>() },
{ provide: SchoolRule, useValue: createMock<SchoolRule>() },
{ provide: LegacySchoolRule, useValue: createMock<LegacySchoolRule>() },
{ provide: UserRule, useValue: createMock<UserRule>() },
{ provide: TaskRule, useValue: createMock<TaskRule>() },
{ provide: TeamRule, useValue: createMock<TeamRule>() },
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/modules/authorization/rule-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
CourseRule,
LessonRule,
SchoolExternalToolRule,
SchoolRule,
LegacySchoolRule,
SubmissionRule,
TaskRule,
TeamRule,
Expand All @@ -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,
Expand All @@ -42,7 +42,7 @@ export class RuleManager {
this.taskRule,
this.teamRule,
this.userRule,
this.schoolRule,
this.legaySchoolRule,
this.submissionRule,
this.schoolExternalToolRule,
this.boardDoRule,
Expand Down
Loading

0 comments on commit 1013581

Please sign in to comment.