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

Open
wants to merge 1 commit into
base: release/7.0.0-rev2
Choose a base branch
from
Open
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
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 @@ -6,10 +6,10 @@ describe('UserValue', () => {
let user: UserValue;
user = new UserValue('0', '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 @@ -8,10 +8,10 @@ describe('UserListValue', () => {
let user: UserListValue;
user = new UserListValue(new Map([['0', new UserValue('0', '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', () => {
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 @@ -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 @@ -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 @@ -79,14 +79,14 @@ export class FieldConverterService {
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:
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);
Expand Down Expand Up @@ -288,7 +288,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
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class DelegateTaskService extends TaskHandlingService {
roles: Object.keys(this._safeTask.roles).filter(role =>
this._safeTask.roles[role]['assign'] !== undefined && this._safeTask.roles[role]['assign']),
value: !this._safeTask.user ? undefined : new UserValue(
this._safeTask.user.id, this._safeTask.user.name, this._safeTask.user.surname, this._safeTask.user.email
this._safeTask.user.id, this._safeTask.user.realmId, this._safeTask.user.firstName, this._safeTask.user.lastName, this._safeTask.user.username
),
negativeRoles: Object.keys(this._safeTask.roles).filter(role =>
this._safeTask.roles[role]['assign'] !== undefined && !this._safeTask.roles[role]['assign'])
Expand Down
Loading