[AAE-9019] - People/Group cloud with HxP (#7658)

* Cover the use cases by mocking them

* Replace the mock with real stream and remove useless code

* Provide new service to fetch groups

* Fix group tests

* Use the interface and token injection

* [AAE-8870] add unit test and mock for new service

* Improve roles condifion

* initialize the stream as part of NgOnInit to be sure it relies on the correct FormControl instance(input)

* Rollback tmp change for roles

* [AAE-8641] people abstraction mock

* [AAE-8641] revert angular.json changes

* [AAE-8641] few conditions and code improvements

* [AAE-8641] revert change input controls name

* [AAE-8641] initialize the stream as part of ngOnInit

* [AAE-8641] people abstraction improvements

* [AAE-8870] cherry pick people abstraction

* [AAE-8641] fix people-group e2es

* fix lint

* remove hardcoded identityHost

* Use the identityhost api in case of cloud

* Solve issue with returnType array string

* Rebase and use GroupModel from cloud

* Rebase and use GroupModel from cloud

* Use the bpmHost instead of identityFor

* Add identity ingress for user access service

* Rename test

* Fix linting issues

* Fix playwright storybook e2e for people and group

* Trigger travis

* Fix people group e2e

* improved formatting

* Remove not needed travis var override

* Remove unused import after rebase

* Make roles in filter optional + remove comments

Co-authored-by: Tomasz <tomasz.gnyp@hyland.com>
Co-authored-by: arditdomi <ardit.domi@hyland.com>
This commit is contained in:
Maurizio Vitale
2022-06-28 16:21:59 +01:00
committed by GitHub
parent 93c5619e23
commit e27833d770
72 changed files with 2117 additions and 1937 deletions

View File

@@ -0,0 +1,111 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Injectable } from '@angular/core';
import { AppConfigService, OAuth2Service } from '@alfresco/adf-core';
import { EMPTY, Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { IdentityGroupServiceInterface } from './identity-group.service.interface';
import { IdentityGroupFilterInterface } from './identity-group-filter.interface';
import { IdentityGroupModel } from '../models/identity-group.model';
const IDENTITY_MICRO_SERVICE_INGRESS = 'modeling-service';
@Injectable({ providedIn: 'root' })
export class IdentityGroupService implements IdentityGroupServiceInterface {
queryParams: { search: string; application?: string; roles?: string [] };
constructor(
private oAuth2Service: OAuth2Service,
private appConfigService: AppConfigService
) {}
public search(name: string, filters?: IdentityGroupFilterInterface): Observable<IdentityGroupModel[]> {
if (name.trim() === '') {
return EMPTY;
} else if (filters?.withinApplication) {
return this.searchGroupsWithinApp(name, filters.withinApplication, filters?.roles);
} else if (filters?.roles?.length > 0) {
return this.searchGroupsWithGlobalRoles(name, filters.roles);
} else {
return this.searchGroupsByName(name);
}
}
private searchGroupsByName(name: string): Observable<IdentityGroupModel[]> {
this.buildQueryParam(name);
return this.invokeIdentityGroupApi().pipe(
catchError((err) => this.handleError(err))
);
}
private searchGroupsWithGlobalRoles(name: string, roles: string []): Observable<IdentityGroupModel[]> {
this.buildQueryParam(name, roles);
return this.invokeIdentityGroupApi().pipe(
catchError((err) => this.handleError(err))
);
}
private searchGroupsWithinApp(name: string, applicationName: string, roles?: string []): Observable<IdentityGroupModel[]> {
this.buildQueryParam(name, roles, applicationName);
return this.invokeIdentityGroupApi().pipe(
catchError((err) => this.handleError(err))
);
}
private invokeIdentityGroupApi(): Observable<IdentityGroupModel[]> {
const url = `${this.identityHost}/${IDENTITY_MICRO_SERVICE_INGRESS}/v1/identity/groups`;
return this.oAuth2Service.get({ url, queryParams: this.queryParams });
}
private buildQueryParam(name: string, roles?: string [], applicationName?: string) {
this.queryParams = { search: name };
this.addOptionalValueToQueryParam('application', applicationName);
this.addOptionalCommaValueToQueryParam('role', roles);
}
private addOptionalCommaValueToQueryParam(key: string, values: string []) {
if (values?.length > 0) {
const valuesNotEmpty = this.filterOutEmptyValue(values);
if (valuesNotEmpty?.length > 0) {
this.queryParams[key] = valuesNotEmpty.join(',');
}
}
}
private addOptionalValueToQueryParam(key: string, value: string) {
if (value?.trim()) {
this.queryParams[key] = value;
}
}
private filterOutEmptyValue(roles: string []): string [] {
return roles.filter( role => role.trim() ? true : false);
}
private handleError(error: any) {
return throwError(error || 'Server error');
}
private get identityHost(): string {
return `${this.appConfigService.get('bpmHost')}`;
}
}