Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPSH-1666: add istTechnisch to Person #872

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions migrations/.snapshot-dbildungs-iam-server.json
Original file line number Diff line number Diff line change
Expand Up @@ -2177,6 +2177,16 @@
"nullable": true,
"length": 6,
"mappedType": "datetime"
},
"ist_technisch": {
"name": "ist_technisch",
"type": "boolean",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"default": "false",
"mappedType": "boolean"
}
},
"name": "person",
Expand Down
11 changes: 11 additions & 0 deletions migrations/Migration20250114120248-S.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Migration } from '@mikro-orm/migrations';

export class Migration20250114120248 extends Migration {
public async up(): Promise<void> {
this.addSql('alter table "person" add column "ist_technisch" boolean not null default false;');
}

public override async down(): Promise<void> {
this.addSql('alter table "person" drop column "ist_technisch";');
}
}
9 changes: 9 additions & 0 deletions migrations/Migration20250114133700-D.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Migration } from '@mikro-orm/migrations';

export class Migration20250114120248 extends Migration {
public async up(): Promise<void> {
this.addSql(
'update person as p set ist_technisch = true where p.id in (select pk.person_id from personenkontext as pk join rolle as r on r.id = pk.rolle_id where r.ist_technisch = true);',
);
}
}
1 change: 1 addition & 0 deletions src/console/dbseed/domain/db-seed.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ export class DbSeedService {
vorname: file.vorname,
username: file.username,
password: file.password,
istTechnisch: true,
};

const person: Person<false> | DomainError = await this.personFactory.createNew(creationParams);
Expand Down
2 changes: 2 additions & 0 deletions src/console/dbseed/file/person-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ export class PersonFile {
public revision!: string;

public personalnummer?: string;

public istTechnisch?: string;
}
121 changes: 121 additions & 0 deletions src/modules/person/domain/person.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,51 @@ describe('Person', () => {
expect(person).toBeInstanceOf(Person<true>);
expect(person.revision).toEqual('5');
expect(person.userLock).toEqual([]);
expect(person.istTechnisch).toEqual(false);
});

it.each([
[true, true],
[false, false],
[undefined, false],
])('when input is %s, it should set istTechnisch to %s', (input: boolean | undefined, expected: boolean) => {
const person: Person<true> = Person.construct(
faker.string.uuid(),
faker.date.past(),
faker.date.recent(),
faker.person.lastName(),
faker.person.firstName(),
'5',
faker.lorem.word(),
faker.lorem.word(),
faker.string.uuid(),
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
input,
);

expect(person).toBeDefined();
expect(person).toBeInstanceOf(Person<true>);
expect(person.istTechnisch).toEqual(expected);
});
});

