mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4003] Add roles filtering to PeopleCloudComponent (#4261)
* Provided a way to filter users bya specifi role.
This commit is contained in:
committed by
Maurizio Vitale
parent
da379eefd7
commit
f373c28965
@@ -248,4 +248,50 @@ describe('PeopleCloudComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should return true if user has any specified role', async(() => {
|
||||
const checkUserHasRoleSpy = spyOn(identityService, 'checkUserHasRole').and.returnValue(of(true));
|
||||
component.roles = ['mock-role-1'];
|
||||
fixture.detectChanges();
|
||||
let inputHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
|
||||
inputHTMLElement.focus();
|
||||
inputHTMLElement.value = 'M';
|
||||
inputHTMLElement.dispatchEvent(new Event('input'));
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(checkUserHasRoleSpy).toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should return false if user does not have any specified role', async(() => {
|
||||
const checkUserHasRoleSpy = spyOn(identityService, 'checkUserHasRole').and.returnValue(of(false));
|
||||
component.appName = '';
|
||||
component.roles = ['mock-role-10'];
|
||||
fixture.detectChanges();
|
||||
let inputHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
|
||||
inputHTMLElement.focus();
|
||||
inputHTMLElement.value = 'M';
|
||||
inputHTMLElement.dispatchEvent(new Event('input'));
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(checkUserHasRoleSpy).toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not fire checkUserHasRole when roles are not specified', async(() => {
|
||||
const checkUserHasRoleSpy = spyOn(identityService, 'checkUserHasRole').and.returnValue(of(false));
|
||||
component.appName = '';
|
||||
component.roles = [];
|
||||
fixture.detectChanges();
|
||||
let inputHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
|
||||
inputHTMLElement.focus();
|
||||
inputHTMLElement.value = 'M';
|
||||
inputHTMLElement.dispatchEvent(new Event('input'));
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(checkUserHasRoleSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
@@ -148,6 +148,8 @@ export class PeopleCloudComponent implements OnInit {
|
||||
return hasRole ? of(user) : of();
|
||||
})
|
||||
);
|
||||
} else if (this.hasRoles()) {
|
||||
return this.filterUsersByRoles(user);
|
||||
} else {
|
||||
return of(user);
|
||||
}
|
||||
@@ -170,6 +172,14 @@ export class PeopleCloudComponent implements OnInit {
|
||||
return this.roles && this.roles.length > 0;
|
||||
}
|
||||
|
||||
filterUsersByRoles(user: IdentityUserModel): Observable<IdentityUserModel> {
|
||||
return this.identityUserService.checkUserHasRole(user.id, this.roles).pipe(
|
||||
mergeMap((hasRole) => {
|
||||
return hasRole ? of(user) : of();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private isUserAlreadySelected(user: IdentityUserModel): boolean {
|
||||
if (this.preSelectUsers && this.preSelectUsers.length > 0) {
|
||||
const result = this.preSelectUsers.find((selectedUser) => {
|
||||
|
Reference in New Issue
Block a user