mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-3750] - add possibility to exclude user from selection on people… (#6277)
* [AAE-3750] - add possibility to exclude user from selection on people cloud component * update docs * PR changes
This commit is contained in:
@@ -181,6 +181,60 @@ describe('PeopleCloudComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not be able to search for a user that his email matches one of the excluded users email', (done) => {
|
||||
component.excludedUsers = [{ email: mockUsers[0].email }];
|
||||
fixture.detectChanges();
|
||||
|
||||
const inputHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
|
||||
inputHTMLElement.focus();
|
||||
inputHTMLElement.value = 'first-name';
|
||||
inputHTMLElement.dispatchEvent(new Event('keyup'));
|
||||
inputHTMLElement.dispatchEvent(new Event('input'));
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.queryAll(By.css('mat-option')).length).toEqual(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not be able to search for a user that his id matches one of the excluded users id', (done) => {
|
||||
component.excludedUsers = [{ email: mockUsers[0].email }];
|
||||
fixture.detectChanges();
|
||||
|
||||
const inputHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
|
||||
inputHTMLElement.focus();
|
||||
inputHTMLElement.value = 'first-name';
|
||||
inputHTMLElement.dispatchEvent(new Event('keyup'));
|
||||
inputHTMLElement.dispatchEvent(new Event('input'));
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.queryAll(By.css('mat-option')).length).toEqual(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not be able to search for a user that his username matches one of the excluded users username', (done) => {
|
||||
component.excludedUsers = [{ email: mockUsers[0].email }];
|
||||
fixture.detectChanges();
|
||||
|
||||
const inputHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
|
||||
inputHTMLElement.focus();
|
||||
inputHTMLElement.value = 'first-name';
|
||||
inputHTMLElement.dispatchEvent(new Event('keyup'));
|
||||
inputHTMLElement.dispatchEvent(new Event('input'));
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.queryAll(By.css('mat-option')).length).toEqual(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should hide result list if input is empty', (done) => {
|
||||
fixture.detectChanges();
|
||||
|
||||
|
@@ -92,6 +92,12 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
|
||||
@Input()
|
||||
preSelectUsers: IdentityUserModel[] = [];
|
||||
|
||||
/** Array of users to be excluded.
|
||||
* Mandatory properties are: id, email, username
|
||||
*/
|
||||
@Input()
|
||||
excludedUsers: IdentityUserModel[] = [];
|
||||
|
||||
/** FormControl to list of users */
|
||||
@Input()
|
||||
userChipsCtrl: FormControl = new FormControl({ value: '', disabled: false });
|
||||
@@ -211,7 +217,7 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
|
||||
this.searchLoading = false;
|
||||
return users;
|
||||
}),
|
||||
filter(user => !this.isUserAlreadySelected(user)),
|
||||
filter(user => !this.isUserAlreadySelected(user) && !this.isExcludedUser(user)),
|
||||
mergeMap(user => {
|
||||
if (this.appName) {
|
||||
return this.checkUserHasAccess(user.id).pipe(
|
||||
@@ -275,6 +281,13 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
|
||||
return false;
|
||||
}
|
||||
|
||||
private isExcludedUser(searchUser: IdentityUserModel): boolean {
|
||||
if (this.excludedUsers?.length > 0) {
|
||||
return !!this.excludedUsers.find(excludedUser => this.compare(excludedUser, searchUser));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private async loadPreSelectUsers(): Promise<void> {
|
||||
this.selectedUsers = [];
|
||||
|
||||
|
Reference in New Issue
Block a user