[DURACOM-204][#2622] Makes forgot-password link removable

This commit is contained in:
Vincenzo Mecca
2023-11-10 16:13:20 +01:00
parent 684846ae36
commit 91b4d3dcd1
3 changed files with 31 additions and 12 deletions

View File

@@ -34,4 +34,5 @@ export enum FeatureID {
CanEditItem = 'canEditItem', CanEditItem = 'canEditItem',
CanRegisterDOI = 'canRegisterDOI', CanRegisterDOI = 'canRegisterDOI',
CanSubscribe = 'canSubscribeDso', CanSubscribe = 'canSubscribeDso',
EPersonForgotPassword = 'epersonForgotPassword',
} }

View File

@@ -29,11 +29,11 @@
[disabled]="!form.valid"><i class="fas fa-sign-in-alt"></i> {{"login.form.submit" | translate}}</button> [disabled]="!form.valid"><i class="fas fa-sign-in-alt"></i> {{"login.form.submit" | translate}}</button>
</form> </form>
<div class="mt-2"> <ng-container *ngIf="canShowDivider$ | async">
<a class="dropdown-item" *ngIf="canRegister$ | async" [routerLink]="[getRegisterRoute()]" [attr.data-test]="'register' | dsBrowserOnly"> <div class="mt-2">
{{ 'login.form.new-user' | translate }} <a class="dropdown-item" *ngIf="canRegister$ | async" [routerLink]="[getRegisterRoute()]"
</a> [attr.data-test]="'register' | dsBrowserOnly">{{"login.form.new-user" | translate}}</a>
<a class="dropdown-item" [routerLink]="[getForgotRoute()]" [attr.data-test]="'forgot' | dsBrowserOnly"> <a class="dropdown-item" *ngIf="canForgot$ | async" [routerLink]="[getForgotRoute()]"
{{ 'login.form.forgot-password' | translate }} [attr.data-test]="'forgot' | dsBrowserOnly">{{"login.form.forgot-password" | translate}}</a>
</a> </div>
</div> </ng-container>

View File

@@ -1,9 +1,9 @@
import { map } from 'rxjs/operators'; import { combineLatest, Observable, shareReplay } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { Component, Inject, OnInit } from '@angular/core'; import { Component, Inject, OnInit } from '@angular/core';
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
import { select, Store } from '@ngrx/store'; import { select, Store } from '@ngrx/store';
import { Observable } from 'rxjs';
import { AuthenticateAction, ResetAuthenticationMessagesAction } from '../../../../core/auth/auth.actions'; import { AuthenticateAction, ResetAuthenticationMessagesAction } from '../../../../core/auth/auth.actions';
import { getAuthenticationError, getAuthenticationInfo, } from '../../../../core/auth/selectors'; import { getAuthenticationError, getAuthenticationInfo, } from '../../../../core/auth/selectors';
@@ -73,6 +73,17 @@ export class LogInPasswordComponent implements OnInit {
*/ */
public canRegister$: Observable<boolean>; public canRegister$: Observable<boolean>;
/**
* Whether or not the current user (or anonymous) is authorized to register an account
*/
canForgot$: Observable<boolean>;
/**
* Shows the divider only if contains at least one link to show
*/
canShowDivider$: Observable<boolean>;
constructor( constructor(
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod, @Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
@Inject('isStandalonePage') public isStandalonePage: boolean, @Inject('isStandalonePage') public isStandalonePage: boolean,
@@ -114,8 +125,15 @@ export class LogInPasswordComponent implements OnInit {
return message; return message;
}) })
); );
this.canRegister$ = this.authorizationService.isAuthorized(FeatureID.EPersonRegistration); this.canRegister$ = this.authorizationService.isAuthorized(FeatureID.EPersonRegistration).pipe(shareReplay(1));
this.canForgot$ = this.authorizationService.isAuthorized(FeatureID.EPersonForgotPassword).pipe(shareReplay(1));
this.canShowDivider$ =
combineLatest([this.canRegister$, this.canForgot$])
.pipe(
map(([canRegister, canForgot]) => canRegister || canForgot),
filter(Boolean)
);
} }
getRegisterRoute() { getRegisterRoute() {