Skip to content

Commit b8eaf90

Browse files
Merge branch 'fix-display-order-authentication-methods_contribute-7.4' into fix-display-order-authentication-methods_contribute-7.6
# Conflicts: # src/app/shared/log-in/log-in.component.html # src/app/shared/log-in/log-in.component.ts
2 parents 0905a53 + 51b13fb commit b8eaf90

6 files changed

Lines changed: 20 additions & 41 deletions

File tree

src/app/core/data/feature-authorization/authorization-data.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class AuthorizationDataService extends BaseDataService<Authorization> imp
7474
return [];
7575
}
7676
}),
77-
catchError(() => observableOf(false)),
77+
catchError(() => observableOf([])),
7878
oneAuthorizationMatchesFeature(featureId)
7979
);
8080
}

src/app/core/data/feature-authorization/authorization-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ export const oneAuthorizationMatchesFeature = (featureID: FeatureID) =>
6868
source.pipe(
6969
switchMap((authorizations: Authorization[]) => {
7070
if (isNotEmpty(authorizations)) {
71-
return observableCombineLatest(
71+
return observableCombineLatest([
7272
...authorizations
7373
.filter((authorization: Authorization) => hasValue(authorization.feature))
7474
.map((authorization: Authorization) => authorization.feature.pipe(
7575
getFirstSucceededRemoteDataPayload()
7676
))
77-
);
77+
]);
7878
} else {
7979
return observableOf([]);
8080
}

src/app/shared/log-in/container/log-in-container.component.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Component, Injector, Input, OnInit } from '@angular/core';
2-
1+
import { Component, Injector, Input, OnInit, Type } from '@angular/core';
32
import { rendersAuthMethodType } from '../methods/log-in.methods-decorator';
43
import { AuthMethod } from '../../../core/auth/models/auth.method';
54

@@ -27,12 +26,9 @@ export class LogInContainerComponent implements OnInit {
2726
*/
2827
public objectInjector: Injector;
2928

30-
/**
31-
* Initialize instance variables
32-
*
33-
* @param {Injector} injector
34-
*/
35-
constructor(private injector: Injector) {
29+
constructor(
30+
protected injector: Injector,
31+
) {
3632
}
3733

3834
/**
@@ -51,8 +47,8 @@ export class LogInContainerComponent implements OnInit {
5147
/**
5248
* Find the correct component based on the AuthMethod's type
5349
*/
54-
getAuthMethodContent(): string {
55-
return rendersAuthMethodType(this.authMethod.authMethodType);
50+
getAuthMethodContent(): Type<Component> {
51+
return rendersAuthMethodType(this.authMethod.authMethodType);
5652
}
5753

5854
}
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
<ds-themed-loading *ngIf="(loading | async) || (isAuthenticated | async)" class="m-5"></ds-themed-loading>
22
<div *ngIf="!(loading | async) && !(isAuthenticated | async)" class="px-4 py-3 mx-auto login-container">
3-
<ng-container *ngFor="let authMethod of getOrderedAuthMethods(authMethods | async); let last = last">
4-
<div [class.d-none]="contentRef.innerText?.trim().length === 0">
5-
<div #contentRef>
6-
<ds-log-in-container [authMethod]="authMethod" [isStandalonePage]="isStandalonePage"></ds-log-in-container>
7-
</div>
8-
<div *ngIf="!last" class="dropdown-divider my-2"></div>
9-
</div>
3+
<ng-container *ngFor="let authMethod of (authMethods | async); let last = last">
4+
<ds-log-in-container [authMethod]="authMethod" [isStandalonePage]="isStandalonePage"></ds-log-in-container>
5+
<div *ngIf="!last" class="dropdown-divider my-2"></div>
106
</ng-container>
117
</div>

src/app/shared/log-in/log-in.component.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ import {
1111
import { hasValue } from '../empty.util';
1212
import { AuthService } from '../../core/auth/auth.service';
1313
import { CoreState } from '../../core/core-state.model';
14-
import { AuthMethodType } from '../../core/auth/models/auth.method-type';
14+
import { rendersAuthMethodType } from './methods/log-in.methods-decorator';
1515

16-
/**
17-
* /users/sign-in
18-
* @class LogInComponent
19-
*/
2016
@Component({
2117
selector: 'ds-log-in',
2218
templateUrl: './log-in.component.html',
@@ -57,8 +53,10 @@ export class LogInComponent implements OnInit {
5753
ngOnInit(): void {
5854
this.authMethods = this.store.pipe(
5955
select(getAuthenticationMethods),
60-
// ignore the ip authentication method when it's returned by the backend
61-
map((methods: AuthMethod[]) => methods.filter((authMethod: AuthMethod) => authMethod.authMethodType !== AuthMethodType.Ip)),
56+
map((methods: AuthMethod[]) => methods
57+
.filter((authMethod: AuthMethod) => rendersAuthMethodType(authMethod.authMethodType) !== undefined)
58+
.sort((method1: AuthMethod, method2: AuthMethod) => method1.position - method2.position)
59+
),
6260
);
6361

6462
// set loading
@@ -75,16 +73,4 @@ export class LogInComponent implements OnInit {
7573
});
7674
}
7775

78-
/**
79-
* Returns an ordered list of {@link AuthMethod}s based on their position.
80-
*
81-
* @param authMethods The {@link AuthMethod}s to sort
82-
*/
83-
getOrderedAuthMethods(authMethods: AuthMethod[] | null): AuthMethod[] {
84-
if (hasValue(authMethods)) {
85-
return [...authMethods].sort((method1: AuthMethod, method2: AuthMethod) => method1.position - method2.position);
86-
} else {
87-
return [];
88-
}
89-
}
9076
}

src/app/shared/log-in/methods/log-in.methods-decorator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { Component, Type } from '@angular/core';
12
import { AuthMethodType } from '../../../core/auth/models/auth.method-type';
23

3-
const authMethodsMap = new Map();
4+
const authMethodsMap: Map<AuthMethodType, Type<Component>> = new Map();
45

56
export function renderAuthMethodFor(authMethodType: AuthMethodType) {
67
return function decorator(objectElement: any) {
@@ -11,6 +12,6 @@ export function renderAuthMethodFor(authMethodType: AuthMethodType) {
1112
};
1213
}
1314

14-
export function rendersAuthMethodType(authMethodType: AuthMethodType) {
15+
export function rendersAuthMethodType(authMethodType: AuthMethodType): Type<Component> | undefined {
1516
return authMethodsMap.get(authMethodType);
1617
}

0 commit comments

Comments
 (0)