diff --git a/docs/process-services-cloud/components/people-cloud.component.md b/docs/process-services-cloud/components/people-cloud.component.md index 874021cb87..769e9b242c 100644 --- a/docs/process-services-cloud/components/people-cloud.component.md +++ b/docs/process-services-cloud/components/people-cloud.component.md @@ -1,9 +1,10 @@ ---- -Title: People Cloud Component +* * * + +Title: [People Cloud Component](../../process-services-cloud/components/people-cloud.component.md) Added: v3.0.0 Status: Experimental -Last reviewed: 2019-03-20 ---- + +## Last reviewed: 2019-03-20 # [People Cloud Component](../../../lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts "Defined in people-cloud.component.ts") @@ -22,17 +23,18 @@ Allows one or more users to be selected (with auto-suggestion) based on the inpu ### Properties -| Name | Type | Default value | Description | -| -------------- | -------------------------------------------------------------------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| appName | `string` | | Name of the application. If specified, this shows the users who have access to the app. | -| mode | [`ComponentSelectionMode`](../../../lib/process-services-cloud/src/lib/types.ts) | "single" | [User](../../../lib/core/pipes/user-initial.pipe.ts) selection mode (single/multiple). | -| preSelectUsers | [`IdentityUserModel`](../../../lib/core/models/identity-user.model.ts)`[]` | \[] | Array of users to be pre-selected. All users in the array are pre-selected in multi selection mode, but only the first user is pre-selected in single selection mode. Mandatory properties are: id, email, username | -| readOnly | `boolean` | false | Show the info in readonly mode | -| roles | `string[]` | | Role names of the users to be listed. | -| searchUserCtrl | `FormControl` | | FormControl to search the user | -| title | `string` | | Placeholder translation key | -| userChipsCtrl | `FormControl` | | FormControl to list of users | -| validate | `boolean` | false | This flag enables the validation on the preSelectUsers passed as input. In case the flag is true the components call the [identity service](../../../lib/testing/src/lib/core/actions/identity/identity.service.ts) to verify the validity of the information passed as input. Otherwise, no check will be done. | +| Name | Type | Default value | Description | +| -------------- | -------------------------------------------------------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| appName | `string` | | Name of the application. If specified, this shows the users who have access to the app. | +| excludedUsers | [`IdentityUserModel`](../../../lib/core/models/identity-user.model.ts)`[]` | \[] | Array of users to be excluded. Mandatory properties are: id, email, username | +| mode | [`ComponentSelectionMode`](../../../lib/process-services-cloud/src/lib/types.ts) | "single" | [User](../../../lib/core/pipes/user-initial.pipe.ts) selection mode (single/multiple). | +| preSelectUsers | [`IdentityUserModel`](../../../lib/core/models/identity-user.model.ts)`[]` | \[] | Array of users to be pre-selected. All users in the array are pre-selected in multi selection mode, but only the first user is pre-selected in single selection mode. Mandatory properties are: id, email, username | +| readOnly | `boolean` | false | Show the info in readonly mode | +| roles | `string[]` | | Role names of the users to be listed. | +| searchUserCtrl | `FormControl` | | FormControl to search the user | +| title | `string` | | Placeholder translation key | +| userChipsCtrl | `FormControl` | | FormControl to list of users | +| validate | `boolean` | false | This flag enables the validation on the preSelectUsers passed as input. In case the flag is true the components call the identity service to verify the validity of the information passed as input. Otherwise, no check will be done. | ### Events diff --git a/lib/process-services-cloud/src/lib/people/components/people-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/people/components/people-cloud.component.spec.ts index e1b8b36576..3e8a10a25a 100644 --- a/lib/process-services-cloud/src/lib/people/components/people-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/people/components/people-cloud.component.spec.ts @@ -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 = 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 = 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 = 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(); diff --git a/lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts b/lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts index 9404772f89..03fa20a0f8 100644 --- a/lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts @@ -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 { this.selectedUsers = [];