Skip to content

Commit

Permalink
N21-1493 Provision other group members (#4582)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinOehlerkingCap authored Dec 1, 2023
1 parent ebaaff8 commit 6103055
Show file tree
Hide file tree
Showing 35 changed files with 962 additions and 484 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 @@ -31,6 +31,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
14 changes: 7 additions & 7 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;

from: Date;
otherUsers?: ExternalGroupUserDto[];

until: Date;
from?: Date;

type: GroupTypes;
until?: Date;

externalOrganizationId?: string;
type: GroupTypes;

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,26 +1,7 @@
import { SanisGroupRole, SanisSonstigeGruppenzugehoerigeResponse } from '../strategy/sanis/response';
import { SanisGroupRole, SanisSonstigeGruppenzugehoerigeResponse } from '../strategy';
import { GroupRoleUnknownLoggable } from './group-role-unknown.loggable';

describe('GroupRoleUnknownLoggable', () => {
describe('constructor', () => {
const setup = () => {
const sanisSonstigeGruppenzugehoerigeResponse: SanisSonstigeGruppenzugehoerigeResponse = {
ktid: 'ktid',
rollen: [SanisGroupRole.TEACHER],
};

return { sanisSonstigeGruppenzugehoerigeResponse };
};

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

const loggable = new GroupRoleUnknownLoggable(sanisSonstigeGruppenzugehoerigeResponse);

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

describe('getLogMessage', () => {
const setup = () => {
const sanisSonstigeGruppenzugehoerigeResponse: SanisSonstigeGruppenzugehoerigeResponse = {
Expand All @@ -42,7 +23,7 @@ describe('GroupRoleUnknownLoggable', () => {
message: 'Unable to add unknown user to group during provisioning.',
data: {
externalUserId: sanisSonstigeGruppenzugehoerigeResponse.ktid,
externalRoleName: sanisSonstigeGruppenzugehoerigeResponse.rollen[0],
externalRoleName: sanisSonstigeGruppenzugehoerigeResponse.rollen?.[0],
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class GroupRoleUnknownLoggable implements Loggable {
message: 'Unable to add unknown user to group during provisioning.',
data: {
externalUserId: this.relation.ktid,
externalRoleName: this.relation.rollen[0],
externalRoleName: this.relation.rollen?.[0],
},
};
}
Expand Down
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
Expand Up @@ -5,8 +5,12 @@ import { Test, TestingModule } from '@nestjs/testing';
import { LegacySchoolDo, UserDO } from '@shared/domain/domainobject';
import { RoleName } from '@shared/domain/interface';
import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy';
import { legacySchoolDoFactory, userDoFactory } from '@shared/testing';
import { externalGroupDtoFactory } from '@shared/testing/factory/external-group-dto.factory';
import {
externalGroupDtoFactory,
externalSchoolDtoFactory,
legacySchoolDoFactory,
userDoFactory,
} from '@shared/testing';
import {
ExternalSchoolDto,
ExternalUserDto,
Expand Down Expand Up @@ -182,6 +186,7 @@ describe('OidcStrategy', () => {
systemId: 'systemId',
provisioningStrategy: SystemProvisioningStrategy.OIDC,
}),
externalSchool: externalSchoolDtoFactory.build(),
externalUser: new ExternalUserDto({
externalId: externalUserId,
}),
Expand Down Expand Up @@ -218,10 +223,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 6103055

Please sign in to comment.