Skip to content

Commit 644c48d

Browse files
vins01-4scienceMattia Vianelli
authored andcommitted
[DURACOM-204][DSpace#2622] Makes forgot-password link removable
(cherry picked from commit 91b4d3d)
1 parent 63f5072 commit 644c48d

3 files changed

Lines changed: 32 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export enum FeatureID {
3636
CanEditItem = 'canEditItem',
3737
CanRegisterDOI = 'canRegisterDOI',
3838
CanSubscribe = 'canSubscribeDso',
39+
EPersonForgotPassword = 'epersonForgotPassword',
3940
ShowClaimItem = 'showClaimItem',
4041
CanCorrectItem = 'canCorrectItem',
4142
}

src/app/shared/log-in/methods/password/log-in-password.component.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,12 @@
2828
<button class="btn btn-lg btn-primary btn-block mt-3" type="submit" [attr.data-test]="'login-button' | dsBrowserOnly"
2929
[disabled]="!form.valid"><i class="fas fa-sign-in-alt"></i> {{"login.form.submit" | translate}}</button>
3030
</form>
31+
32+
<ng-container *ngIf="canShowDivider$ | async">
33+
<div class="mt-2">
34+
<a class="dropdown-item" *ngIf="canRegister$ | async" [routerLink]="[getRegisterRoute()]"
35+
[attr.data-test]="'register' | dsBrowserOnly">{{"login.form.new-user" | translate}}</a>
36+
<a class="dropdown-item" *ngIf="canForgot$ | async" [routerLink]="[getForgotRoute()]"
37+
[attr.data-test]="'forgot' | dsBrowserOnly">{{"login.form.forgot-password" | translate}}</a>
38+
</div>
39+
</ng-container>

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { map } from 'rxjs/operators';
1+
import { combineLatest, Observable, shareReplay } from 'rxjs';
2+
import { filter, map } from 'rxjs/operators';
23
import { Component, Inject, OnInit } from '@angular/core';
34
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
45

56
import { select, Store } from '@ngrx/store';
6-
import { Observable } from 'rxjs';
77
import { AuthenticateAction, ResetAuthenticationMessagesAction } from '../../../../core/auth/auth.actions';
88

99
import { getAuthenticationError, getAuthenticationInfo, } from '../../../../core/auth/selectors';
@@ -73,6 +73,17 @@ export class LogInPasswordComponent implements OnInit {
7373
*/
7474
public canRegister$: Observable<boolean>;
7575

76+
/**
77+
* Whether or not the current user (or anonymous) is authorized to register an account
78+
*/
79+
canForgot$: Observable<boolean>;
80+
81+
/**
82+
* Shows the divider only if contains at least one link to show
83+
*/
84+
canShowDivider$: Observable<boolean>;
85+
86+
7687
constructor(
7788
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
7889
@Inject('isStandalonePage') public isStandalonePage: boolean,
@@ -114,8 +125,15 @@ export class LogInPasswordComponent implements OnInit {
114125
return message;
115126
})
116127
);
117-
118-
this.canRegister$ = this.authorizationService.isAuthorized(FeatureID.EPersonRegistration);
128+
129+
this.canRegister$ = this.authorizationService.isAuthorized(FeatureID.EPersonRegistration).pipe(shareReplay(1));
130+
this.canForgot$ = this.authorizationService.isAuthorized(FeatureID.EPersonForgotPassword).pipe(shareReplay(1));
131+
this.canShowDivider$ =
132+
combineLatest([this.canRegister$, this.canForgot$])
133+
.pipe(
134+
map(([canRegister, canForgot]) => canRegister || canForgot),
135+
filter(Boolean)
136+
);
119137
}
120138

121139
getRegisterRoute() {

0 commit comments

Comments
 (0)