Skip to content

Commit

Permalink
Merged in task/dspace-cris-2023_02_x/DSC-1832 (pull request DSpace#1982)
Browse files Browse the repository at this point in the history
Task/dspace cris 2023 02 x/DSC-1832

Approved-by: Vincenzo Mecca
  • Loading branch information
Mattia Vianelli authored and vins01-4science committed Jul 23, 2024
2 parents d8da69f + f682ed9 commit 5320325
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
import { ServerCheckGuard } from './core/server-check/server-check.guard';
import { MenuResolver } from './menu.resolver';
import { ThemedPageErrorComponent } from './page-error/themed-page-error.component';
import { ForgotPasswordCheckGuard } from './core/rest-property/forgot-password-check-guard.guard';
import { SUGGESTION_MODULE_PATH } from './suggestions-page/suggestions-page-routing-paths';
import { RedirectService } from './redirect/redirect.service';

Expand Down Expand Up @@ -99,7 +100,10 @@ import { RedirectService } from './redirect/redirect.service';
path: FORGOT_PASSWORD_PATH,
loadChildren: () => import('./forgot-password/forgot-password.module')
.then((m) => m.ForgotPasswordModule),
canActivate: [EndUserAgreementCurrentUserGuard]
canActivate: [
ForgotPasswordCheckGuard,
EndUserAgreementCurrentUserGuard
]
},
{
path: COMMUNITY_MODULE_PATH,
Expand Down
1 change: 1 addition & 0 deletions src/app/core/data/feature-authorization/feature-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export enum FeatureID {
CanEditItem = 'canEditItem',
CanRegisterDOI = 'canRegisterDOI',
CanSubscribe = 'canSubscribeDso',
EPersonForgotPassword = 'epersonForgotPassword',
ShowClaimItem = 'showClaimItem',
CanCorrectItem = 'canCorrectItem',
}
31 changes: 31 additions & 0 deletions src/app/core/rest-property/forgot-password-check-guard.guard.ts
Original file line number Diff line number Diff line change
@@ -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);
}

}
11 changes: 8 additions & 3 deletions src/app/shared/log-in/log-in.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
<ds-log-in-container [authMethod]="authMethod" [isStandalonePage]="isStandalonePage"></ds-log-in-container>
<div *ngIf="!last" class="dropdown-divider my-2"></div>
</ng-container>
<div class="dropdown-divider"></div>
<a class="dropdown-item" *ngIf="(canRegister$ | async) && showRegisterLink" [routerLink]="[getRegisterRoute()]" [attr.data-test]="'register' | dsBrowserOnly">{{"login.form.new-user" | translate}}</a>
<a class="dropdown-item" [routerLink]="[getForgotRoute()]" [attr.data-test]="'forgot' | dsBrowserOnly">{{"login.form.forgot-password" | translate}}</a>
<ng-container *ngIf="canShowDivider$ | async">
<div class="mt-2">
<a class="dropdown-item" *ngIf="canRegister$ | async" [routerLink]="[getRegisterRoute()]"
[attr.data-test]="'register' | dsBrowserOnly">{{"login.form.new-user" | translate}}</a>
<a class="dropdown-item" *ngIf="canForgot$ | async" [routerLink]="[getForgotRoute()]"
[attr.data-test]="'forgot' | dsBrowserOnly">{{"login.form.forgot-password" | translate}}</a>
</div>
</ng-container>
</div>
23 changes: 20 additions & 3 deletions src/app/shared/log-in/log-in.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ChangeDetectionStrategy, Component, Input, OnDestroy, OnInit } from '@angular/core';

import { Observable, Subscription } from 'rxjs';
import { map } from 'rxjs/operators';
import { Observable, Subscription, combineLatest } from 'rxjs';
import { filter, map, shareReplay } from 'rxjs/operators';
import { select, Store } from '@ngrx/store';
import uniqBy from 'lodash/uniqBy';

Expand Down Expand Up @@ -67,6 +66,16 @@ export class LogInComponent implements OnInit, OnDestroy {
*/
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>;

/**
* Track subscription to unsubscribe on destroy
* @private
Expand Down Expand Up @@ -106,6 +115,14 @@ export class LogInComponent implements OnInit, OnDestroy {
});

this.canRegister$ = this.authorizationService.isAuthorized(FeatureID.EPersonRegistration);

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { AuthService } from '../../../../core/auth/auth.service';
import { HardRedirectService } from '../../../../core/services/hard-redirect.service';
import { CoreState } from '../../../../core/core-state.model';
import { getForgotPasswordRoute, getRegisterRoute } from '../../../../app-routing-paths';
import { FeatureID } from '../../../../core/data/feature-authorization/feature-id';
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
import { FeatureID } from '../../../../core/data/feature-authorization/feature-id';

/**
* /users/sign-in
Expand Down Expand Up @@ -73,6 +73,7 @@ export class LogInPasswordComponent implements OnInit {
*/
public canRegister$: Observable<boolean>;


constructor(
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
@Inject('isStandalonePage') public isStandalonePage: boolean,
Expand Down

0 comments on commit 5320325

Please sign in to comment.