Expand Down Expand Up @@ -296,12 +341,88 @@ describe('Person', () => {
faker.lorem.word(),
faker.string.uuid(),
);
const initialIstTechnisch: boolean = person.istTechnisch;
const result: void | DomainError = person.update('5', undefined, undefined, 'abc');

expect(result).not.toBeInstanceOf(DomainError);
expect(person.vorname).toEqual('Max');
expect(person.familienname).toEqual('Mustermann');
expect(person.referrer).toEqual('abc');
expect(person.istTechnisch).toEqual(initialIstTechnisch);
});
});
describe('revision does match and istTechnisch is updated', () => {
it('should update istTechnisch in the person', () => {
const person: Person<true> = Person.construct(
faker.string.uuid(),
faker.date.past(),
faker.date.recent(),
'Mustermann',
'Max',
'5',
faker.lorem.word(),
faker.lorem.word(),
faker.string.uuid(),
);
let result: void | DomainError = person.update(
'5',
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
'',
true,
);
expect(result).not.toBeInstanceOf(DomainError);
expect(person.istTechnisch).toEqual(true);

result = person.update(
'6',
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
'',
false,
);
expect(result).not.toBeInstanceOf(DomainError);
expect(person.istTechnisch).toEqual(false);
});
});
describe('revision does not match', () => {
Expand Down
8 changes: 8 additions & 0 deletions src/modules/person/domain/person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type PersonCreationParams = {
userLock?: UserLock[];
isLocked?: boolean;
orgUnassignmentDate?: Date;
istTechnisch?: boolean;
};

export class Person<WasPersisted extends boolean> {
Expand Down Expand Up @@ -79,8 +80,10 @@ export class Person<WasPersisted extends boolean> {
public isLocked: boolean | undefined,
public email: string | undefined,
public oxUserId: string | undefined,
public istTechnisch: boolean,
) {
this.mandant = Person.CREATE_PERSON_DTO_MANDANT_UUID;
this.istTechnisch = istTechnisch;
}

public get newPassword(): string | undefined {
Expand Down Expand Up @@ -122,6 +125,7 @@ export class Person<WasPersisted extends boolean> {
isLocked?: boolean,
email?: string,
oxUserId?: string,
istTechnisch?: boolean,
): Person<WasPersisted> {
return new Person(
id,
Expand Down Expand Up @@ -154,6 +158,7 @@ export class Person<WasPersisted extends boolean> {
isLocked,
email,
oxUserId,
istTechnisch ?? false,
);
}

Expand Down Expand Up @@ -202,6 +207,7 @@ export class Person<WasPersisted extends boolean> {
undefined,
undefined,
undefined,
creationParams.istTechnisch ?? false,
);

if (creationParams.password) {
Expand Down Expand Up @@ -252,6 +258,7 @@ export class Person<WasPersisted extends boolean> {
orgUnassignmentDate?: Date,
isLocked?: boolean,
email?: string,
istTechnisch?: boolean,
): void | DomainError {
if (this.revision !== revision) {
return new MismatchedRevisionError(
Expand Down Expand Up @@ -295,6 +302,7 @@ export class Person<WasPersisted extends boolean> {
this.isLocked = isLocked;
this.email = email;
this.userLock = userLock ?? [];
if (istTechnisch !== undefined) this.istTechnisch = istTechnisch;
}

public resetPassword(): void {
Expand Down
4 changes: 4 additions & 0 deletions src/modules/person/persistence/person.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,8 @@ export class PersonEntity extends TimestampedEntity {
orphanRemoval: true,
})
public userLocks: Collection<UserLockEntity> = new Collection<UserLockEntity>(this);

@AutoMap()
@Property({ default: false })
public istTechnisch!: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,7 @@ describe('PersonRepository Integration', () => {
'auskunftssperre',
'dataProvider',
'revision',
'istTechnisch',
];

const result: RequiredEntityData<PersonEntity> = mapAggregateToData(person);
Expand Down Expand Up @@ -1271,6 +1272,7 @@ describe('PersonRepository Integration', () => {

it('should return DomainError when user is technical', async () => {
const person1: Person<true> = DoFactory.createPerson(true);
person1.istTechnisch = true;
const personEntity: PersonEntity = new PersonEntity();
await em.persistAndFlush(personEntity.assign(mapAggregateToData(person1)));
person1.id = personEntity.id;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/person/persistence/person.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export function mapAggregateToData(person: Person<boolean>): RequiredEntityData<
revision: person.revision,
personalnummer: person.personalnummer,
orgUnassignmentDate: person.orgUnassignmentDate,
istTechnisch: person.istTechnisch,
};
}

Expand Down Expand Up @@ -123,6 +124,7 @@ export function mapEntityToAggregate(entity: PersonEntity): Person<true> {
undefined,
getEnabledOrAlternativeEmailAddress(entity),
getOxUserId(entity),
entity.istTechnisch,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,11 @@ describe('PersonScope', () => {
});

it('should not return technical users', async () => {
const orgnisationID: string = faker.string.uuid();
const person1: PersonEntity = createPersonEntity();
const person2: PersonEntity = createPersonEntity();
const rolle: Rolle<true> | DomainError = await rolleRepo.save(
DoFactory.createRolle(false, { istTechnisch: true }),
);
if (rolle instanceof DomainError) throw Error();
person2.istTechnisch = true;

await em.persistAndFlush([person1, person2]);
await createPersonenkontext(person1.id, orgnisationID, rolle.id);

const scope: PersonScope = new PersonScope()
.findBy({ ids: [person1.id, person2.id] })
Expand Down
4 changes: 1 addition & 3 deletions src/modules/person/persistence/person.scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ export class PersonScope extends ScopeBase<PersonEntity> {
findProps.organisationen !== undefined && {
personenKontexte: { $some: { organisationId: { $in: findProps.organisationen } } },
},
{
personenKontexte: { $none: { rolleId: { istTechnisch: true } } },
},
{ istTechnisch: false },
].filter(Boolean),
};

Expand Down
1 change: 1 addition & 0 deletions test/utils/do-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class DoFactory {
personalnummer: faker.string.numeric({ length: 7 }),
revision: '1',
};
person.istTechnisch = false;
return Object.assign(Object.create(Person.prototype) as Person<boolean>, person, props);
}

Expand Down
Loading