Skip to content

Commit

Permalink
enhance logging regarding PersonenkontextUpdateEvent in handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
DPDS93CT committed Jan 15, 2025
1 parent 3173196 commit 3cf7c06
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/core/ldap/domain/ldap-client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export class LdapClientService {
returnAttributeValues: true,
});
if (!searchResult.searchEntries[0]) {
this.logger.error(`Modification FAILED, no entry for person:${oldReferrer}`);
this.logger.error(`Modifying person-attributes FAILED, no entry for person:${oldReferrer}`);
return {
ok: false,
error: new LdapSearchError(LdapEntityType.LEHRER),
Expand Down Expand Up @@ -834,7 +834,7 @@ export class LdapClientService {
returnAttributeValues: true,
});
if (!searchResult.searchEntries[0]) {
this.logger.error(`Modification FAILED, no entry for person:${referrer}`);
this.logger.error(`Modifying user-password FAILED, no entry for person:${referrer}`);
return {
ok: false,
error: new LdapSearchError(LdapEntityType.LEHRER),
Expand Down
4 changes: 2 additions & 2 deletions src/core/ldap/domain/ldap-event-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ describe('LDAP Event Handler', () => {
await ldapEventHandler.handleEmailAddressGeneratedEvent(event);

expect(loggerMock.info).toHaveBeenLastCalledWith(
`Received EmailAddressGeneratedEvent, personId:${event.personId}, emailAddress: ${event.address}`,
`Received EmailAddressGeneratedEvent, personId:${event.personId}, referrer:${event.referrer}, emailAddress:${event.address}`,
);
expect(ldapClientServiceMock.changeEmailAddressByPersonId).toHaveBeenCalledTimes(1);
});
Expand All @@ -920,7 +920,7 @@ describe('LDAP Event Handler', () => {
await ldapEventHandler.handleEmailAddressChangedEvent(event);

expect(loggerMock.info).toHaveBeenLastCalledWith(
`Received EmailAddressChangedEvent, personId:${event.personId}, newEmailAddress: ${event.newAddress}`,
`Received EmailAddressChangedEvent, personId:${event.personId}, referrer:${event.referrer}, newEmailAddress:${event.newAddress}`,
);
expect(ldapClientServiceMock.changeEmailAddressByPersonId).toHaveBeenCalledTimes(1);
});
Expand Down
14 changes: 9 additions & 5 deletions src/core/ldap/domain/ldap-event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export class LdapEventHandler {

@EventHandler(PersonDeletedEvent)
public async handlePersonDeletedEvent(event: PersonDeletedEvent): Promise<void> {
this.logger.info(`Received PersonenkontextDeletedEvent, personId:${event.personId}`);
this.logger.info(
`Received PersonenkontextDeletedEvent, personId:${event.personId}, referrer:${event.referrer}`,
);
const deletionResult: Result<PersonID> = await this.ldapClientService.deleteLehrerByReferrer(event.referrer);
if (!deletionResult.ok) {
this.logger.error(deletionResult.error.message);
Expand Down Expand Up @@ -133,7 +135,9 @@ export class LdapEventHandler {

@EventHandler(PersonRenamedEvent)
public async personRenamedEventHandler(event: PersonRenamedEvent): Promise<void> {
this.logger.info(`Received PersonRenamedEvent, personId:${event.personId}`);
this.logger.info(
`Received PersonRenamedEvent, personId:${event.personId}, referrer:${event.referrer}, oldReferrer:${event.oldReferrer}`,
);
const modifyResult: Result<PersonID> = await this.ldapClientService.modifyPersonAttributes(
event.oldReferrer,
event.vorname,
Expand All @@ -150,7 +154,7 @@ export class LdapEventHandler {
@EventHandler(PersonenkontextUpdatedEvent)
public async handlePersonenkontextUpdatedEvent(event: PersonenkontextUpdatedEvent): Promise<void> {
this.logger.info(
`Received PersonenkontextUpdatedEvent, personId:${event.person.id}, new personenkontexte: ${event.newKontexte.length}, deleted personenkontexte: ${event.removedKontexte.length}`,
`Received PersonenkontextUpdatedEvent, personId:${event.person.id}, referrer:${event.person.referrer}, newPKs:${event.newKontexte.length}, removedPKs:${event.removedKontexte.length}`,
);

await Promise.allSettled(
Expand Down Expand Up @@ -235,7 +239,7 @@ export class LdapEventHandler {
@EventHandler(EmailAddressGeneratedEvent)
public async handleEmailAddressGeneratedEvent(event: EmailAddressGeneratedEvent): Promise<void> {
this.logger.info(
`Received EmailAddressGeneratedEvent, personId:${event.personId}, emailAddress: ${event.address}`,
`Received EmailAddressGeneratedEvent, personId:${event.personId}, referrer:${event.referrer}, emailAddress:${event.address}`,
);

await this.ldapClientService.changeEmailAddressByPersonId(event.personId, event.referrer, event.address);
Expand All @@ -244,7 +248,7 @@ export class LdapEventHandler {
@EventHandler(EmailAddressChangedEvent)
public async handleEmailAddressChangedEvent(event: EmailAddressChangedEvent): Promise<void> {
this.logger.info(
`Received EmailAddressChangedEvent, personId:${event.personId}, newEmailAddress: ${event.newAddress}`,
`Received EmailAddressChangedEvent, personId:${event.personId}, referrer:${event.referrer}, newEmailAddress:${event.newAddress}`,
);

await this.ldapClientService.changeEmailAddressByPersonId(event.personId, event.referrer, event.newAddress);
Expand Down
6 changes: 4 additions & 2 deletions src/modules/email/domain/email-event-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ describe('EmailEventHandler', () => {
fakeEmailAddress = faker.internet.email();
event = createMock<PersonenkontextUpdatedEvent>({
person: { id: fakePersonId },
removedKontexte: undefined,
removedKontexte: [],
newKontexte: [],
});
personRenamedEvent = new PersonRenamedEvent(
fakePersonId,
Expand Down Expand Up @@ -347,7 +348,8 @@ describe('EmailEventHandler', () => {

event = createMock<PersonenkontextUpdatedEvent>({
person: { id: fakePersonId, referrer: fakeReferrer },
removedKontexte: undefined,
removedKontexte: [],
newKontexte: [],
});
personenkontexte = [createMock<Personenkontext<true>>({ rolleId: fakeRolleId })];

Expand Down
2 changes: 1 addition & 1 deletion src/modules/email/domain/email-event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class EmailEventHandler {
// currently receiving of this event is not causing a deletion of email and the related addresses for the affected user, this is intentional
public async handlePersonenkontextUpdatedEvent(event: PersonenkontextUpdatedEvent): Promise<void> {
this.logger.info(
`Received PersonenkontextUpdatedEvent, personId:${event.person.id}, referrer:${event.person.referrer}`,
`Received PersonenkontextUpdatedEvent, personId:${event.person.id}, referrer:${event.person.referrer}, newPKs:${event.newKontexte.length}, removedPKs:${event.removedKontexte.length}`,
);

await this.handlePerson(event.person.id, event.person.referrer, event.removedKontexte);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ export class ItsLearningPersonsEventHandler {
@EventHandler(PersonenkontextUpdatedEvent)
public async updatePersonenkontexteEventHandler(event: PersonenkontextUpdatedEvent): Promise<void> {
await this.personUpdateMutex.runExclusive(async () => {
this.logger.info(`[EventID: ${event.eventID}] Received PersonenkontextUpdatedEvent, ${event.person.id}`);
this.logger.info(
`[EventID: ${event.eventID}] Received PersonenkontextUpdatedEvent, ${event.person.id}, ${event.person.referrer}`,
);

if (!this.ENABLED) {
return this.logger.info(`[EventID: ${event.eventID}] Not enabled, ignoring event.`);
Expand Down
8 changes: 5 additions & 3 deletions src/modules/ox/domain/ox-event-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ describe('OxEventHandler', () => {
await sut.handleEmailAddressAlreadyExistsEvent(event);

expect(loggerMock.info).toHaveBeenLastCalledWith(
`Successfully added user with personId:${event.personId} to OX group with id:${fakeOXGroupId}`,
`Successfully added user to group, personId:${event.personId}, oxUserId:${person.oxUserId}, oxGroupId:${fakeOXGroupId}`,
);
expect(eventServiceMock.publish).toHaveBeenCalledTimes(1);
});
Expand All @@ -1018,7 +1018,9 @@ describe('OxEventHandler', () => {
await sut.handleEmailAddressAlreadyExistsEvent(event);

expect(loggerMock.error).toHaveBeenCalledWith(
expect.stringContaining(`Failed to get or create OX group for orgaKennung:${event.orgaKennung}`),
expect.stringContaining(
`Get or create OX group failed, personId:${event.personId}, oxUserId:${person.oxUserId}, orgaKennung:${event.orgaKennung}`,
),
);
});

Expand Down Expand Up @@ -1051,7 +1053,7 @@ describe('OxEventHandler', () => {

expect(loggerMock.error).toHaveBeenCalledWith(
expect.stringContaining(
`Failed to add user with personId:${event.personId} to OX group with id:${fakeOXGroupId}`,
`Failed to add user to group, personId:${event.personId}, oxUserId:${person.oxUserId}, oxGroupId:${fakeOXGroupId}`,
),
);
});
Expand Down
10 changes: 6 additions & 4 deletions src/modules/ox/domain/ox-event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ export class OxEventHandler {
);

if (!oxGroupIdResult.ok) {
return this.logger.error(`Failed to get or create OX group for orgaKennung:${event.orgaKennung}`);
return this.logger.error(
`Get or create OX group failed, personId:${event.personId}, oxUserId:${person.oxUserId}, orgaKennung:${event.orgaKennung}`,
);
}

// Add the user to the OX group
Expand All @@ -148,13 +150,13 @@ export class OxEventHandler {

if (!addUserToGroupResult.ok) {
return this.logger.error(
`Failed to add user with personId:${event.personId} to OX group with id:${oxGroupIdResult.value}`,
`Failed to add user to group, personId:${event.personId}, oxUserId:${person.oxUserId}, oxGroupId:${oxGroupIdResult.value}`,
);
}

// Log the successful addition of the user to the group
this.logger.info(
`Successfully added user with personId:${event.personId} to OX group with id:${oxGroupIdResult.value}`,
`Successfully added user to group, personId:${event.personId}, oxUserId:${person.oxUserId}, oxGroupId:${oxGroupIdResult.value}`,
);

// Should always be true
Expand Down Expand Up @@ -196,7 +198,7 @@ export class OxEventHandler {
@EventHandler(PersonenkontextUpdatedEvent)
public async handlePersonenkontextUpdatedEvent(event: PersonenkontextUpdatedEvent): Promise<void> {
this.logger.info(
`Received PersonenkontextUpdatedEvent, personId:${event.person.id}, deleted personenkontexte: ${event.removedKontexte.length}`,
`Received PersonenkontextUpdatedEvent, personId:${event.person.id}, referrer:${event.person.referrer}, newPKs:${event.newKontexte.length}, removedPKs:${event.removedKontexte.length}`,
);
if (!this.ENABLED) {
return this.logger.info('Not enabled, ignoring event');
Expand Down

0 comments on commit 3cf7c06

Please sign in to comment.