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
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 @@ -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 @@ -77,8 +77,11 @@ 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.realmId, this._safeTask.user.firstName, this._safeTask.user.lastName, this._safeTask.user.username
// ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commented code if not needed.

value: !this._safeTask.userId ? undefined : new UserValue(
this._safeTask.userId, '', '', ''
this._safeTask.userId, '', '', '', ''
),
negativeRoles: Object.keys(this._safeTask.roles).filter(role =>
this._safeTask.roles[role]['assign'] !== undefined && !this._safeTask.roles[role]['assign'])
Expand Down Expand Up @@ -115,39 +118,39 @@ export class DelegateTaskService extends TaskHandlingService {
this._taskState.startLoading(delegatedTaskId);
this._taskResourceService.delegateTask(this._safeTask.stringId, delegatedUserId).pipe(take(1)).subscribe(
(outcomeResource: EventOutcomeMessageResource) => {
this._taskState.stopLoading(delegatedTaskId);
if (!this.isTaskRelevant(delegatedTaskId)) {
this._log.debug('current task changed before the delegate response could be received, discarding...');
nextEvent.resolve(false);
return;
}
this._taskState.stopLoading(delegatedTaskId);
if (!this.isTaskRelevant(delegatedTaskId)) {
this._log.debug('current task changed before the delegate response could be received, discarding...');
nextEvent.resolve(false);
return;
}

if (outcomeResource.success) {
this._taskContentService.updateStateData(outcomeResource.outcome as DelegateTaskEventOutcome);
const changedFieldsMap: ChangedFieldsMap = this._eventService
.parseChangedFieldsFromOutcomeTree(outcomeResource.outcome);
if (!!changedFieldsMap) {
this._changedFieldsService.emitChangedFields(changedFieldsMap);
if (outcomeResource.success) {
this._taskContentService.updateStateData(outcomeResource.outcome as DelegateTaskEventOutcome);
const changedFieldsMap: ChangedFieldsMap = this._eventService
.parseChangedFieldsFromOutcomeTree(outcomeResource.outcome);
if (!!changedFieldsMap) {
this._changedFieldsService.emitChangedFields(changedFieldsMap);
}
this.completeSuccess(afterAction, nextEvent, outcomeResource.outcome as DelegateTaskEventOutcome);
} else if (outcomeResource.error) {
this._snackBar.openErrorSnackBar(outcomeResource.error);
this.completeActions(afterAction, nextEvent, false);
}
this.completeSuccess(afterAction, nextEvent, outcomeResource.outcome as DelegateTaskEventOutcome);
} else if (outcomeResource.error) {
this._snackBar.openErrorSnackBar(outcomeResource.error);
this.completeActions(afterAction, nextEvent, false);
}
}, error => {
this._taskState.stopLoading(delegatedTaskId);
this._log.debug('getting task data failed', error);
}, error => {
this._taskState.stopLoading(delegatedTaskId);
this._log.debug('getting task data failed', error);

if (!this.isTaskRelevant(delegatedTaskId)) {
this._log.debug('current task changed before the delegate error could be received');
nextEvent.resolve(false);
return;
}
if (!this.isTaskRelevant(delegatedTaskId)) {
this._log.debug('current task changed before the delegate error could be received');
nextEvent.resolve(false);
return;
}

this._snackBar.openErrorSnackBar(`${this._translate.instant('tasks.snackbar.assignTask')}
this._snackBar.openErrorSnackBar(`${this._translate.instant('tasks.snackbar.assignTask')}
${this._task} ${this._translate.instant('tasks.snackbar.failed')}`);
this.completeActions(afterAction, nextEvent, false);
});
this.completeActions(afterAction, nextEvent, false);
});
}

/**
Expand Down
Loading