From f19ce2e8f8be76103e2ebd988de80eab49670d0d Mon Sep 17 00:00:00 2001 From: cmoinier Date: Wed, 27 Nov 2024 12:24:52 +0100 Subject: [PATCH] feat: make settings url configurable --- apps/metadata-editor/src/app/app.module.ts | 5 +++++ .../src/app/dashboard/sidebar/sidebar.component.ts | 5 +---- conf/default.toml | 1 + .../src/lib/gn4/auth/auth.service.spec.ts | 10 ++++++++++ .../repository/src/lib/gn4/auth/auth.service.ts | 14 ++++++++++++++ libs/util/app-config/src/lib/app-config.ts | 1 + libs/util/app-config/src/lib/model.ts | 1 + 7 files changed, 33 insertions(+), 4 deletions(-) diff --git a/apps/metadata-editor/src/app/app.module.ts b/apps/metadata-editor/src/app/app.module.ts index c2a378472..ce7a03c92 100644 --- a/apps/metadata-editor/src/app/app.module.ts +++ b/apps/metadata-editor/src/app/app.module.ts @@ -27,6 +27,7 @@ import { EditorRouterService } from './router.service' import { LOGIN_URL, LOGOUT_URL, + SETTINGS_URL, provideGn4, provideRepositoryUrl, } from '@geonetwork-ui/api/repository' @@ -75,6 +76,10 @@ import { FeatureEditorModule } from '@geonetwork-ui/feature/editor' provide: LOGOUT_URL, useFactory: () => getGlobalConfig().LOGOUT_URL, }, + { + provide: SETTINGS_URL, + useFactory: () => getGlobalConfig().SETTINGS_URL, + }, ], bootstrap: [AppComponent], }) diff --git a/apps/metadata-editor/src/app/dashboard/sidebar/sidebar.component.ts b/apps/metadata-editor/src/app/dashboard/sidebar/sidebar.component.ts index d382b4ba6..c842bb1ef 100644 --- a/apps/metadata-editor/src/app/dashboard/sidebar/sidebar.component.ts +++ b/apps/metadata-editor/src/app/dashboard/sidebar/sidebar.component.ts @@ -32,10 +32,7 @@ export class SidebarComponent implements OnInit { organisations$: Observable get settingsUrl() { - return ( - this.authService.loginUrl.split('/catalog')[0] + - '/admin.console#/organization/users?userOrGroup=' - ) + return this.authService.settingsUrl } constructor( diff --git a/conf/default.toml b/conf/default.toml index bae70b32d..2586bd086 100644 --- a/conf/default.toml +++ b/conf/default.toml @@ -24,6 +24,7 @@ proxy_path = "" # Example to use the georchestra login page: # login_url = "/cas/login?service=${current_url}" # logout_url = "/geonetwork/signout" +# settings_url = "/geonetwork/srv/\${lang3}/admin.console#/organization/users?userOrGroup=" # This optional URL should point to the static html page wc-embedder.html which allows to display a web component (like chart and table) via a permalink. # URLs can be indicated from the root of the same server starting with a "/" or as an external URL. Be conscious of potential CORS issues when using an external URL. # The default location in the dockerized datahub app for example is "/datahub/wc-embedder.html". diff --git a/libs/api/repository/src/lib/gn4/auth/auth.service.spec.ts b/libs/api/repository/src/lib/gn4/auth/auth.service.spec.ts index dabc434e3..cc3fc4d38 100644 --- a/libs/api/repository/src/lib/gn4/auth/auth.service.spec.ts +++ b/libs/api/repository/src/lib/gn4/auth/auth.service.spec.ts @@ -91,4 +91,14 @@ describe('AuthService', () => { expect(service.logoutUrl).toEqual('/geonetwork/signout') }) }) + describe('Settings', () => { + beforeEach(() => { + service = TestBed.inject(AuthService) + }) + it('should return the logout url', () => { + expect(service.settingsUrl).toEqual( + '/geonetwork/srv/fre/admin.console#/organization/users?userOrGroup=' + ) + }) + }) }) diff --git a/libs/api/repository/src/lib/gn4/auth/auth.service.ts b/libs/api/repository/src/lib/gn4/auth/auth.service.ts index 667e817aa..988b2ada9 100644 --- a/libs/api/repository/src/lib/gn4/auth/auth.service.ts +++ b/libs/api/repository/src/lib/gn4/auth/auth.service.ts @@ -8,12 +8,17 @@ export const LOGIN_URL = new InjectionToken('loginUrl') export const DEFAULT_GN4_LOGOUT_URL = `/geonetwork/signout` export const LOGOUT_URL = new InjectionToken('logoutUrl') +export const DEFAULT_GN4_SETTINGS_URL = `/geonetwork/srv/\${lang3}/admin.console#/organization/users?userOrGroup=` +export const SETTINGS_URL = new InjectionToken('settingsUrl') + @Injectable({ providedIn: 'root', }) export class AuthService { baseLoginUrl = this.baseLoginUrlToken || DEFAULT_GN4_LOGIN_URL baseLogoutUrl = this.baseLogoutUrlToken || DEFAULT_GN4_LOGOUT_URL + baseSettingsUrl = this.baseSettingsUrlToken || DEFAULT_GN4_SETTINGS_URL + get loginUrl() { let baseUrl = this.baseLoginUrl const locationHasQueryParams = !!window.location.search @@ -34,9 +39,18 @@ export class AuthService { return this.baseLogoutUrl } + get settingsUrl() { + let baseUrl = this.baseSettingsUrl + return baseUrl.replace( + '${lang3}', + LANG_2_TO_3_MAPPER[this.translateService.currentLang] + ) + } + constructor( @Optional() @Inject(LOGIN_URL) private baseLoginUrlToken: string, @Optional() @Inject(LOGOUT_URL) private baseLogoutUrlToken: string, + @Optional() @Inject(SETTINGS_URL) private baseSettingsUrlToken: string, private translateService: TranslateService ) {} } diff --git a/libs/util/app-config/src/lib/app-config.ts b/libs/util/app-config/src/lib/app-config.ts index 540073903..5547fd165 100644 --- a/libs/util/app-config/src/lib/app-config.ts +++ b/libs/util/app-config/src/lib/app-config.ts @@ -126,6 +126,7 @@ export function loadAppConfig() { : undefined, LOGIN_URL: parsedGlobalSection.login_url, LOGOUT_URL: parsedGlobalSection.logout_url, + SETTINGS_URL: parsedGlobalSection.settings_url, WEB_COMPONENT_EMBEDDER_URL: parsedGlobalSection.web_component_embedder_url, LANGUAGES: parsedGlobalSection.languages, diff --git a/libs/util/app-config/src/lib/model.ts b/libs/util/app-config/src/lib/model.ts index 742aa7fc4..072dadd2b 100644 --- a/libs/util/app-config/src/lib/model.ts +++ b/libs/util/app-config/src/lib/model.ts @@ -7,6 +7,7 @@ export interface GlobalConfig { METADATA_LANGUAGE?: string LOGIN_URL?: string LOGOUT_URL?: string + SETTINGS_URL?: string WEB_COMPONENT_EMBEDDER_URL?: string LANGUAGES?: string[] CONTACT_EMAIL?: string