From 71cf66ecf491870d8abe578408af3a1f7b5077c9 Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Wed, 2 Aug 2023 00:00:37 +0200 Subject: [PATCH 1/3] Fix display order of authentication methods --- src/app/core/auth/auth.interceptor.ts | 6 +-- src/app/core/auth/auth.reducer.spec.ts | 8 ++-- src/app/core/auth/auth.reducer.ts | 2 +- src/app/core/auth/models/auth.method.ts | 5 ++- .../log-in-container.component.spec.ts | 12 ++++-- src/app/shared/log-in/log-in.component.html | 14 +++---- .../shared/log-in/log-in.component.spec.ts | 2 +- src/app/shared/log-in/log-in.component.ts | 34 +++++++-------- .../methods/oidc/log-in-oidc.component.html | 4 +- .../oidc/log-in-oidc.component.spec.ts | 42 ++++--------------- .../methods/orcid/log-in-orcid.component.html | 4 +- .../orcid/log-in-orcid.component.spec.ts | 39 +++-------------- .../password/log-in-password.component.html | 9 ++++ .../password/log-in-password.component.scss | 4 ++ .../log-in-password.component.spec.ts | 20 ++++----- .../password/log-in-password.component.ts | 25 +++++++---- .../log-in-shibboleth.component.html | 2 +- .../log-in-shibboleth.component.spec.ts | 39 +++-------------- src/app/shared/testing/auth-service.stub.ts | 7 ++-- src/assets/i18n/en.json5 | 2 - 20 files changed, 107 insertions(+), 173 deletions(-) diff --git a/src/app/core/auth/auth.interceptor.ts b/src/app/core/auth/auth.interceptor.ts index e55d0c0ff96..47ef0b11a5e 100644 --- a/src/app/core/auth/auth.interceptor.ts +++ b/src/app/core/auth/auth.interceptor.ts @@ -152,12 +152,12 @@ export class AuthInterceptor implements HttpInterceptor { let authMethodModel: AuthMethod; if (splittedRealm.length === 1) { - authMethodModel = new AuthMethod(methodName); + authMethodModel = new AuthMethod(methodName, Number(j)); authMethodModels.push(authMethodModel); } else if (splittedRealm.length > 1) { let location = splittedRealm[1]; location = this.parseLocation(location); - authMethodModel = new AuthMethod(methodName, location); + authMethodModel = new AuthMethod(methodName, Number(j), location); authMethodModels.push(authMethodModel); } } @@ -165,7 +165,7 @@ export class AuthInterceptor implements HttpInterceptor { // make sure the email + password login component gets rendered first authMethodModels = this.sortAuthMethods(authMethodModels); } else { - authMethodModels.push(new AuthMethod(AuthMethodType.Password)); + authMethodModels.push(new AuthMethod(AuthMethodType.Password, 0)); } return authMethodModels; diff --git a/src/app/core/auth/auth.reducer.spec.ts b/src/app/core/auth/auth.reducer.spec.ts index 8ebc9f6cb03..770bcc8691f 100644 --- a/src/app/core/auth/auth.reducer.spec.ts +++ b/src/app/core/auth/auth.reducer.spec.ts @@ -575,9 +575,9 @@ describe('authReducer', () => { authMethods: [], idle: false }; - const authMethods = [ - new AuthMethod(AuthMethodType.Password), - new AuthMethod(AuthMethodType.Shibboleth, 'location') + const authMethods: AuthMethod[] = [ + new AuthMethod(AuthMethodType.Password, 0), + new AuthMethod(AuthMethodType.Shibboleth, 1, 'location'), ]; const action = new RetrieveAuthMethodsSuccessAction(authMethods); const newState = authReducer(initialState, action); @@ -609,7 +609,7 @@ describe('authReducer', () => { loaded: false, blocking: false, loading: false, - authMethods: [new AuthMethod(AuthMethodType.Password)], + authMethods: [new AuthMethod(AuthMethodType.Password, 0)], idle: false }; expect(newState).toEqual(state); diff --git a/src/app/core/auth/auth.reducer.ts b/src/app/core/auth/auth.reducer.ts index acdb8ef812f..d09777c60f1 100644 --- a/src/app/core/auth/auth.reducer.ts +++ b/src/app/core/auth/auth.reducer.ts @@ -228,7 +228,7 @@ export function authReducer(state: any = initialState, action: AuthActions): Aut return Object.assign({}, state, { loading: false, blocking: false, - authMethods: [new AuthMethod(AuthMethodType.Password)] + authMethods: [new AuthMethod(AuthMethodType.Password, 0)] }); case AuthActionTypes.SET_REDIRECT_URL: diff --git a/src/app/core/auth/models/auth.method.ts b/src/app/core/auth/models/auth.method.ts index 0579ae0cd1b..b84e7a308af 100644 --- a/src/app/core/auth/models/auth.method.ts +++ b/src/app/core/auth/models/auth.method.ts @@ -2,11 +2,12 @@ import { AuthMethodType } from './auth.method-type'; export class AuthMethod { authMethodType: AuthMethodType; + position: number; location?: string; - // isStandalonePage? = true; + constructor(authMethodName: string, position: number, location?: string) { + this.position = position; - constructor(authMethodName: string, location?: string) { switch (authMethodName) { case 'ip': { this.authMethodType = AuthMethodType.Ip; diff --git a/src/app/shared/log-in/container/log-in-container.component.spec.ts b/src/app/shared/log-in/container/log-in-container.component.spec.ts index 29598e422ec..4700cf93071 100644 --- a/src/app/shared/log-in/container/log-in-container.component.spec.ts +++ b/src/app/shared/log-in/container/log-in-container.component.spec.ts @@ -13,13 +13,17 @@ import { AuthMethod } from '../../../core/auth/models/auth.method'; import { AuthServiceStub } from '../../testing/auth-service.stub'; import { createTestComponent } from '../../testing/utils.test'; import { HardRedirectService } from '../../../core/services/hard-redirect.service'; +import { AuthMethodType } from '../../../core/auth/models/auth.method-type'; +import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service'; +import { AuthorizationDataServiceStub } from '../../testing/authorization-service.stub'; +import { RouterTestingModule } from '@angular/router/testing'; describe('LogInContainerComponent', () => { let component: LogInContainerComponent; let fixture: ComponentFixture; - const authMethod = new AuthMethod('password'); + const authMethod = new AuthMethod(AuthMethodType.Password, 0); let hardRedirectService: HardRedirectService; @@ -35,13 +39,15 @@ describe('LogInContainerComponent', () => { ReactiveFormsModule, StoreModule.forRoot(authReducer), SharedModule, - TranslateModule.forRoot() + TranslateModule.forRoot(), + RouterTestingModule, ], declarations: [ TestComponent ], providers: [ { provide: AuthService, useClass: AuthServiceStub }, + { provide: AuthorizationDataService, useClass: AuthorizationDataServiceStub }, { provide: HardRedirectService, useValue: hardRedirectService }, LogInContainerComponent ], @@ -113,6 +119,6 @@ describe('LogInContainerComponent', () => { class TestComponent { isStandalonePage = true; - authMethod = new AuthMethod('password'); + authMethod = new AuthMethod(AuthMethodType.Password, 0); } diff --git a/src/app/shared/log-in/log-in.component.html b/src/app/shared/log-in/log-in.component.html index 6e4685a07bd..173e0f8e303 100644 --- a/src/app/shared/log-in/log-in.component.html +++ b/src/app/shared/log-in/log-in.component.html @@ -1,13 +1,11 @@