Merge pull request #2624 from 4Science/DURACOM-204

[#2622] Makes forgot-password link removable
This commit is contained in:
Tim Donohue
2024-02-13 14:19:22 -06:00
committed by GitHub
5 changed files with 69 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { RouterModule, NoPreloading } from '@angular/router'; import { NoPreloading, RouterModule } from '@angular/router';
import { AuthBlockingGuard } from './core/auth/auth-blocking.guard'; import { AuthBlockingGuard } from './core/auth/auth-blocking.guard';
import { AuthenticatedGuard } from './core/auth/authenticated.guard'; import { AuthenticatedGuard } from './core/auth/authenticated.guard';
@@ -40,6 +40,7 @@ import {
import { ServerCheckGuard } from './core/server-check/server-check.guard'; import { ServerCheckGuard } from './core/server-check/server-check.guard';
import { MenuResolver } from './menu.resolver'; import { MenuResolver } from './menu.resolver';
import { ThemedPageErrorComponent } from './page-error/themed-page-error.component'; import { ThemedPageErrorComponent } from './page-error/themed-page-error.component';
import { ForgotPasswordCheckGuard } from './core/rest-property/forgot-password-check-guard.guard';
@NgModule({ @NgModule({
imports: [ imports: [
@@ -94,7 +95,10 @@ import { ThemedPageErrorComponent } from './page-error/themed-page-error.compone
path: FORGOT_PASSWORD_PATH, path: FORGOT_PASSWORD_PATH,
loadChildren: () => import('./forgot-password/forgot-password.module') loadChildren: () => import('./forgot-password/forgot-password.module')
.then((m) => m.ForgotPasswordModule), .then((m) => m.ForgotPasswordModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [
ForgotPasswordCheckGuard,
EndUserAgreementCurrentUserGuard
]
}, },
{ {
path: COMMUNITY_MODULE_PATH, path: COMMUNITY_MODULE_PATH,

View File

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

View File

@@ -0,0 +1,31 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service';
import { FeatureID } from '../data/feature-authorization/feature-id';
import {
SingleFeatureAuthorizationGuard
} from '../data/feature-authorization/feature-authorization-guard/single-feature-authorization.guard';
import { AuthService } from '../auth/auth.service';
@Injectable({
providedIn: 'root'
})
/**
* Guard that checks if the forgot-password feature is enabled
*/
export class ForgotPasswordCheckGuard extends SingleFeatureAuthorizationGuard {
constructor(
protected readonly authorizationService: AuthorizationDataService,
protected readonly router: Router,
protected readonly authService: AuthService
) {
super(authorizationService, router, authService);
}
getFeatureID(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<FeatureID> {
return of(FeatureID.EPersonForgotPassword);
}
}

View File

@@ -27,11 +27,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';
@@ -64,7 +64,7 @@ export class LogInPasswordComponent implements OnInit {
/** /**
* The authentication form. * The authentication form.
* @type {FormGroup} * @type {UntypedFormGroup}
*/ */
public form: UntypedFormGroup; public form: UntypedFormGroup;
@@ -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,
@@ -115,7 +126,14 @@ export class LogInPasswordComponent implements OnInit {
}) })
); );
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() {