From c2c42297e53aa6a7a68d46b267eecc4605ca5146 Mon Sep 17 00:00:00 2001 From: Sofia Papacharalampous Date: Fri, 22 Mar 2024 14:15:01 +0200 Subject: [PATCH] my-profile, added configuration for auth-provider icons --- .../auth-providers.model.ts | 65 +++++++++++++++++++ .../configuration/configuration.service.ts | 7 ++ .../user-profile/user-profile-editor.model.ts | 1 - .../user-profile/user-profile.component.html | 7 +- .../ui/user-profile/user-profile.component.ts | 24 +++++++ dmp-frontend/src/assets/config/config.json | 20 +++++- 6 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 dmp-frontend/src/app/core/model/configuration-models/auth-providers.model.ts diff --git a/dmp-frontend/src/app/core/model/configuration-models/auth-providers.model.ts b/dmp-frontend/src/app/core/model/configuration-models/auth-providers.model.ts new file mode 100644 index 000000000..81ff02205 --- /dev/null +++ b/dmp-frontend/src/app/core/model/configuration-models/auth-providers.model.ts @@ -0,0 +1,65 @@ + +export class AuthProviders { + + private _authProviders: AuthProvider[]; + get authProviders(): AuthProvider[] { + return this._authProviders; + } + + private _defaultAuthProvider: AuthProvider; + get defaultAuthProvider(): AuthProvider { + return this._defaultAuthProvider; + } + + public static parseValue(value: any): AuthProviders { + const authProvidersObj: AuthProviders = new AuthProviders(); + + authProvidersObj._defaultAuthProvider = AuthProvider.parseValue(value.defaultAuthProvider); + + authProvidersObj._authProviders = []; + for (let authProviderValue of value.authProviders) { + const authProviderObj: AuthProvider = AuthProvider.parseValue(authProviderValue); + authProvidersObj._authProviders.push(authProviderObj); + } + + return authProvidersObj; + } + + public findOrGetDefault(providerName: string, culture: string): AuthProvider { + const authProvider = this.find(providerName, culture); + + if (authProvider === null) return this.defaultAuthProvider; + + return authProvider; + } + + public find(providerName: string, culture: string): AuthProvider | undefined { + + return this.authProviders.find(p => p.name === providerName && p.cultures.includes(culture)); + } +} + +export class AuthProvider { + private _name: string; + get name(): string { + return this._name; + } + + private _providerClass: string; + get providerClass(): string { + return this._providerClass; + } + + private _cultures: string[]; + get cultures(): string[] { + return this._cultures; + } + + public static parseValue(value: any): AuthProvider { + const obj: AuthProvider = new AuthProvider(); + obj._name = value.name; + obj._providerClass = value.providerClass; + obj._cultures = value.cultures; + return obj; + } +} diff --git a/dmp-frontend/src/app/core/services/configuration/configuration.service.ts b/dmp-frontend/src/app/core/services/configuration/configuration.service.ts index 3f67f1034..0d502a974 100644 --- a/dmp-frontend/src/app/core/services/configuration/configuration.service.ts +++ b/dmp-frontend/src/app/core/services/configuration/configuration.service.ts @@ -9,6 +9,7 @@ import { Logging } from '@app/core/model/configuration-models/logging.model'; import { HttpClient } from '@angular/common/http'; import { KeycloakConfiguration } from '@app/core/model/configuration-models/keycloak-configuration.model'; import { Guid } from '@common/types/guid'; +import { AuthProviders } from '@app/core/model/configuration-models/auth-providers.model'; @Injectable({ providedIn: 'root', @@ -148,6 +149,11 @@ export class ConfigurationService extends BaseComponent { return this._newReleaseNotificationVersionCode; } + private _authProviders: AuthProviders; + get authProviders(): AuthProviders { + return this._authProviders; + } + public loadConfiguration(): Promise { return new Promise((r, e) => { // We need to exclude all interceptors here, for the initial configuration request. @@ -216,6 +222,7 @@ export class ConfigurationService extends BaseComponent { this._newReleaseNotificationExpires = config.newReleaseNotification?.expires; this._newReleaseNotificationLink = config.newReleaseNotification?.link; this._newReleaseNotificationVersionCode = config.newReleaseNotification?.versionCode; + this._authProviders = AuthProviders.parseValue(config.authProviders); } } diff --git a/dmp-frontend/src/app/ui/user-profile/user-profile-editor.model.ts b/dmp-frontend/src/app/ui/user-profile/user-profile-editor.model.ts index d5fe69071..2400a6ae1 100644 --- a/dmp-frontend/src/app/ui/user-profile/user-profile-editor.model.ts +++ b/dmp-frontend/src/app/ui/user-profile/user-profile-editor.model.ts @@ -38,5 +38,4 @@ export class UserProfileEditorModel { return formGroup; } - } diff --git a/dmp-frontend/src/app/ui/user-profile/user-profile.component.html b/dmp-frontend/src/app/ui/user-profile/user-profile.component.html index 0ab832a5f..6bd4b77cf 100644 --- a/dmp-frontend/src/app/ui/user-profile/user-profile.component.html +++ b/dmp-frontend/src/app/ui/user-profile/user-profile.component.html @@ -46,8 +46,11 @@
{{userCredential.data.email}}
- - + + + + +