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([]); } 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 857b977360e..030d1a81761 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 4bfae183326..0fdc029cb4c 100644 --- a/src/app/shared/log-in/log-in.component.ts +++ b/src/app/shared/log-in/log-in.component.ts @@ -11,12 +11,8 @@ import { import { hasValue } from '../empty.util'; import { AuthService } from '../../core/auth/auth.service'; import { CoreState } from '../../core/core-state.model'; -import { AuthMethodType } from '../../core/auth/models/auth.method-type'; +import { rendersAuthMethodType } from './methods/log-in.methods-decorator'; -/** - * /users/sign-in - * @class LogInComponent - */ @Component({ selector: 'ds-log-in', templateUrl: './log-in.component.html', @@ -57,8 +53,10 @@ export class LogInComponent implements OnInit { ngOnInit(): void { this.authMethods = this.store.pipe( select(getAuthenticationMethods), - // ignore the ip authentication method when it's returned by the backend - map((methods: AuthMethod[]) => methods.filter((authMethod: AuthMethod) => authMethod.authMethodType !== AuthMethodType.Ip)), + map((methods: AuthMethod[]) => methods + .filter((authMethod: AuthMethod) => rendersAuthMethodType(authMethod.authMethodType) !== undefined) + .sort((method1: AuthMethod, method2: AuthMethod) => method1.position - method2.position) + ), ); // set loading @@ -75,16 +73,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); }