From 987a92f5293cb7aec95664c4faefcd99aa71c830 Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Sat, 21 Oct 2023 18:07:16 +0200 Subject: [PATCH 1/2] Filter out all the AuthMethods who don't have a component to render before rendering LogInContainerComponent --- .../container/log-in-container.component.ts | 16 +++++--------- src/app/shared/log-in/log-in.component.html | 10 +++------ src/app/shared/log-in/log-in.component.ts | 22 +++++-------------- .../methods/log-in.methods-decorator.ts | 5 +++-- 4 files changed, 18 insertions(+), 35 deletions(-) diff --git a/src/app/shared/log-in/container/log-in-container.component.ts b/src/app/shared/log-in/container/log-in-container.component.ts index f6a08a1e1ec..28e9f2f7e18 100644 --- a/src/app/shared/log-in/container/log-in-container.component.ts +++ b/src/app/shared/log-in/container/log-in-container.component.ts @@ -1,5 +1,4 @@ -import { Component, Injector, Input, OnInit } from '@angular/core'; - +import { Component, Injector, Input, OnInit, Type } from '@angular/core'; import { rendersAuthMethodType } from '../methods/log-in.methods-decorator'; import { AuthMethod } from '../../../core/auth/models/auth.method'; @@ -27,12 +26,9 @@ export class LogInContainerComponent implements OnInit { */ public objectInjector: Injector; - /** - * Initialize instance variables - * - * @param {Injector} injector - */ - constructor(private injector: Injector) { + constructor( + protected injector: Injector, + ) { } /** @@ -51,8 +47,8 @@ export class LogInContainerComponent implements OnInit { /** * Find the correct component based on the AuthMethod's type */ - getAuthMethodContent(): string { - return rendersAuthMethodType(this.authMethod.authMethodType); + getAuthMethodContent(): Type { + return rendersAuthMethodType(this.authMethod.authMethodType); } } diff --git a/src/app/shared/log-in/log-in.component.html b/src/app/shared/log-in/log-in.component.html index 173e0f8e303..7ce14cdeb2e 100644 --- a/src/app/shared/log-in/log-in.component.html +++ b/src/app/shared/log-in/log-in.component.html @@ -1,11 +1,7 @@ diff --git a/src/app/shared/log-in/log-in.component.ts b/src/app/shared/log-in/log-in.component.ts index 9cc466dcfe2..9d596a2a154 100644 --- a/src/app/shared/log-in/log-in.component.ts +++ b/src/app/shared/log-in/log-in.component.ts @@ -11,11 +11,9 @@ import { import { hasValue } from '../empty.util'; import { AuthService } from '../../core/auth/auth.service'; import { CoreState } from '../../core/core-state.model'; +import { rendersAuthMethodType } from './methods/log-in.methods-decorator'; +import { map } from 'rxjs/operators'; -/** - * /users/sign-in - * @class LogInComponent - */ @Component({ selector: 'ds-log-in', templateUrl: './log-in.component.html', @@ -57,6 +55,10 @@ export class LogInComponent implements OnInit { this.authMethods = this.store.pipe( select(getAuthenticationMethods), + map((methods: AuthMethod[]) => methods + .filter((authMethod: AuthMethod) => rendersAuthMethodType(authMethod.authMethodType) !== undefined) + .sort((method1: AuthMethod, method2: AuthMethod) => method1.position - method2.position) + ), ); // set loading @@ -73,16 +75,4 @@ export class LogInComponent implements OnInit { }); } - /** - * Returns an ordered list of {@link AuthMethod}s based on their position. - * - * @param authMethods The {@link AuthMethod}s to sort - */ - getOrderedAuthMethods(authMethods: AuthMethod[] | null): AuthMethod[] { - if (hasValue(authMethods)) { - return [...authMethods].sort((method1: AuthMethod, method2: AuthMethod) => method1.position - method2.position); - } else { - return []; - } - } } diff --git a/src/app/shared/log-in/methods/log-in.methods-decorator.ts b/src/app/shared/log-in/methods/log-in.methods-decorator.ts index 0614bdeb511..e30a4813dd8 100644 --- a/src/app/shared/log-in/methods/log-in.methods-decorator.ts +++ b/src/app/shared/log-in/methods/log-in.methods-decorator.ts @@ -1,6 +1,7 @@ +import { Component, Type } from '@angular/core'; import { AuthMethodType } from '../../../core/auth/models/auth.method-type'; -const authMethodsMap = new Map(); +const authMethodsMap: Map> = new Map(); export function renderAuthMethodFor(authMethodType: AuthMethodType) { return function decorator(objectElement: any) { @@ -11,6 +12,6 @@ export function renderAuthMethodFor(authMethodType: AuthMethodType) { }; } -export function rendersAuthMethodType(authMethodType: AuthMethodType) { +export function rendersAuthMethodType(authMethodType: AuthMethodType): Type | undefined { return authMethodsMap.get(authMethodType); } From 51b13fb78cac180ab27f117e63d975c8b0b5497d Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Sat, 21 Oct 2023 18:08:02 +0200 Subject: [PATCH 2/2] Fix AuthorizationDataService.isAuthorized throwing a console error when the searchByObject request doesn't succeed --- .../data/feature-authorization/authorization-data.service.ts | 2 +- .../core/data/feature-authorization/authorization-utils.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/core/data/feature-authorization/authorization-data.service.ts b/src/app/core/data/feature-authorization/authorization-data.service.ts index c43d335234b..95730422726 100644 --- a/src/app/core/data/feature-authorization/authorization-data.service.ts +++ b/src/app/core/data/feature-authorization/authorization-data.service.ts @@ -74,7 +74,7 @@ export class AuthorizationDataService extends BaseDataService imp return []; } }), - catchError(() => observableOf(false)), + catchError(() => observableOf([])), oneAuthorizationMatchesFeature(featureId) ); } diff --git a/src/app/core/data/feature-authorization/authorization-utils.ts b/src/app/core/data/feature-authorization/authorization-utils.ts index d1b65f61235..a4e5e4d997c 100644 --- a/src/app/core/data/feature-authorization/authorization-utils.ts +++ b/src/app/core/data/feature-authorization/authorization-utils.ts @@ -68,13 +68,13 @@ export const oneAuthorizationMatchesFeature = (featureID: FeatureID) => source.pipe( switchMap((authorizations: Authorization[]) => { if (isNotEmpty(authorizations)) { - return observableCombineLatest( + return observableCombineLatest([ ...authorizations .filter((authorization: Authorization) => hasValue(authorization.feature)) .map((authorization: Authorization) => authorization.feature.pipe( getFirstSucceededRemoteDataPayload() )) - ); + ]); } else { return observableOf([]); }