Skip to content

Commit 56b38f6

Browse files
authored
Merge pull request DSpace#2624 from 4Science/DURACOM-204
[DSpace#2622] Makes forgot-password link removable
2 parents 645024d + 0e4151e commit 56b38f6

5 files changed

Lines changed: 69 additions & 15 deletions

File tree

src/app/app-routing.module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NgModule } from '@angular/core';
2-
import { RouterModule, NoPreloading } from '@angular/router';
2+
import { NoPreloading, RouterModule } from '@angular/router';
33
import { AuthBlockingGuard } from './core/auth/auth-blocking.guard';
44

55
import { AuthenticatedGuard } from './core/auth/authenticated.guard';
@@ -40,6 +40,7 @@ import {
4040
import { ServerCheckGuard } from './core/server-check/server-check.guard';
4141
import { MenuResolver } from './menu.resolver';
4242
import { ThemedPageErrorComponent } from './page-error/themed-page-error.component';
43+
import { ForgotPasswordCheckGuard } from './core/rest-property/forgot-password-check-guard.guard';
4344

4445
@NgModule({
4546
imports: [
@@ -94,7 +95,10 @@ import { ThemedPageErrorComponent } from './page-error/themed-page-error.compone
9495
path: FORGOT_PASSWORD_PATH,
9596
loadChildren: () => import('./forgot-password/forgot-password.module')
9697
.then((m) => m.ForgotPasswordModule),
97-
canActivate: [EndUserAgreementCurrentUserGuard]
98+
canActivate: [
99+
ForgotPasswordCheckGuard,
100+
EndUserAgreementCurrentUserGuard
101+
]
98102
},
99103
{
100104
path: COMMUNITY_MODULE_PATH,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ export enum FeatureID {
3434
CanEditItem = 'canEditItem',
3535
CanRegisterDOI = 'canRegisterDOI',
3636
CanSubscribe = 'canSubscribeDso',
37-
CanSeeQA = 'canSeeQA'
37+
EPersonForgotPassword = 'epersonForgotPassword',
38+
CanSeeQA = 'canSeeQA',
3839
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Injectable } from '@angular/core';
2+
import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router';
3+
import { Observable, of } from 'rxjs';
4+
import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service';
5+
import { FeatureID } from '../data/feature-authorization/feature-id';
6+
import {
7+
SingleFeatureAuthorizationGuard
8+
} from '../data/feature-authorization/feature-authorization-guard/single-feature-authorization.guard';
9+
import { AuthService } from '../auth/auth.service';
10+
11+
@Injectable({
12+
providedIn: 'root'
13+
})
14+
/**
15+
* Guard that checks if the forgot-password feature is enabled
16+
*/
17+
export class ForgotPasswordCheckGuard extends SingleFeatureAuthorizationGuard {
18+
19+
constructor(
20+
protected readonly authorizationService: AuthorizationDataService,
21+
protected readonly router: Router,
22+
protected readonly authService: AuthService
23+
) {
24+
super(authorizationService, router, authService);
25+
}
26+
27+
getFeatureID(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<FeatureID> {
28+
return of(FeatureID.EPersonForgotPassword);
29+
}
30+
31+
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
[disabled]="!form.valid"><i class="fas fa-sign-in-alt"></i> {{"login.form.submit" | translate}}</button>
2828
</form>
2929

30-
<div class="mt-2">
31-
<a class="dropdown-item" *ngIf="canRegister$ | async" [routerLink]="[getRegisterRoute()]" [attr.data-test]="'register' | dsBrowserOnly">
32-
{{ 'login.form.new-user' | translate }}
33-
</a>
34-
<a class="dropdown-item" [routerLink]="[getForgotRoute()]" [attr.data-test]="'forgot' | dsBrowserOnly">
35-
{{ 'login.form.forgot-password' | translate }}
36-
</a>
37-
</div>
30+
<ng-container *ngIf="canShowDivider$ | async">
31+
<div class="mt-2">
32+
<a class="dropdown-item" *ngIf="canRegister$ | async" [routerLink]="[getRegisterRoute()]"
33+
[attr.data-test]="'register' | dsBrowserOnly">{{"login.form.new-user" | translate}}</a>
34+
<a class="dropdown-item" *ngIf="canForgot$ | async" [routerLink]="[getForgotRoute()]"
35+
[attr.data-test]="'forgot' | dsBrowserOnly">{{"login.form.forgot-password" | translate}}</a>
36+
</div>
37+
</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';
@@ -64,7 +64,7 @@ export class LogInPasswordComponent implements OnInit {
6464

6565
/**
6666
* The authentication form.
67-
* @type {FormGroup}
67+
* @type {UntypedFormGroup}
6868
*/
6969
public form: UntypedFormGroup;
7070

@@ -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,
@@ -115,7 +126,14 @@ export class LogInPasswordComponent implements OnInit {
115126
})
116127
);
117128

118-
this.canRegister$ = this.authorizationService.isAuthorized(FeatureID.EPersonRegistration);
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)