From 3b6fcd6cf82a4d2444cb15e7cb9fbc176b227573 Mon Sep 17 00:00:00 2001 From: jourdiw Date: Wed, 15 Jan 2025 17:42:16 +0100 Subject: [PATCH] feat(console): create portal configuration service (cherry picked from commit 6217a154078728f5fa7f1b9de8da18cce2cc8026) # Conflicts: # gravitee-apim-console-webui/src/entities/portal/portalSettings.ts --- .../entities/portal/portalSettings.fixture.ts | 20 +++++++- .../src/entities/portal/portalSettings.ts | 15 +++++- .../portal-configuration.service.spec.ts | 49 +++++++++++++++++++ .../portal-configuration.service.ts | 38 ++++++++++++++ .../services-ngx/portal-settings.service.ts | 5 ++ 5 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 gravitee-apim-console-webui/src/services-ngx/portal-configuration.service.spec.ts create mode 100644 gravitee-apim-console-webui/src/services-ngx/portal-configuration.service.ts diff --git a/gravitee-apim-console-webui/src/entities/portal/portalSettings.fixture.ts b/gravitee-apim-console-webui/src/entities/portal/portalSettings.fixture.ts index 5ac3bbb7404..f08dcd01a3b 100644 --- a/gravitee-apim-console-webui/src/entities/portal/portalSettings.fixture.ts +++ b/gravitee-apim-console-webui/src/entities/portal/portalSettings.fixture.ts @@ -13,10 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { PortalSettings } from './portalSettings'; +import { PortalConfiguration, PortalSettings } from './portalSettings'; export function fakePortalSettings(attributes?: Partial): PortalSettings { const base: PortalSettings = { + ...fakePortalConfiguration(), + cors: { + allowOrigin: ['test.entrypoint.dev', 'test.entrypoint.dev2'], + allowHeaders: ['Cache-Control', 'Pragma'], + allowMethods: ['GET', 'DELETE'], + exposedHeaders: ['ETag', 'X-Xsrf-Token'], + maxAge: 1728000, + }, + }; + + return { + ...base, + ...attributes, + }; +} + +export function fakePortalConfiguration(attributes?: Partial): PortalConfiguration { + const base: PortalConfiguration = { portal: { entrypoint: 'https://api.company.com', apikeyHeader: 'X-Gravitee-Api-Key', diff --git a/gravitee-apim-console-webui/src/entities/portal/portalSettings.ts b/gravitee-apim-console-webui/src/entities/portal/portalSettings.ts index 0dbf79ba780..cdab9d5506f 100644 --- a/gravitee-apim-console-webui/src/entities/portal/portalSettings.ts +++ b/gravitee-apim-console-webui/src/entities/portal/portalSettings.ts @@ -16,7 +16,11 @@ /** * TODO: to complete, contains only one part used in the Ui console */ -export interface PortalSettings { +export interface PortalSettings extends PortalConfiguration { + cors?: PortalSettingsCors; +} + +export interface PortalConfiguration { portal?: PortalSettingsPortal; metadata?: PortalSettingsMetadata; application?: PortalSettingsApplication; @@ -92,6 +96,7 @@ export interface PortalSettingsPortal { }; } +<<<<<<< HEAD export interface PortalApiQualityMetrics { enabled: boolean; functionalDocumentationWeight: number; @@ -115,4 +120,12 @@ export interface PortalSettingsAuthentication { localLogin?: { enabled: boolean; }; +======= +export interface PortalSettingsCors { + allowOrigin: string[]; + allowMethods: string[]; + allowHeaders: string[]; + exposedHeaders: string[]; + maxAge: number; +>>>>>>> 6217a15407 (feat(console): create portal configuration service) } diff --git a/gravitee-apim-console-webui/src/services-ngx/portal-configuration.service.spec.ts b/gravitee-apim-console-webui/src/services-ngx/portal-configuration.service.spec.ts new file mode 100644 index 00000000000..9b1c0ec3c48 --- /dev/null +++ b/gravitee-apim-console-webui/src/services-ngx/portal-configuration.service.spec.ts @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2015 The Gravitee team (http://gravitee.io) + * + * 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 { TestBed } from '@angular/core/testing'; +import { HttpTestingController } from '@angular/common/http/testing'; + +import { PortalConfigurationService } from './portal-configuration.service'; + +import { fakePortalConfiguration } from '../entities/portal/portalSettings.fixture'; +import { CONSTANTS_TESTING, GioHttpTestingModule } from '../shared/testing'; + +describe('PortalConfigurationService', () => { + let service: PortalConfigurationService; + let httpTestingController: HttpTestingController; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [GioHttpTestingModule], + }); + + httpTestingController = TestBed.inject(HttpTestingController); + service = TestBed.inject(PortalConfigurationService); + }); + + describe('getEnvConfiguration', () => { + it('should call the API', (done) => { + const portalConfigurationToGet = fakePortalConfiguration(); + + service.get().subscribe((portalSettings) => { + expect(portalSettings).toMatchObject(portalConfigurationToGet); + done(); + }); + + httpTestingController.expectOne({ method: 'GET', url: `${CONSTANTS_TESTING.env.baseURL}/portal` }).flush(portalConfigurationToGet); + }); + }); +}); diff --git a/gravitee-apim-console-webui/src/services-ngx/portal-configuration.service.ts b/gravitee-apim-console-webui/src/services-ngx/portal-configuration.service.ts new file mode 100644 index 00000000000..33a91ba5916 --- /dev/null +++ b/gravitee-apim-console-webui/src/services-ngx/portal-configuration.service.ts @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2015 The Gravitee team (http://gravitee.io) + * + * 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 { Inject, Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { Observable } from 'rxjs'; + +import { Constants } from '../entities/Constants'; +import { PortalConfiguration } from '../entities/portal/portalSettings'; + +/** + * Portal Configuration Service is to be used to read Portal settings regardless of user permissions + */ +@Injectable({ + providedIn: 'root', +}) +export class PortalConfigurationService { + constructor( + private readonly http: HttpClient, + @Inject('Constants') private readonly constants: Constants, + ) {} + + get(): Observable { + return this.http.get(`${this.constants.env.baseURL}/portal`); + } +} diff --git a/gravitee-apim-console-webui/src/services-ngx/portal-settings.service.ts b/gravitee-apim-console-webui/src/services-ngx/portal-settings.service.ts index 11a40c259de..cfd55ba75cb 100644 --- a/gravitee-apim-console-webui/src/services-ngx/portal-settings.service.ts +++ b/gravitee-apim-console-webui/src/services-ngx/portal-settings.service.ts @@ -23,6 +23,11 @@ import { EnvironmentSettingsService } from './environment-settings.service'; import { Constants } from '../entities/Constants'; import { PortalSettings } from '../entities/portal/portalSettings'; +/** + * Portal Settings Service is used to return the settings for users that have the READ permission for settings at the org or env level + * + * Use {@link portal-configuration.service.ts} to access settings open to all users. + */ @Injectable({ providedIn: 'root', })