mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-10-01 14:41:32 +00:00
* [AAE-12501] Provide an AlfrescoApiService implementation that disable the AlfrescoApi oauth initialization when we use new oidc implementation * [AAE-12501] Replace oauth2Auth with authentication service, define get username as abstract * [AAE-12501] Replace sitesService with authentication service since sitesService get the username from oauth2Auth * [AAE-12501] Call implicitLogin by authentication service * [AAE-12501] Replace Oauth2Auth with AlfrescoApi and call the custom api without using authentication * [AAE-12501] Replace oauth2Auth with authentication service to get the token * [AAE-12501] Replace oauth2Auth with alfrescoApi * remove unneeded JS-API dep move auth in the right place * [AAE-10501] Rename alfresco-api.http-client to adf-http-client * [AAE-10501] Remove config from a CoreModule, a different service is provided in AuthModule to use angular http client instead of super agent * [AAE-10501] Disable AlfrescoApi oauth initialization while using new adf oidc authentication * [AAE-12501] Replace alfresco api client with AdfHttpClient * [AAE-12501] Restore get username methods * [AAE-12501] Get username with authentication service * [AAE-12501] removee unused method * [AAE-12501] Trigger on login when token is received * [AAE-12501] Fix content-services unit test * [AAE-12501] Fix import * [AAE-12501] Fix core unit tests * [AAE-12501] Fix process-services-cloud unit tests * [AAE-12501] Create a request options interface with the needed props, remove the import from js-api, return the body from request * [AAE-12501] Fix process-services-cloud unit tests without Expectation * [AAE-12501] Fix Core secondary entrypoints unit tests are not executed: move test.ts one level up in order to find all the spec files into the secondary entrypoints folders and update path * [AAE-12501] Fix Core unit tests that weren't executed because of the previous test.ts wrong location * [AAE-12501] Fix authentication token_issued subscription * add emitters * [AAE-12501] Replace Math.random() to fix hospot security issue, fix lint issues * [AAE-12501] Install event-emitter dependency * [AAE-12501] Comment temporary setCsrfToken because is not possible to import app config service from core due to circular dependencies * [AAE-12501] Get disableCsrf from app config serviice when app configuration is loaded * [AAE-12501] Fix license-header lint issue * [AAE-14221] Regenerate lock file * [AAE-14221] Fix sonarcloud issues * [AAE-12501] Remove wrong character * [AAE-12501] Regenerate lock file * [AAE-12501] Fix BC: update alfresco api response error --------- Co-authored-by: eromano <eugenioromano16@gmail.com>
114 lines
4.0 KiB
TypeScript
114 lines
4.0 KiB
TypeScript
/*!
|
|
* @license
|
|
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
|
*
|
|
* 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 { Observable, from, throwError, of } from 'rxjs';
|
|
import { map, catchError } from 'rxjs/operators';
|
|
import { AppConfigService, LogService } from '@alfresco/adf-core';
|
|
import { ApplicationInstanceModel } from '../models/application-instance.model';
|
|
import { Environment } from '../../common/interface/environment.interface';
|
|
import { AdfHttpClient } from '@alfresco/adf-core/api';
|
|
import { RequestOptions } from '@alfresco/js-api';
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class AppsProcessCloudService {
|
|
|
|
deployedApps: ApplicationInstanceModel[];
|
|
|
|
constructor(
|
|
private adfHttpClient: AdfHttpClient,
|
|
private logService: LogService,
|
|
private appConfigService: AppConfigService) {
|
|
this.loadApps();
|
|
}
|
|
|
|
/**
|
|
* Gets a list of deployed apps for this user by status.
|
|
*
|
|
* @param status Required status value
|
|
* @param role to filter the apps
|
|
* @returns The list of deployed apps
|
|
*/
|
|
getDeployedApplicationsByStatus(status: string, role?: string): Observable<ApplicationInstanceModel[]> {
|
|
return this.hasDeployedApps() ? of(this.deployedApps) : this.getApplicationsByStatus(status, role);
|
|
}
|
|
|
|
hasDeployedApps(): boolean {
|
|
return this.deployedApps && this.deployedApps.length > 0;
|
|
}
|
|
|
|
loadApps() {
|
|
const apps = this.appConfigService.get<any>('alfresco-deployed-apps', []);
|
|
apps.map((app) => {
|
|
app.theme = app.theme ? app.theme : 'theme-1';
|
|
app.icon = app.icon ? app.icon : 'favorite';
|
|
});
|
|
this.deployedApps = apps;
|
|
}
|
|
|
|
getApplicationLabel(application: ApplicationInstanceModel, environmentList?: Environment[]): string {
|
|
const envName = environmentList?.find((env: Environment) => env.id === application.environmentId)?.name;
|
|
|
|
if (application.environmentId && environmentList && envName) {
|
|
return `${application.displayName} (${envName})`;
|
|
} else {
|
|
return application.displayName;
|
|
}
|
|
}
|
|
|
|
private getApplicationsByStatus(status: string, role?: string): Observable<ApplicationInstanceModel[]> {
|
|
if (status === '') {
|
|
return of([]);
|
|
}
|
|
const path = this.getApplicationUrl();
|
|
const pathParams = {};
|
|
const queryParams = { status, roles : role, sort: 'name' };
|
|
const httpMethod = 'GET';
|
|
const headerParams = {};
|
|
const formParams = {};
|
|
const bodyParam = {};
|
|
const contentTypes = ['application/json'];
|
|
const accepts = ['application/json'];
|
|
const requestOptions: RequestOptions = {
|
|
path,
|
|
pathParams,
|
|
queryParams,
|
|
headerParams,
|
|
formParams,
|
|
bodyParam,
|
|
contentTypes,
|
|
accepts,
|
|
httpMethod
|
|
};
|
|
|
|
return from(this.adfHttpClient.request(path, requestOptions))
|
|
.pipe(
|
|
map((applications: any) => applications.list.entries.map((application) => application.entry)),
|
|
catchError((err) => this.handleError(err))
|
|
);
|
|
}
|
|
|
|
private getApplicationUrl(): string {
|
|
return `${this.appConfigService.get('bpmHost')}/deployment-service/v1/applications`;
|
|
}
|
|
|
|
private handleError(error?: any) {
|
|
this.logService.error(error);
|
|
return throwError(error || 'Server error');
|
|
}
|
|
}
|