Skip to content

Commit

Permalink
Personenkontext-Update Event / ldapEntryUUID
Browse files Browse the repository at this point in the history
  • Loading branch information
casparneumann-cap authored Sep 9, 2024
1 parent 0ee0f61 commit 4bf3c8c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 6 deletions.
23 changes: 23 additions & 0 deletions src/core/ldap/domain/ldap-client.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,29 @@ describe('LDAP Client Service', () => {
expect(result.ok).toBeTruthy();
});

it('when called with extra entryUUID should return truthy result', async () => {
ldapClientMock.getClient.mockImplementation(() => {
clientMock.bind.mockResolvedValue();
clientMock.add.mockResolvedValueOnce();
clientMock.search.mockResolvedValueOnce(
createMock<SearchResult>({ searchEntries: [createMock<Entry>()] }),
); //mock existsSchule
clientMock.search.mockResolvedValueOnce(createMock<SearchResult>()); //mock existsLehrer

return clientMock;
});
const testLehrer: PersonData = {
id: faker.string.uuid(),
vorname: faker.person.firstName(),
familienname: faker.person.lastName(),
referrer: faker.lorem.word(),
ldapEntryUUID: faker.string.uuid(),
};
const result: Result<PersonData> = await ldapClientService.createLehrer(testLehrer, organisation);

expect(result.ok).toBeTruthy();
});

it('when called with valid person and an organisation without kennung should return error result', async () => {
ldapClientMock.getClient.mockImplementation(() => {
clientMock.bind.mockResolvedValue();
Expand Down
13 changes: 11 additions & 2 deletions src/core/ldap/domain/ldap-client.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { ClassLogger } from '../../logging/class-logger.js';
import { Client, SearchResult } from 'ldapts';
import { Client, Control, SearchResult } from 'ldapts';
import { LdapEntityType, LdapOrganisationEntry, LdapPersonEntry, LdapRoleEntry } from './ldap.types.js';
import { KennungRequiredForSchuleError } from '../../../modules/organisation/specification/error/kennung-required-for-schule.error.js';
import { LdapClient } from './ldap-client.js';
Expand All @@ -15,6 +15,7 @@ export type PersonData = {
familienname: string;
id: string;
referrer?: string;
ldapEntryUUID?: string;
};

type OrganisationData = {
Expand Down Expand Up @@ -154,7 +155,15 @@ export class LdapClientService {
mail: [`${person.referrer}@schule-sh.de`],
objectclass: ['inetOrgPerson'],
};
await client.add(lehrerUid, entry);

const controls: Control[] = [];
if (person.ldapEntryUUID) {
const relaxRulesControlOID: string = '1.3.6.1.4.1.4203.666.5.12';
entry.entryUUID = person.ldapEntryUUID;
controls.push(new Control(relaxRulesControlOID));
}

await client.add(lehrerUid, entry, controls);
this.logger.info(`LDAP: Successfully created lehrer ${lehrerUid}`);

return { ok: true, value: person };
Expand Down
1 change: 1 addition & 0 deletions src/core/ldap/domain/ldap.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type LdapPersonEntry = {
employeeNumber: string;
mail: string[];
objectclass: string[];
entryUUID?: string;
};

export type LdapOrganisationEntry = {
Expand Down
8 changes: 6 additions & 2 deletions src/modules/personenkontext/domain/personenkontexte-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ export class PersonenkontexteUpdate {
return undefined;
}

public async update(): Promise<Personenkontext<true>[] | PersonenkontexteUpdateError> {
public async update(ldapEntryUUID?: string): Promise<Personenkontext<true>[] | PersonenkontexteUpdateError> {
//If first lehrer kontext is created and a UUID is passed as ldapEntryUUID it is used as internal LDAP entryUUID (needed for migration, can be build back afterwards)
const sentPKs: Personenkontext<true>[] | PersonenkontexteUpdateError = await this.getSentPersonenkontexte();
if (sentPKs instanceof PersonenkontexteUpdateError) {
return sentPKs;
Expand Down Expand Up @@ -317,7 +318,8 @@ export class PersonenkontexteUpdate {
const existingPKsAfterUpdate: Personenkontext<true>[] = await this.dBiamPersonenkontextRepo.findByPerson(
this.personId,
);
await this.publishEvent(deletedPKs, createdPKs, existingPKsAfterUpdate);

await this.publishEvent(deletedPKs, createdPKs, existingPKsAfterUpdate, ldapEntryUUID);

return existingPKsAfterUpdate;
}
Expand All @@ -326,6 +328,7 @@ export class PersonenkontexteUpdate {
deletedPKs: Personenkontext<true>[],
createdPKs: Personenkontext<true>[],
existingPKs: Personenkontext<true>[],
ldapEntryUUID?: string,
): Promise<void> {
const deletedRollenIDs: RolleID[] = deletedPKs.map((pk: Personenkontext<true>) => pk.rolleId);
const createdRollenIDs: RolleID[] = createdPKs.map((pk: Personenkontext<true>) => pk.rolleId);
Expand Down Expand Up @@ -372,6 +375,7 @@ export class PersonenkontexteUpdate {
orgas.get(pk.organisationId)!,
rollen.get(pk.rolleId)!,
]),
ldapEntryUUID,
),
);
}
Expand Down
1 change: 1 addition & 0 deletions src/shared/events/personenkontext-event.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type PersonenkontextEventPersonData = {
familienname: string;
referrer?: string;
email?: string;
ldapEntryUUID?: string;
};

export type PersonenkontextEventKontextData = {
Expand Down
6 changes: 4 additions & 2 deletions src/shared/events/personenkontext-updated.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ export type PersonenkontextUpdatedPersonData = PersonenkontextEventPersonData;

export type PersonenkontextUpdatedData = PersonenkontextEventKontextData;

function mapPersonToData(person: Person<true>): PersonenkontextUpdatedPersonData {
function mapPersonToData(person: Person<true>, ldapEntryUUID?: string): PersonenkontextUpdatedPersonData {
return {
id: person.id,
vorname: person.vorname,
familienname: person.familienname,
referrer: person.referrer,
ldapEntryUUID: ldapEntryUUID,
email: person.email,
};
}
Expand Down Expand Up @@ -50,9 +51,10 @@ export class PersonenkontextUpdatedEvent extends BaseEvent {
newKontexte: [Personenkontext<true>, Organisation<true>, Rolle<true>][],
removedKontexte: [Personenkontext<true>, Organisation<true>, Rolle<true>][],
currentKontexte: [Personenkontext<true>, Organisation<true>, Rolle<true>][],
ldapEntryUUID?: string,
): PersonenkontextUpdatedEvent {
return new PersonenkontextUpdatedEvent(
mapPersonToData(person),
mapPersonToData(person, ldapEntryUUID),
newKontexte.map(mapPersonenkontextAndRolleAggregateToData),
removedKontexte.map(mapPersonenkontextAndRolleAggregateToData),
currentKontexte.map(mapPersonenkontextAndRolleAggregateToData),
Expand Down

0 comments on commit 4bf3c8c

Please sign in to comment.