Skip to content

Commit

Permalink
add sonstige gruppenzugehörige
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinOehlerkingCap committed Nov 27, 2023
1 parent 25eead8 commit 53ccfe6
Show file tree
Hide file tree
Showing 14 changed files with 500 additions and 317 deletions.
4 changes: 4 additions & 0 deletions apps/server/src/modules/group/domain/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export class Group extends DomainObject<GroupProps> {
return this.props.users;
}

set users(value: GroupUser[]) {
this.props.users = value;
}

get externalSource(): ExternalSource | undefined {
return this.props.externalSource;
}
Expand Down
10 changes: 5 additions & 5 deletions apps/server/src/modules/provisioning/dto/external-group.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ export class ExternalGroupDto {

name: string;

users: ExternalGroupUserDto[];
user: ExternalGroupUserDto;

otherUsers?: ExternalGroupUserDto[];

from: Date;

until: Date;

type: GroupTypes;

externalOrganizationId?: string;

constructor(props: ExternalGroupDto) {
this.externalId = props.externalId;
this.name = props.name;
this.users = props.users;
this.user = props.user;
this.otherUsers = props.otherUsers;
this.from = props.from;
this.until = props.until;
this.type = props.type;
this.externalOrganizationId = props.externalOrganizationId;
}
}
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
import { externalSchoolDtoFactory } from '@shared/testing';
import { externalGroupDtoFactory } from '@shared/testing/factory/external-group-dto.factory';
import { ExternalGroupDto } from '../dto';
import { ExternalGroupDto, ExternalSchoolDto } from '../dto';
import { SchoolForGroupNotFoundLoggable } from './school-for-group-not-found.loggable';

describe('SchoolForGroupNotFoundLoggable', () => {
describe('constructor', () => {
const setup = () => {
const externalGroupDto: ExternalGroupDto = externalGroupDtoFactory.build();

return { externalGroupDto };
};

it('should create an instance of UserForGroupNotFoundLoggable', () => {
const { externalGroupDto } = setup();

const loggable = new SchoolForGroupNotFoundLoggable(externalGroupDto);

expect(loggable).toBeInstanceOf(SchoolForGroupNotFoundLoggable);
});
});

describe('getLogMessage', () => {
const setup = () => {
const externalGroupDto: ExternalGroupDto = externalGroupDtoFactory.build();
const externalSchoolDto: ExternalSchoolDto = externalSchoolDtoFactory.build();

const loggable = new SchoolForGroupNotFoundLoggable(externalGroupDto);
const loggable = new SchoolForGroupNotFoundLoggable(externalGroupDto, externalSchoolDto);

return { loggable, externalGroupDto };
return {
loggable,
externalGroupDto,
externalSchoolDto,
};
};

it('should return a loggable message', () => {
const { loggable, externalGroupDto } = setup();
const { loggable, externalGroupDto, externalSchoolDto } = setup();

const message = loggable.getLogMessage();

expect(message).toEqual({
message: 'Unable to provision group, since the connected school cannot be found.',
data: {
externalGroupId: externalGroupDto.externalId,
externalOrganizationId: externalGroupDto.externalOrganizationId,
externalOrganizationId: externalSchoolDto.externalId,
},
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ErrorLogMessage, Loggable, LogMessage, ValidationErrorLogMessage } from '@src/core/logger';
import { ExternalGroupDto } from '../dto';
import { ExternalGroupDto, ExternalSchoolDto } from '../dto';

export class SchoolForGroupNotFoundLoggable implements Loggable {
constructor(private readonly group: ExternalGroupDto) {}
constructor(private readonly group: ExternalGroupDto, private readonly school: ExternalSchoolDto) {}

getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage {
return {
message: 'Unable to provision group, since the connected school cannot be found.',
data: {
externalGroupId: this.group.externalId,
externalOrganizationId: this.group.externalOrganizationId,
externalOrganizationId: this.school.externalId,
},
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { Configuration } from '@hpi-schul-cloud/commons/lib';
import { NotImplementedException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { LegacySchoolDo, RoleName, UserDO } from '@shared/domain';
import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy';
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 { externalSchoolDtoFactory } from '@shared/testing/factory/external-school-dto.factory';
import {
ExternalSchoolDto,
ExternalUserDto,
Expand Down Expand Up @@ -181,6 +182,7 @@ describe('OidcStrategy', () => {
systemId: 'systemId',
provisioningStrategy: SystemProvisioningStrategy.OIDC,
}),
externalSchool: externalSchoolDtoFactory.build(),
externalUser: new ExternalUserDto({
externalId: externalUserId,
}),
Expand Down Expand Up @@ -217,10 +219,12 @@ describe('OidcStrategy', () => {

expect(oidcProvisioningService.provisionExternalGroup).toHaveBeenCalledWith(
oauthData.externalGroups?.[0],
oauthData.externalSchool,
oauthData.system.systemId
);
expect(oidcProvisioningService.provisionExternalGroup).toHaveBeenCalledWith(
oauthData.externalGroups?.[1],
oauthData.externalSchool,
oauthData.system.systemId
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export abstract class OidcProvisioningStrategy extends ProvisioningStrategy {
if (data.externalGroups) {
await Promise.all(
data.externalGroups.map((externalGroup) =>
this.oidcProvisioningService.provisionExternalGroup(externalGroup, data.system.systemId)
this.oidcProvisioningService.provisionExternalGroup(
externalGroup,
data.externalSchool,
data.system.systemId
)
)
);
}
Expand Down
Loading

0 comments on commit 53ccfe6

Please sign in to comment.