[CST-15074][#3355] PR review

This commit is contained in:
Vincenzo Mecca
2025-03-12 20:15:57 +01:00
parent f2c5912dfa
commit d6776a8a1e
9 changed files with 155 additions and 117 deletions

View File

@@ -11,6 +11,7 @@ import {
} from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import { CookieAttributes } from 'js-cookie';
import uniqBy from 'lodash/uniqBy';
import {
Observable,
of as observableOf,
@@ -38,6 +39,7 @@ import {
isNotNull,
isNotUndefined,
} from '../../shared/empty.util';
import { rendersAuthMethodType } from '../../shared/log-in/methods/log-in.methods-decorator';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
import { followLink } from '../../shared/utils/follow-link-config.model';
@@ -74,6 +76,7 @@ import {
} from './auth.actions';
import { AuthRequestService } from './auth-request.service';
import { AuthMethod } from './models/auth.method';
import { AuthMethodType } from './models/auth.method-type';
import { AuthStatus } from './models/auth-status.model';
import {
AuthTokenInfo,
@@ -81,6 +84,7 @@ import {
} from './models/auth-token-info.model';
import {
getAuthenticatedUserId,
getAuthenticationMethods,
getAuthenticationToken,
getExternalAuthCookieStatus,
getRedirectUrl,
@@ -690,4 +694,18 @@ export class AuthService {
}
}
public getAuthMethods(excludedAuthMethod?: AuthMethodType): Observable<AuthMethod[]> {
return this.store.pipe(
select(getAuthenticationMethods),
map((methods: AuthMethod[]) => methods
// ignore the given auth method if it should be excluded
.filter((authMethod: AuthMethod) => excludedAuthMethod == null || authMethod.authMethodType !== excludedAuthMethod)
.filter((authMethod: AuthMethod) => rendersAuthMethodType(authMethod.authMethodType) !== undefined)
.sort((method1: AuthMethod, method2: AuthMethod) => method1.position - method2.position),
),
// ignore the ip authentication method when it's returned by the backend
map((authMethods: AuthMethod[]) => uniqBy(authMethods.filter(a => a.authMethodType !== AuthMethodType.Ip), 'authMethodType')),
);
}
}