mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-8061] Fix the group restriction for people widget (#7601)
* FIx the restrinction * Fix unit test about restricted groups * Add a small sleep to make it green * Add sleep to other checks * Remove sleeps, improve assertions Co-authored-by: MichalFidor <michal.fidor@hyland.com>
This commit is contained in:
@@ -824,6 +824,8 @@ describe('PeopleCloudComponent', () => {
|
||||
});
|
||||
|
||||
describe('Groups restriction', () => {
|
||||
const GROUP_1 = 0;
|
||||
const GROUP_2 = 1;
|
||||
|
||||
beforeEach(() => {
|
||||
fixture.detectChanges();
|
||||
@@ -831,8 +833,8 @@ describe('PeopleCloudComponent', () => {
|
||||
});
|
||||
|
||||
it('Shoud display all users if groups restriction is empty', async () => {
|
||||
getInvolvedGroupsSpy = spyOn(identityService, 'getInvolvedGroups').and.returnValue(of(mockInvolvedGroups));
|
||||
component.groupsRestriction = [];
|
||||
getInvolvedGroupsSpy = spyOn(identityService, 'getInvolvedGroups').and.returnValue(of({name: 'fire'}));
|
||||
typeInputValue('M');
|
||||
|
||||
await fixture.whenStable();
|
||||
@@ -842,21 +844,41 @@ describe('PeopleCloudComponent', () => {
|
||||
expect(fixture.debugElement.queryAll(By.css('[data-automation-id="adf-people-cloud-row"]')).length).toEqual(mockUsers.length);
|
||||
});
|
||||
|
||||
it('Should display users that belongs to restricted groups', async () => {
|
||||
getInvolvedGroupsSpy = spyOn(identityService, 'getInvolvedGroups').and.returnValue(of(mockInvolvedGroups));
|
||||
component.groupsRestriction = [mockInvolvedGroups[0].name, mockInvolvedGroups[1].name];
|
||||
it('Should display users that belongs to every restricted groups', async () => {
|
||||
component.groupsRestriction = ['water', 'fire', 'air'];
|
||||
getInvolvedGroupsSpy = spyOn(identityService, 'getInvolvedGroups').and.returnValue(of([{name: 'fire'}, {name: 'air'}, {name: 'water'}]));
|
||||
typeInputValue('M');
|
||||
|
||||
await fixture.whenStable();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(getInvolvedGroupsSpy).toHaveBeenCalledTimes(3);
|
||||
expect(fixture.debugElement.queryAll(By.css('[data-automation-id="adf-people-cloud-row"]')).length).toEqual(mockUsers.length);
|
||||
const userList = fixture.debugElement.queryAll(By.css('[data-automation-id="adf-people-cloud-row"]'));
|
||||
expect(userList.length).toEqual(3);
|
||||
});
|
||||
|
||||
it('Should not display users that not belongs to restricted groups', async () => {
|
||||
getInvolvedGroupsSpy = spyOn(identityService, 'getInvolvedGroups').and.returnValue(of([mockInvolvedGroups[0]]));
|
||||
component.groupsRestriction = [mockInvolvedGroups[0].name, mockInvolvedGroups[1].name];
|
||||
it('Should not display user if belong to partial restricted groups', async () => {
|
||||
component.groupsRestriction = ['water', 'fire', 'air'];
|
||||
getInvolvedGroupsSpy = spyOn(identityService, 'getInvolvedGroups').and.returnValue(of([{name: 'fire'}, {name: 'water'}]));
|
||||
typeInputValue('M');
|
||||
|
||||
await fixture.whenStable();
|
||||
fixture.detectChanges();
|
||||
const userList = fixture.debugElement.queryAll(By.css('[data-automation-id="adf-people-cloud-row"]'));
|
||||
expect(userList.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('Should not display user if belong to none of the restricted groups', async () => {
|
||||
component.groupsRestriction = ['water', 'fire', 'air'];
|
||||
getInvolvedGroupsSpy = spyOn(identityService, 'getInvolvedGroups').and.returnValue(of([]));
|
||||
typeInputValue('M');
|
||||
|
||||
await fixture.whenStable();
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.queryAll(By.css('[data-automation-id="adf-people-cloud-row"]')).length).toEqual(0);
|
||||
});
|
||||
|
||||
it('Should not be able to see a user that does not belong to the restricted group', async () => {
|
||||
component.groupsRestriction = ['water'];
|
||||
getInvolvedGroupsSpy = spyOn(identityService, 'getInvolvedGroups').and.returnValue(of([{name: 'fire'}]));
|
||||
typeInputValue('M');
|
||||
|
||||
await fixture.whenStable();
|
||||
@@ -867,7 +889,7 @@ describe('PeopleCloudComponent', () => {
|
||||
|
||||
it('Should mark as invalid preselected user if is not belongs to restricted groups', (done) => {
|
||||
spyOn(identityService, 'findUserById').and.returnValue(of(mockPreselectedUsers[0]));
|
||||
getInvolvedGroupsSpy = spyOn(identityService, 'getInvolvedGroups').and.returnValue(of([mockInvolvedGroups[0]]));
|
||||
getInvolvedGroupsSpy = spyOn(identityService, 'getInvolvedGroups').and.returnValue(of([mockInvolvedGroups[GROUP_1]]));
|
||||
|
||||
const expectedWarning = {
|
||||
message: 'INVALID_PRESELECTED_USERS',
|
||||
@@ -882,7 +904,7 @@ describe('PeopleCloudComponent', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
component.groupsRestriction = [mockInvolvedGroups[0].name, mockInvolvedGroups[1].name];
|
||||
component.groupsRestriction = [mockInvolvedGroups[GROUP_1].name, mockInvolvedGroups[GROUP_2].name];
|
||||
component.mode = 'single';
|
||||
component.validate = true;
|
||||
component.preSelectUsers = [mockPreselectedUsers[0]];
|
||||
|
@@ -33,7 +33,6 @@ import { Observable, of, BehaviorSubject, Subject } from 'rxjs';
|
||||
import { switchMap, debounceTime, distinctUntilChanged, mergeMap, tap, filter, map, takeUntil } from 'rxjs/operators';
|
||||
import {
|
||||
FullNamePipe,
|
||||
IdentityGroupModel,
|
||||
IdentityUserModel,
|
||||
IdentityUserService,
|
||||
LogService
|
||||
@@ -563,15 +562,13 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
|
||||
|
||||
private isUserPartOfAllRestrictedGroups(user: IdentityUserModel): Observable<boolean> {
|
||||
return this.getUserGroups(user.id).pipe(
|
||||
map(userGroups => userGroups.filter(
|
||||
restrictedGroup => userGroups.includes(restrictedGroup)
|
||||
).length >= this.groupsRestriction.length)
|
||||
map(userGroups => this.groupsRestriction.every(restricted => userGroups.includes(restricted)))
|
||||
);
|
||||
}
|
||||
|
||||
private getUserGroups(userId: string): Observable<IdentityGroupModel[]> {
|
||||
private getUserGroups(userId: string): Observable<string[]> {
|
||||
return this.identityUserService.getInvolvedGroups(userId).pipe(
|
||||
map(groups => groups.map(({id, name}) => ({id, name})))
|
||||
map(groups => groups.map((group) => group.name))
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -15,8 +15,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { IdentityGroupModel } from '@alfresco/adf-core';
|
||||
|
||||
export const mockUsers = [
|
||||
{ id: 'fake-id-1', username: 'first-name-1 last-name-1', firstName: 'first-name-1', lastName: 'last-name-1', email: 'abc@xyz.com' },
|
||||
{ id: 'fake-id-2', username: 'first-name-2 last-name-2', firstName: 'first-name-2', lastName: 'last-name-2', email: 'abcd@xyz.com'},
|
||||
@@ -49,6 +47,6 @@ export const mockPreselectedUsers = [
|
||||
];
|
||||
|
||||
export const mockInvolvedGroups = [
|
||||
{ id: 'mock-group-id-1', name: 'Mock Group 1', path: '/mock', subGroups: [] } as IdentityGroupModel,
|
||||
{ id: 'mock-group-id-2', name: 'Mock Group 2', path: '', subGroups: [] } as IdentityGroupModel
|
||||
{ id: 'mock-group-id-1', name: 'Mock Group 1', path: '/mock', subGroups: [] },
|
||||
{ id: 'mock-group-id-2', name: 'Mock Group 2', path: '', subGroups: [] }
|
||||
];
|
||||
|
@@ -19,9 +19,9 @@ import { by, element, $, ElementFinder, $$ } from 'protractor';
|
||||
import { BrowserVisibility } from '../../core/utils/browser-visibility';
|
||||
import { BrowserActions } from '../../core/utils/browser-actions';
|
||||
import { FormFields } from '../../core/pages/form/form-fields';
|
||||
import { TestElement } from '../../core/test-element';
|
||||
|
||||
export class GroupCloudComponentPage {
|
||||
|
||||
groupCloudSearch = $('input[data-automation-id="adf-cloud-group-search-input"]');
|
||||
groupField = $('group-cloud-widget .adf-readonly');
|
||||
formFields = new FormFields();
|
||||
@@ -29,11 +29,11 @@ export class GroupCloudComponentPage {
|
||||
getGroupRowLocatorByName = async (name: string): Promise<ElementFinder> => $$(`mat-option[data-automation-id="adf-cloud-group-chip-${name}"]`).first();
|
||||
|
||||
async searchGroups(name: string): Promise<void> {
|
||||
await BrowserActions.clearSendKeys(this.groupCloudSearch, name);
|
||||
await BrowserActions.clearSendKeys(this.groupCloudSearch, name, 100);
|
||||
}
|
||||
|
||||
async searchGroupsToExisting(name: string) {
|
||||
await BrowserActions.clearSendKeys(this.groupCloudSearch, name);
|
||||
await BrowserActions.clearSendKeys(this.groupCloudSearch, name, 100);
|
||||
}
|
||||
|
||||
async getGroupsFieldContent(): Promise<string> {
|
||||
@@ -57,8 +57,13 @@ export class GroupCloudComponentPage {
|
||||
await BrowserVisibility.waitUntilElementIsNotVisible(groupRow);
|
||||
}
|
||||
|
||||
async checkSelectedGroup(group: string): Promise<void> {
|
||||
await BrowserVisibility.waitUntilElementIsVisible(element(by.cssContainingText('mat-chip[data-automation-id*="adf-cloud-group-chip-"]', group)));
|
||||
async checkSelectedGroup(group: string): Promise<boolean> {
|
||||
try {
|
||||
await TestElement.byText('mat-chip[data-automation-id*="adf-cloud-group-chip-"]', group).waitVisible();
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
async checkGroupNotSelected(group: string): Promise<void> {
|
||||
|
@@ -22,7 +22,6 @@ import { FormFields } from '../../core/pages/form/form-fields';
|
||||
import { TestElement } from '../../core/test-element';
|
||||
|
||||
export class PeopleCloudComponentPage {
|
||||
|
||||
peopleCloudSearch = $('input[data-automation-id="adf-people-cloud-search-input"]');
|
||||
assigneeField = $('input[data-automation-id="adf-people-cloud-search-input"]');
|
||||
selectionReady = $('div[data-automation-id="adf-people-cloud-row"]');
|
||||
@@ -50,7 +49,7 @@ export class PeopleCloudComponentPage {
|
||||
}
|
||||
|
||||
async searchAssignee(name: string): Promise<void> {
|
||||
await BrowserActions.clearSendKeys(this.peopleCloudSearch, name);
|
||||
await BrowserActions.clearSendKeys(this.peopleCloudSearch, name, 100);
|
||||
}
|
||||
|
||||
async selectAssigneeFromList(name: string): Promise<void> {
|
||||
@@ -103,8 +102,13 @@ export class PeopleCloudComponentPage {
|
||||
await BrowserVisibility.waitUntilElementIsNotVisible(optionList);
|
||||
}
|
||||
|
||||
async checkSelectedPeople(person: string): Promise<void> {
|
||||
await BrowserVisibility.waitUntilElementIsVisible(element(by.cssContainingText('mat-chip-list mat-chip', person)));
|
||||
async checkSelectedPeople(person: string): Promise<boolean> {
|
||||
try {
|
||||
await TestElement.byText('mat-chip-list mat-chip', person).waitVisible();
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async getAssigneeFieldContent(): Promise<string> {
|
||||
@@ -163,9 +167,13 @@ export class PeopleCloudComponentPage {
|
||||
}
|
||||
}
|
||||
|
||||
async checkNoResultsFoundError(): Promise<void> {
|
||||
const errorLocator = $('[data-automation-id="adf-people-cloud-no-results"]');
|
||||
await BrowserVisibility.waitUntilElementIsVisible(errorLocator);
|
||||
async checkNoResultsFoundError(): Promise<boolean> {
|
||||
try {
|
||||
await TestElement.byCss('[data-automation-id="adf-people-cloud-no-results"]').waitVisible();
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user