Skip to content

Commit

Permalink
Merge branch 'main' into EW-1021
Browse files Browse the repository at this point in the history
  • Loading branch information
mkreuzkam-cap authored Dec 11, 2024
2 parents 30a1a44 + 545982e commit 032938a
Show file tree
Hide file tree
Showing 72 changed files with 568 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,12 @@ describe(EtherpadClientAdapter.name, () => {
it('should throw EtherpadErrorLoggableException', async () => {
const groupId = setup();

const exception = new EtherpadErrorLoggableException(EtherpadErrorType.INTERNAL_ERROR, { padId: groupId }, {});
const exception = new EtherpadErrorLoggableException(
EtherpadErrorType.INTERNAL_ERROR,
{ padId: groupId },
undefined,
{}
);
await expect(service.deleteGroup(groupId)).rejects.toThrowError(exception);
});
});
Expand Down Expand Up @@ -1084,7 +1089,12 @@ describe(EtherpadClientAdapter.name, () => {
it('should throw EtherpadErrorLoggableException', async () => {
const sessionId = setup();

const exception = new EtherpadErrorLoggableException(EtherpadErrorType.BAD_REQUEST, { sessionId }, {});
const exception = new EtherpadErrorLoggableException(
EtherpadErrorType.BAD_REQUEST,
{ sessionId },
undefined,
{}
);
await expect(service.deleteSession(sessionId)).rejects.toThrowError(exception);
});
});
Expand Down Expand Up @@ -1150,7 +1160,7 @@ describe(EtherpadClientAdapter.name, () => {
it('should throw EtherpadErrorLoggableException', async () => {
const padId = setup();

const exception = new EtherpadErrorLoggableException(EtherpadErrorType.BAD_REQUEST, { padId }, {});
const exception = new EtherpadErrorLoggableException(EtherpadErrorType.BAD_REQUEST, { padId }, undefined, {});
await expect(service.deletePad(padId)).rejects.toThrowError(exception);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export class EtherpadErrorLoggableException extends InternalServerErrorException
constructor(
private readonly type: EtherpadErrorType,
private readonly payload: EtherpadParams,
private readonly originalMessage: string | undefined,
private readonly exceptionOptions: HttpExceptionOptions
) {
super(type, exceptionOptions);
Expand All @@ -20,6 +21,7 @@ export class EtherpadErrorLoggableException extends InternalServerErrorException
data: {
userId,
parentId,
originalMessage: this.originalMessage,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('EtherpadErrorLoggableException', () => {
const error = new Error('error');
const httpExceptionOptions = ErrorUtils.createHttpExceptionOptions(error);

const exception = new EtherpadErrorLoggableException(type, payload, httpExceptionOptions);
const exception = new EtherpadErrorLoggableException(type, payload, 'hugo ist nudeln', httpExceptionOptions);
const result = exception.getLogMessage();

expect(result).toStrictEqual({
Expand All @@ -22,6 +22,7 @@ describe('EtherpadErrorLoggableException', () => {
data: {
userId: 'userId',
parentId: 'parentId',
originalMessage: 'hugo ist nudeln',
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ export class EtherpadResponseMapper {
payload: EtherpadParams,
response: T | Error
): EtherpadErrorLoggableException {
return new EtherpadErrorLoggableException(type, payload, ErrorUtils.createHttpExceptionOptions(response.message));
return new EtherpadErrorLoggableException(
type,
payload,
response.message,
ErrorUtils.createHttpExceptionOptions(response.message)
);
}

static mapEtherpadSessionsToSessions(etherpadSessions: unknown): Session[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Type } from 'class-transformer';
import { IsEnum, IsObject, IsOptional, IsString, ValidateNested } from 'class-validator';
import { SchulconnexGroupType } from './schulconnex-group-type';
import { IsObject, IsOptional, IsString, ValidateNested } from 'class-validator';
import { SchulconnexLaufzeitResponse } from './schulconnex-laufzeit-response';

export class SchulconnexGruppeResponse {
Expand All @@ -10,8 +9,8 @@ export class SchulconnexGruppeResponse {
@IsString()
bezeichnung!: string;

@IsEnum(SchulconnexGroupType)
typ!: SchulconnexGroupType;
@IsString()
typ!: string;

@IsOptional()
@IsObject()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { Type } from 'class-transformer';
import { IsArray, IsEnum, IsObject, IsOptional, IsString, ValidateNested } from 'class-validator';
import { IsArray, IsObject, IsOptional, IsString, ValidateNested } from 'class-validator';
import { SchulconnexErreichbarkeitenResponse } from './schulconnex-erreichbarkeiten-response';
import { SchulconnexGruppenResponse } from './schulconnex-gruppen-response';
import { SchulconnexOrganisationResponse } from './schulconnex-organisation-response';
import { SchulconnexResponseValidationGroups } from './schulconnex-response-validation-groups';
import { SchulconnexRole } from './schulconnex-role';

export class SchulconnexPersonenkontextResponse {
@IsString({ groups: [SchulconnexResponseValidationGroups.USER, SchulconnexResponseValidationGroups.GROUPS] })
id!: string;

@IsEnum(SchulconnexRole, { groups: [SchulconnexResponseValidationGroups.USER] })
rolle!: SchulconnexRole;
@IsString({ groups: [SchulconnexResponseValidationGroups.USER] })
rolle!: string;

@IsObject({ groups: [SchulconnexResponseValidationGroups.SCHOOL] })
@ValidateNested({ groups: [SchulconnexResponseValidationGroups.SCHOOL] })
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/infra/sync/tsp/tsp-oauth-data.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class TspOauthDataMapper {
});

const externalSchools = new Map<string, ExternalSchoolDto>();
const externalClasses = new Map<string, ExternalUserDto>();
const externalClasses = new Map<string, ExternalClassDto>();
const teacherForClasses = new Map<string, Array<string>>();
const oauthDataDtos: OauthDataDto[] = [];

Expand Down Expand Up @@ -85,9 +85,9 @@ export class TspOauthDataMapper {
});

const classIds = teacherForClasses.get(tspTeacher.lehrerUid) ?? [];
const classes = classIds
const classes: ExternalClassDto[] = classIds
.map((classId) => externalClasses.get(classId))
.filter((externalClass) => !!externalClass);
.filter((externalClass: ExternalClassDto | undefined): externalClass is ExternalClassDto => !!externalClass);

const externalSchool = tspTeacher.schuleNummer == null ? undefined : externalSchools.get(tspTeacher.schuleNummer);

Expand Down
3 changes: 2 additions & 1 deletion apps/server/src/infra/sync/tsp/tsp-sync.strategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { schoolFactory } from '@src/modules/school/testing';
import { System } from '@src/modules/system';
import { systemFactory } from '@src/modules/system/testing';
import { SyncStrategyTarget } from '../sync-strategy.types';
import { TspLegacyMigrationService } from './tsp-legacy-migration.service';
import { TspFetchService } from './tsp-fetch.service';
import { TspLegacyMigrationService } from './tsp-legacy-migration.service';
import { TspOauthDataMapper } from './tsp-oauth-data.mapper';
import { TspSyncConfig } from './tsp-sync.config';
import { TspSyncService } from './tsp-sync.service';
Expand Down Expand Up @@ -171,6 +171,7 @@ describe(TspSyncStrategy.name, () => {
}),
externalUser: new ExternalUserDto({
externalId: faker.string.alpha(),
roles: [],
}),
});
const tspTeacher: RobjExportLehrerMigration = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export class AuthorizationContextBuilder {
return context;
}

static write(requiredPermissions: Permission[]): AuthorizationContext {
public static write(requiredPermissions: Permission[]): AuthorizationContext {
const context = this.build(requiredPermissions, Action.write);

return context;
}

static read(requiredPermissions: Permission[]): AuthorizationContext {
public static read(requiredPermissions: Permission[]): AuthorizationContext {
const context = this.build(requiredPermissions, Action.read);

return context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
cleanupCollections,
groupEntityFactory,
roleFactory,
schoolEntityFactory,
TestApiClient,
UserAndAccountTestFactory,
} from '@shared/testing';
Expand Down Expand Up @@ -49,12 +50,17 @@ describe(`board copy with room relation (api)`, () => {
name: RoleName.ROOMEDITOR,
permissions: [Permission.ROOM_EDIT],
});
const { teacherAccount, teacherUser } = UserAndAccountTestFactory.buildTeacher();
const school = schoolEntityFactory.buildWithId();
const { teacherAccount, teacherUser } = UserAndAccountTestFactory.buildTeacher({ school });
const userGroup = groupEntityFactory.buildWithId({
type: GroupEntityTypes.ROOM,
users: [{ role, user: teacherUser }],
});
const roomMembership = roomMembershipEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id });
const roomMembership = roomMembershipEntityFactory.build({
roomId: room.id,
userGroupId: userGroup.id,
schoolId: teacherUser.school.id,
});
const columnBoardNode = columnBoardEntityFactory.build({
...columnBoardProps,
context: { id: room.id, type: BoardExternalReferenceType.Room },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { INestApplication } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { Permission } from '@shared/domain/interface';
import { RoleName } from '@shared/domain/interface/rolename.enum';
import { cleanupCollections, groupEntityFactory, roleFactory, TestApiClient, userFactory } from '@shared/testing';
import {
cleanupCollections,
groupEntityFactory,
roleFactory,
schoolEntityFactory,
TestApiClient,
userFactory,
} from '@shared/testing';
import { accountFactory } from '@src/modules/account/testing';
import { GroupEntityTypes } from '@src/modules/group/entity';
import { roomMembershipEntityFactory } from '@src/modules/room-membership/testing';
Expand Down Expand Up @@ -42,7 +49,8 @@ describe(`create board in room (api)`, () => {
describe('When request is valid', () => {
describe('When user is allowed to edit the room', () => {
const setup = async () => {
const user = userFactory.buildWithId();
const school = schoolEntityFactory.buildWithId();
const user = userFactory.buildWithId({ school });
const account = accountFactory.withUser(user).build();

const role = roleFactory.buildWithId({ name: RoleName.ROOMEDITOR, permissions: [Permission.ROOM_EDIT] });
Expand All @@ -52,9 +60,13 @@ describe(`create board in room (api)`, () => {
users: [{ user, role }],
});

const room = roomEntityFactory.buildWithId();
const room = roomEntityFactory.buildWithId({ schoolId: user.school.id });

const roomMembership = roomMembershipEntityFactory.build({ roomId: room.id, userGroupId: userGroup.id });
const roomMembership = roomMembershipEntityFactory.build({
roomId: room.id,
userGroupId: userGroup.id,
schoolId: user.school.id,
});

await em.persistAndFlush([account, user, role, userGroup, room, roomMembership]);
em.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ describe(BoardContextService.name, () => {
id: 'foo',
roomId: columnBoard.context.id,
members: [{ userId: user.id, roles: [role] }],
schoolId: user.school.id,
});

const result = await service.getUsersWithBoardRoles(columnBoard);
Expand Down Expand Up @@ -271,6 +272,7 @@ describe(BoardContextService.name, () => {
id: 'foo',
roomId: columnBoard.context.id,
members: [{ userId: user.id, roles: [role] }],
schoolId: user.school.id,
});

const result = await service.getUsersWithBoardRoles(columnBoard);
Expand Down Expand Up @@ -306,6 +308,7 @@ describe(BoardContextService.name, () => {
id: 'foo',
roomId: columnBoard.context.id,
members: [{ userId: user.id, roles: [role] }],
schoolId: user.school.id,
});

const result = await service.getUsersWithBoardRoles(columnBoard);
Expand Down
33 changes: 17 additions & 16 deletions apps/server/src/modules/oauth/service/oauth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { LegacyLogger } from '@src/core/logger';
import { OauthDataDto } from '@src/modules/provisioning/dto';
import { System } from '@src/modules/system';
import jwt, { JwtPayload } from 'jsonwebtoken';
import { externalUserDtoFactory } from '../../provisioning/testing';
import { OAuthTokenDto } from '../interface';
import {
OauthConfigMissingLoggableException,
Expand Down Expand Up @@ -378,9 +379,9 @@ describe('OAuthService', () => {
provisioningStrategy: SystemProvisioningStrategy.SANIS,
provisioningUrl: 'https://mock.person-info.de/',
},
externalUser: {
externalUser: externalUserDtoFactory.build({
externalId: externalUserId,
},
}),
externalSchool: {
externalId: 'externalSchoolId',
name: 'External School',
Expand Down Expand Up @@ -429,9 +430,9 @@ describe('OAuthService', () => {
provisioningStrategy: SystemProvisioningStrategy.SANIS,
provisioningUrl: 'https://mock.person-info.de/',
},
externalUser: {
externalUser: externalUserDtoFactory.build({
externalId: externalUserId,
},
}),
externalSchool: {
externalId: 'externalSchoolId',
name: 'External School',
Expand Down Expand Up @@ -476,9 +477,9 @@ describe('OAuthService', () => {
provisioningStrategy: SystemProvisioningStrategy.SANIS,
provisioningUrl: 'https://mock.person-info.de/',
},
externalUser: {
externalUser: externalUserDtoFactory.build({
externalId: externalUserId,
},
}),
externalSchool: {
externalId: 'externalSchoolId',
name: 'External School',
Expand Down Expand Up @@ -544,9 +545,9 @@ describe('OAuthService', () => {
provisioningStrategy: SystemProvisioningStrategy.SANIS,
provisioningUrl: 'https://mock.person-info.de/',
},
externalUser: {
externalUser: externalUserDtoFactory.build({
externalId: externalUserId,
},
}),
externalSchool: {
externalId: externalSchoolId,
name: school.name,
Expand Down Expand Up @@ -612,9 +613,9 @@ describe('OAuthService', () => {
provisioningStrategy: SystemProvisioningStrategy.SANIS,
provisioningUrl: 'https://mock.person-info.de/',
},
externalUser: {
externalUser: externalUserDtoFactory.build({
externalId: externalUserId,
},
}),
externalSchool: {
externalId: externalSchoolId,
name: school.name,
Expand Down Expand Up @@ -675,9 +676,9 @@ describe('OAuthService', () => {
provisioningStrategy: SystemProvisioningStrategy.SANIS,
provisioningUrl: 'https://mock.person-info.de/',
},
externalUser: {
externalUser: externalUserDtoFactory.build({
externalId: externalUserId,
},
}),
externalSchool: {
externalId: externalSchoolId,
name: school.name,
Expand Down Expand Up @@ -737,9 +738,9 @@ describe('OAuthService', () => {
provisioningStrategy: SystemProvisioningStrategy.SANIS,
provisioningUrl: 'https://mock.person-info.de/',
},
externalUser: {
externalUser: externalUserDtoFactory.build({
externalId: externalUserId,
},
}),
externalSchool: {
externalId: externalSchoolId,
name: school.name,
Expand Down Expand Up @@ -804,9 +805,9 @@ describe('OAuthService', () => {
provisioningStrategy: SystemProvisioningStrategy.SANIS,
provisioningUrl: 'https://mock.person-info.de/',
},
externalUser: {
externalUser: externalUserDtoFactory.build({
externalId: externalUserId,
},
}),
externalSchool: {
externalId: externalSchoolId,
name: school.name,
Expand Down
Loading

0 comments on commit 032938a

Please sign in to comment.