Skip to content

[NAE-2085] Refactor User #281

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

Merged
merged 12 commits into from
Jul 20, 2025
8 changes: 4 additions & 4 deletions projects/nae-example-app/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

export const environment = {
production: false,
resolve_configuration: window['env']['resolve_configuration'] || false,
gateway_url: window['env']['gateway_url'] || 'http://localhost:8800/api',
application_identifier: window['env']['application_identifier'] || 'nae',
type_identifier: window['env']['type_identifier'] || 'default'
resolve_configuration: window['env']?.['resolve_configuration'] || false,
gateway_url: window['env']?.['gateway_url'] || 'http://localhost:8800/api',
application_identifier: window['env']?.['application_identifier'] || 'nae',
type_identifier: window['env']?.['type_identifier'] || 'default'
};

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export class UserTransformer implements Transformer<UserResource, User> {
user.username,
user.email,
user.realmId,
user.name,
user.surname,
user.firstName,
user.lastName,
this.transformAuthorities(user.authorities),
user.processRoles,
groups,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export class UserField extends DataField<UserValue> {
}

protected valueEquality(a: UserValue, b: UserValue): boolean {
return (!a && !b) || (!!a && !!b && a.email === b.email);
return (!a && !b) || (!!a && !!b && a.username === b.username);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {TestBed} from '@angular/core/testing';
describe('UserValue', () => {
it('should create an instance', () => {
let user: UserValue;
user = new UserValue('0', 'name', 'surname', 'mail');
user = new UserValue('0', 'realmID0', 'name', 'surname', 'mail');
expect(user.id).toEqual('0');
expect(user.name).toEqual('name');
expect(user.surname).toEqual('surname');
expect(user.firstName).toEqual('name');
expect(user.lastName).toEqual('surname');
expect(user.fullName).toEqual('name surname');
expect(user.email).toEqual('mail');
expect(user.username).toEqual('mail');
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,35 @@ export class UserValue {
/**
* An object that represents the selected user in {@link UserField} and [UserAssignComponent]{@link AbstractUserAssignComponent}.
* @param _id the id of the selected user
* @param _name the first name of the selected user
* @param _surname the surname of the selected user
* @param _email email of the selected user
* @param _realmId the id of the selected user realm
* @param _firstName the first name of the selected user
* @param _lastName the surname of the selected user
* @param _username email of the selected user
*/
constructor(private _id: string, private _name: string, private _surname: string, private _email: string) {
constructor(private _id: string, private _realmId: string, private _firstName: string, private _lastName: string, private _username: string) {
}

get id(): string {
return this._id;
}

get name(): string {
return this._name;
get realmId(): string {
return this._realmId;
}

get surname(): string {
return this._surname;
get firstName(): string {
return this._firstName;
}

get lastName(): string {
return this._lastName;
}

get fullName(): string {
return this._name + ' ' + this._surname;
return this._firstName + ' ' + this._lastName;
}

get email(): string {
return this._email;
get username(): string {
return this._username;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import {expect} from "@ngbracket/ngx-layout/_private-utils/testing";
describe('UserListValue', () => {
it('should create an instance', () => {
let user: UserListValue;
user = new UserListValue(new Map([['0', new UserValue('0', 'name', 'surname', 'mail')]]));
user = new UserListValue(new Map([['0', new UserValue('0', 'realmID0','name', 'surname', 'mail')]]));
expect(user.userValues.get('0').id).toEqual('0');
expect(user.userValues.get('0').name).toEqual('name');
expect(user.userValues.get('0').surname).toEqual('surname');
expect(user.userValues.get('0').firstName).toEqual('name');
expect(user.userValues.get('0').lastName).toEqual('surname');
expect(user.userValues.get('0').fullName).toEqual('name surname');
expect(user.userValues.get('0').email).toEqual('mail');
expect(user.userValues.get('0').username).toEqual('mail');
});

it('should get last', () => {
let user: UserListValue;
user = new UserListValue(new Map([['0', new UserValue('0', 'name', 'surname', 'mail')]]));
user = new UserListValue(new Map([['0', new UserValue('0', 'realmID0','name', 'surname', 'mail')]]));
expect(user.getLast().id === '0').toBeTruthy();
});

it('should remove', () => {
let user: UserListValue;
user = new UserListValue(new Map([['0', new UserValue('0', 'name', 'surname', 'mail')]]));
user = new UserListValue(new Map([['0', new UserValue('0', 'realmID0','name', 'surname', 'mail')]]));
expect(user.userValues.size === 1).toBeTruthy();
user.removeUserValue('0');
expect(user.userValues.size === 0).toBeTruthy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class UserListValue {

public getLast(): UserValue {
if (this._userValues.size == 0) {
return new UserValue('', '', '', '');
return new UserValue('', '', '', '', '');
}
return Array.from(this._userValues.values()).pop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ describe('AbstractSearchModeComponent', () => {
{provide: ConfigurationService, useClass: TestConfigurationService},
{provide: ViewService, useClass: TestViewService},
CaseHeaderService,
{provide: AllowedNetsService, useFactory: TestCaseViewAllowedNetsFactory, deps: [AllowedNetsServiceFactory]}
{
provide: AllowedNetsService,
useFactory: TestCaseViewAllowedNetsFactory,
deps: [AllowedNetsServiceFactory]
}
],
declarations: [TestSeaarchModeComponent, TestWrapperComponent],
}).compileComponents();
Expand All @@ -80,7 +84,7 @@ describe('AbstractSearchModeComponent', () => {
}));

it('should transform UserValue into id', fakeAsync(() => {
component.formControls[0].setValue(new UserValue('7', '', '', ''));
component.formControls[0].setValue(new UserValue('7', 'realmID0', '', '', ''));
tick(600);
expect(headerSpy).toHaveBeenCalledWith(0, '7');
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ describe('AbstractMultiUserAssignComponent', () => {
],
providers: [
UserListService,
{provide: NAE_SIDE_MENU_CONTROL, useValue: new SideMenuControl(() => {
}, new Observable<boolean>(), null)},
{
provide: NAE_SIDE_MENU_CONTROL, useValue: new SideMenuControl(() => {
}, new Observable<boolean>(), null)
},
{provide: ConfigurationService, useClass: TestConfigurationService}
],
declarations: [
Expand All @@ -51,16 +53,16 @@ describe('AbstractMultiUserAssignComponent', () => {
});

it('should select', () => {
component.userWasSelected(new UserValue('0', '', '', ''));
component.userWasSelected(new UserValue('0', 'realmID0', '', '', ''));
expect(component.currentUsers).toBeTruthy();
expect(component.currentUsers.find(u => u.id === '0')).toBeTruthy()
});

it('should unselect', () => {
component.userWasSelected(new UserValue('0', '', '', ''));
component.userWasSelected(new UserValue('0', 'realmID0', '', '', ''));
expect(component.currentUsers).toBeTruthy();
expect(component.currentUsers.find(u => u.id === '0')).toBeTruthy()
component.userWasUnselected(new UserValue('0', '', '', ''));
component.userWasUnselected(new UserValue('0', 'realmID0', '', '', ''));
expect(component.currentUsers.length === 0).toBeTruthy();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ class TestUserComponent extends AbstractBaseUserAssignListComponent implements O
template: '<ncc-test-user [searchUserControl]="formControl"></ncc-test-user>'
})
class TestWrapperComponent {
injectedData = {roles: [], value: new UserValue('5', 'admin', 'netgrif', 'super@netgrif.com')} as UserListInjectedData;
injectedData = {roles: [], value: new UserValue('5', 'realmID0','admin', 'netgrif', 'super@netgrif.com')} as UserListInjectedData;
formControl = new FormControl();
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ class TestUserComponent extends AbstractMultiUserAssignListComponent {
template: '<ncc-test-user [searchUserControl]="formControl"></ncc-test-user>'
})
class TestWrapperComponent {
injectedData = {roles: [], value: new UserValue('5', 'admin', 'netgrif', 'super@netgrif.com')} as UserListInjectedData;
injectedData = {roles: [], value: new UserValue('5', 'realmID0', 'admin', 'netgrif', 'super@netgrif.com')} as UserListInjectedData;
formControl = new FormControl();
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ export abstract class AbstractMultiUserAssignListComponent extends AbstractBaseU
const index = this._currentlySelectedUsers.indexOf(selectedUser.id);
if (index > -1) {
this._currentlySelectedUsers.splice(index, 1);
this.userUnselected.emit(new UserValue(selectedUser.id, selectedUser.name, selectedUser.surname, selectedUser.email));
this.userUnselected.emit(new UserValue(selectedUser.id, selectedUser.realmId, selectedUser.firstName, selectedUser.lastName, selectedUser.username));
} else {
this._currentlySelectedUsers.push(selectedUser.id);
this.userSelected.emit(new UserValue(selectedUser.id, selectedUser.name, selectedUser.surname, selectedUser.email));
this.userSelected.emit(new UserValue(selectedUser.id, selectedUser.realmId, selectedUser.firstName, selectedUser.lastName, selectedUser.username));
}
this._selectedUsers$.next([...this._currentlySelectedUsers]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ class TestUserComponent extends AbstractMultiUserAssignItemComponent {
template: '<ncc-test-user [user]="user"></ncc-test-user>'
})
class TestWrapperComponent {
user = new UserValue('0', '', '', '');
user = new UserValue('0', 'realmID0', '', '', '');
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class TestUserComponent extends AbstractUserAssignListComponent {
template: '<ncc-test-user [searchUserControl]="formControl"></ncc-test-user>'
})
class TestWrapperComponent {
injectedData = {roles: [], value: new UserValue('5', 'admin', 'netgrif', 'super@netgrif.com')} as UserListInjectedData;
injectedData = {
roles: [],
value: new UserValue('5', 'realmID0', 'admin', 'netgrif', 'super@netgrif.com')
} as UserListInjectedData;
formControl = new FormControl();
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export abstract class AbstractUserAssignListComponent extends AbstractBaseUserAs
* @param selectedUser [UserValue]{@link UserValue}
*/
public select(selectedUser: UserListItem): void {
this.userSelected.emit(new UserValue(selectedUser.id, selectedUser.name, selectedUser.surname, selectedUser.email));
this.userSelected.emit(new UserValue(selectedUser.id, selectedUser.realmId, selectedUser.firstName, selectedUser.lastName, selectedUser.username));
this._markSelectedUser(selectedUser);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ class TestUserComponent extends AbstractUserAssignItemComponent {
template: '<ncc-test-user [user]="user"></ncc-test-user>'
})
class TestWrapperComponent {
user = new UserValue('0', '', '', '');
user = new UserValue('0', 'realmID0', '', '', '');
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ export class FieldConverterService {
case FieldTypeResource.BOOLEAN:
return new BooleanField(item.stringId, item.name, item.value as boolean, item.behavior,
item.placeholder, item.description, item.layout, item.validations, item.component, item.parentTaskId);
case FieldTypeResource.TEXT:
case FieldTypeResource.TEXT: {
if (this.textFieldNames.includes(item.component?.name)) {
return new TextAreaField(item.stringId, item.name, this.resolveTextValue(item, item.value), item.behavior,
item.placeholder, item.description, item.layout, item.validations, item.component, item.parentTaskId);
}
return new TextField(item.stringId, item.name, this.resolveTextValue(item, item.value), item.behavior, item.placeholder,
item.description, item.layout, item.validations, item.component, item.parentTaskId);
}
case FieldTypeResource.NUMBER:
return new NumberField(item.stringId, item.name, item.value as number, item.behavior, item.validations, item.placeholder,
item.description, item.layout, item.formatFilter, this.resolveNumberComponent(item), item.parentTaskId);
Expand All @@ -62,34 +63,38 @@ export class FieldConverterService {
return new MultichoiceField(item.stringId, item.name, item.value, this.resolveMultichoiceOptions(item),
item.behavior, item.placeholder, item.description, item.layout,
item.type, item.validations, item.component, item.parentTaskId);
case FieldTypeResource.DATE:
case FieldTypeResource.DATE: {
let date;
if (item.value) {
date = moment(new Date(item.value[0], item.value[1] - 1, item.value[2]));
}
return new DateField(item.stringId, item.name, date, item.behavior, item.placeholder,
item.description, item.layout, item.validations, item.component, item.parentTaskId);
case FieldTypeResource.DATE_TIME:
}
case FieldTypeResource.DATE_TIME: {
let dateTime;
if (item.value) {
dateTime = moment(new Date(item.value[0], item.value[1] - 1, item.value[2], item.value[3], item.value[4]));
}
return new DateTimeField(item.stringId, item.name, dateTime, item.behavior,
item.placeholder, item.description, item.layout, item.validations, item.component, item.parentTaskId);
case FieldTypeResource.USER:
}
case FieldTypeResource.USER: {
let user;
if (item.value) {
user = new UserValue(item.value.id, item.value.firstName, item.value.lastName, item.value.email);
user = new UserValue(item.value.id, item.value.realmId, item.value.firstName, item.value.lastName, item.value.username);
}
return new UserField(item.stringId, item.name, item.behavior, user,
item.roles, item.placeholder, item.description, item.layout, item.validations, item.component, item.parentTaskId);
case FieldTypeResource.USER_LIST:
}
case FieldTypeResource.USER_LIST: {
let userListValue = new UserListValue(new Map<string, UserValue>());
if (item.value) {
item.value.userValues.forEach(u => userListValue.addUserValue(new UserValue(u.id, u.firstName, u.lastName, u.email)));
item.value.userValues.forEach(u => userListValue.addUserValue(new UserValue(u.id, u.realmId, u.firstName, u.lastName, u.username)));
}
return new UserListField(item.stringId, item.name, item.behavior, userListValue,
item.roles, item.placeholder, item.description, item.layout, item.validations, item.component, item.parentTaskId);
}
case FieldTypeResource.BUTTON:
return new ButtonField(item.stringId, item.name, item.behavior, item.value as number,
item.placeholder, item.description, item.layout, item.validations, item.component, item.parentTaskId);
Expand Down Expand Up @@ -288,7 +293,7 @@ export class FieldConverterService {
return moment(new Date(value[0], value[1] - 1, value[2]));
}
if (this.resolveType(field) === FieldTypeResource.USER) {
return new UserValue(value.id, value.firstName, value.lastName, value.email);
return new UserValue(value.id, value.realmId, value.firstName, value.lastName, value.username);
}
if (this.resolveType(field) === FieldTypeResource.DATE_TIME) {
return moment(new Date(value[0], value[1] - 1, value[2], value[3], value[4]));
Expand Down
Loading
Loading