mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-1602][AAE-1594] Fix duplicated users issue when validation enabl… (#5413)
* [AAE-1602][AAE-1594] Fix duplicated users issue when validation enabled, fix partial username should not return a valid user * [AAE-1602][AAE-1594] Fix removing incorrect invalid user/group when name or id matches
This commit is contained in:
committed by
Maurizio Vitale
parent
d09373501f
commit
0ae55ba590
@@ -345,22 +345,28 @@ export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
|
|
||||||
onRemove(groupToRemove: IdentityGroupModel) {
|
onRemove(groupToRemove: IdentityGroupModel) {
|
||||||
this.removeGroup.emit(groupToRemove);
|
this.removeGroup.emit(groupToRemove);
|
||||||
const indexToRemove = this.selectedGroups.findIndex((group: IdentityGroupModel) => {
|
this.removeGroupFromSelected(groupToRemove);
|
||||||
return group.id === groupToRemove.id;
|
|
||||||
});
|
|
||||||
this.selectedGroups.splice(indexToRemove, 1);
|
|
||||||
this.changedGroups.emit(this.selectedGroups);
|
this.changedGroups.emit(this.selectedGroups);
|
||||||
this.searchGroupsControl.markAsDirty();
|
this.searchGroupsControl.markAsDirty();
|
||||||
|
|
||||||
if (this.isValidationEnabled()) {
|
if (this.isValidationEnabled()) {
|
||||||
this.removeGroupFromValidation(groupToRemove.name);
|
this.removeGroupFromValidation(groupToRemove);
|
||||||
this.checkPreselectValidationErrors();
|
this.checkPreselectValidationErrors();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private removeGroupFromValidation(groupName: string) {
|
private removeGroupFromSelected(groupToRemove: IdentityGroupModel) {
|
||||||
|
const indexToRemove = this.selectedGroups.findIndex((selectedGroup: IdentityGroupModel) => {
|
||||||
|
return selectedGroup.id === groupToRemove.id && selectedGroup.name === groupToRemove.name;
|
||||||
|
});
|
||||||
|
if (indexToRemove !== -1) {
|
||||||
|
this.selectedGroups.splice(indexToRemove, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private removeGroupFromValidation(groupToRemove: IdentityGroupModel) {
|
||||||
const indexToRemove = this.invalidGroups.findIndex((invalidGroup) => {
|
const indexToRemove = this.invalidGroups.findIndex((invalidGroup) => {
|
||||||
return invalidGroup.name === groupName;
|
return invalidGroup.name === groupToRemove.name && invalidGroup.id === groupToRemove.id;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (indexToRemove !== -1) {
|
if (indexToRemove !== -1) {
|
||||||
|
@@ -133,7 +133,7 @@ describe('PeopleCloudComponent', () => {
|
|||||||
it('should selectedUser and changedUsers emit, update selected users when a user is selected', (done) => {
|
it('should selectedUser and changedUsers emit, update selected users when a user is selected', (done) => {
|
||||||
const user = { username: 'username' };
|
const user = { username: 'username' };
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
spyOn(component, 'hasUserDetails').and.returnValue(true);
|
spyOn(component, 'isPreselectedUserValid').and.returnValue(true);
|
||||||
const selectEmitSpy = spyOn(component.selectUser, 'emit');
|
const selectEmitSpy = spyOn(component.selectUser, 'emit');
|
||||||
const changedUsersSpy = spyOn(component.changedUsers, 'emit');
|
const changedUsersSpy = spyOn(component.changedUsers, 'emit');
|
||||||
component.onSelect(user);
|
component.onSelect(user);
|
||||||
@@ -514,7 +514,7 @@ describe('PeopleCloudComponent', () => {
|
|||||||
|
|
||||||
it('should check validation only for the first user and emit warning when user is invalid - single mode', (done) => {
|
it('should check validation only for the first user and emit warning when user is invalid - single mode', (done) => {
|
||||||
spyOn(identityService, 'findUserById').and.returnValue(Promise.resolve([]));
|
spyOn(identityService, 'findUserById').and.returnValue(Promise.resolve([]));
|
||||||
spyOn(component, 'hasUserDetails').and.returnValue(false);
|
spyOn(component, 'isPreselectedUserValid').and.returnValue(false);
|
||||||
|
|
||||||
const expectedWarning = {
|
const expectedWarning = {
|
||||||
message: 'INVALID_PRESELECTED_USERS',
|
message: 'INVALID_PRESELECTED_USERS',
|
||||||
|
@@ -298,11 +298,12 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
|
|
||||||
await Promise.all(preselectedUsersToValidate.map(async (user: IdentityUserModel) => {
|
await Promise.all(preselectedUsersToValidate.map(async (user: IdentityUserModel) => {
|
||||||
try {
|
try {
|
||||||
const validationResult = await this.searchUser(user);
|
const validationResult: IdentityUserModel = await this.searchUser(user);
|
||||||
if (!this.hasUserDetails(validationResult)) {
|
if (this.isPreselectedUserValid(user, validationResult)) {
|
||||||
this.invalidUsers.push(user);
|
validationResult.readonly = user.readonly;
|
||||||
} else {
|
|
||||||
validUsers.push(validationResult);
|
validUsers.push(validationResult);
|
||||||
|
} else {
|
||||||
|
this.invalidUsers.push(user);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.invalidUsers.push(user);
|
this.invalidUsers.push(user);
|
||||||
@@ -310,20 +311,16 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
this.checkPreselectValidationErrors();
|
this.checkPreselectValidationErrors();
|
||||||
this.alignUsersAfterValidation(validUsers);
|
this.selectedUsers = validUsers.concat(this.invalidUsers);
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private alignUsersAfterValidation(validatedUsers: IdentityUserModel[]) {
|
isPreselectedUserValid(preselectedUser: IdentityUserModel, validatedUser: IdentityUserModel) {
|
||||||
this.selectedUsers.forEach((selectedUser, index) => {
|
if (validatedUser && (validatedUser.id !== undefined || validatedUser.username !== undefined || validatedUser.email !== undefined)) {
|
||||||
validatedUsers.forEach(validatedUser => {
|
return preselectedUser.id === validatedUser.id || preselectedUser.username === validatedUser.username || preselectedUser.email === validatedUser.email;
|
||||||
if ((selectedUser.id === validatedUser.id) || (selectedUser.username === validatedUser.username)
|
} else {
|
||||||
|| (selectedUser.email === validatedUser.email)) {
|
return false;
|
||||||
validatedUser.readonly = selectedUser.readonly;
|
|
||||||
this.selectedUsers[index] = validatedUser;
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchUser(user: IdentityUserModel) {
|
async searchUser(user: IdentityUserModel) {
|
||||||
@@ -390,22 +387,28 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
|
|
||||||
onRemove(userToRemove: IdentityUserModel) {
|
onRemove(userToRemove: IdentityUserModel) {
|
||||||
this.removeUser.emit(userToRemove);
|
this.removeUser.emit(userToRemove);
|
||||||
const indexToRemove = this.selectedUsers.findIndex((selectedUser: IdentityUserModel) => {
|
this.removeUserFromSelected(userToRemove);
|
||||||
return selectedUser.id === userToRemove.id;
|
|
||||||
});
|
|
||||||
this.selectedUsers.splice(indexToRemove, 1);
|
|
||||||
this.changedUsers.emit(this.selectedUsers);
|
this.changedUsers.emit(this.selectedUsers);
|
||||||
this.searchUserCtrl.markAsDirty();
|
this.searchUserCtrl.markAsDirty();
|
||||||
|
|
||||||
if (this.isValidationEnabled()) {
|
if (this.isValidationEnabled()) {
|
||||||
this.removeUserFromValidation(userToRemove.username);
|
this.removeUserFromValidation(userToRemove);
|
||||||
this.checkPreselectValidationErrors();
|
this.checkPreselectValidationErrors();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private removeUserFromValidation(username: string) {
|
private removeUserFromSelected(userToRemove: IdentityUserModel) {
|
||||||
|
const indexToRemove = this.selectedUsers.findIndex((selectedUser: IdentityUserModel) => {
|
||||||
|
return selectedUser.id === userToRemove.id && selectedUser.username === userToRemove.username && selectedUser.email === userToRemove.email;
|
||||||
|
});
|
||||||
|
if (indexToRemove !== -1) {
|
||||||
|
this.selectedUsers.splice(indexToRemove, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private removeUserFromValidation(userToRemove: IdentityUserModel) {
|
||||||
const indexToRemove = this.invalidUsers.findIndex((invalidUser) => {
|
const indexToRemove = this.invalidUsers.findIndex((invalidUser) => {
|
||||||
return invalidUser.username === username;
|
return invalidUser.username === userToRemove.username && invalidUser.id === userToRemove.id && invalidUser.email === userToRemove.email;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (indexToRemove !== -1) {
|
if (indexToRemove !== -1) {
|
||||||
@@ -413,10 +416,6 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hasUserDetails(user: IdentityUserModel): boolean {
|
|
||||||
return user && (user.id !== undefined || user.username !== undefined || user.email !== undefined);
|
|
||||||
}
|
|
||||||
|
|
||||||
generateInvalidUsersMessage() {
|
generateInvalidUsersMessage() {
|
||||||
this.validateUsersMessage = '';
|
this.validateUsersMessage = '';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user