Skip to content

Commit 0c1a726

Browse files
author
Andrea Barbasso
committed
Merged dspace-cris-2023_02_x into task/dspace-cris-2023_02_x/DSC-1841
2 parents a64aefe + f37dc08 commit 0c1a726

24 files changed

Lines changed: 286 additions & 51 deletions

src/app/app-routing.module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
import { ServerCheckGuard } from './core/server-check/server-check.guard';
4444
import { MenuResolver } from './menu.resolver';
4545
import { ThemedPageErrorComponent } from './page-error/themed-page-error.component';
46+
import { ForgotPasswordCheckGuard } from './core/rest-property/forgot-password-check-guard.guard';
4647
import { SUGGESTION_MODULE_PATH } from './suggestions-page/suggestions-page-routing-paths';
4748
import { RedirectService } from './redirect/redirect.service';
4849

@@ -99,7 +100,10 @@ import { RedirectService } from './redirect/redirect.service';
99100
path: FORGOT_PASSWORD_PATH,
100101
loadChildren: () => import('./forgot-password/forgot-password.module')
101102
.then((m) => m.ForgotPasswordModule),
102-
canActivate: [EndUserAgreementCurrentUserGuard]
103+
canActivate: [
104+
ForgotPasswordCheckGuard,
105+
EndUserAgreementCurrentUserGuard
106+
]
103107
},
104108
{
105109
path: COMMUNITY_MODULE_PATH,

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/core/locale/locale.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export class LocaleService {
5353
this.routeService.getQueryParameterValue('lang').subscribe(lang => {
5454
if (lang && this.translate.getLangs().includes(lang)) {
5555
this.setCurrentLanguageCode(lang);
56+
this.routeService.removeQueryParam('lang');
5657
}
5758
});
5859
}
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/core/services/route.service.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,23 @@ export class RouteService {
225225
}
226226
);
227227
}
228+
229+
/**
230+
* Remove a parameter from the current route
231+
* @param key The parameter name
232+
*/
233+
removeQueryParam(key: string) {
234+
let queryParams = { ...this.route.snapshot.queryParams };
235+
delete queryParams[key];
236+
237+
// Navigate to the same route with the updated queryParams
238+
this.router.navigate(
239+
[],
240+
{
241+
relativeTo: this.route,
242+
queryParams: queryParams,
243+
}
244+
);
245+
246+
}
228247
}

src/app/shared/cookies/browser-klaro.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ export class BrowserKlaroService extends KlaroService {
264264
* Show the cookie consent form
265265
*/
266266
showSettings() {
267-
this.lazyKlaro.then(({show}) => show(this.klaroConfig));
267+
void this.lazyKlaro.then(({show}) => show(this.klaroConfig, true));
268268
}
269269

270270
/**

src/app/shared/form/builder/ds-dynamic-form-ui/models/onebox/dynamic-onebox.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ export class DsDynamicOneboxComponent extends DsDynamicVocabularyComponent imple
323323
this.previousValue = result;
324324
this.cdr.detectChanges();
325325
}
326-
if (hasValue(this.currentValue.otherInformation)) {
326+
if (hasValue(this.currentValue?.otherInformation)) {
327327
const infoKeys = Object.keys(this.currentValue.otherInformation);
328328
this.setMultipleValuesForOtherInfo(infoKeys, this.currentValue);
329329
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
<ds-log-in-container [authMethod]="authMethod" [isStandalonePage]="isStandalonePage"></ds-log-in-container>
55
<div *ngIf="!last" class="dropdown-divider my-2"></div>
66
</ng-container>
7-
<div class="dropdown-divider"></div>
8-
<a class="dropdown-item" *ngIf="(canRegister$ | async) && showRegisterLink" [routerLink]="[getRegisterRoute()]" [attr.data-test]="'register' | dsBrowserOnly">{{"login.form.new-user" | translate}}</a>
9-
<a class="dropdown-item" [routerLink]="[getForgotRoute()]" [attr.data-test]="'forgot' | dsBrowserOnly">{{"login.form.forgot-password" | translate}}</a>
7+
<ng-container *ngIf="canShowDivider$ | async">
8+
<div class="mt-2">
9+
<a class="dropdown-item" *ngIf="canRegister$ | async" [routerLink]="[getRegisterRoute()]"
10+
[attr.data-test]="'register' | dsBrowserOnly">{{"login.form.new-user" | translate}}</a>
11+
<a class="dropdown-item" *ngIf="canForgot$ | async" [routerLink]="[getForgotRoute()]"
12+
[attr.data-test]="'forgot' | dsBrowserOnly">{{"login.form.forgot-password" | translate}}</a>
13+
</div>
14+
</ng-container>
1015
</div>

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ChangeDetectionStrategy, Component, Input, OnDestroy, OnInit } from '@angular/core';
2-
3-
import { Observable, Subscription } from 'rxjs';
4-
import { map } from 'rxjs/operators';
2+
import { Observable, Subscription, combineLatest } from 'rxjs';
3+
import { filter, map, shareReplay } from 'rxjs/operators';
54
import { select, Store } from '@ngrx/store';
65
import uniqBy from 'lodash/uniqBy';
76

@@ -67,6 +66,16 @@ export class LogInComponent implements OnInit, OnDestroy {
6766
*/
6867
canRegister$: Observable<boolean>;
6968

69+
/**
70+
* Whether or not the current user (or anonymous) is authorized to register an account
71+
*/
72+
canForgot$: Observable<boolean>;
73+
74+
/**
75+
* Shows the divider only if contains at least one link to show
76+
*/
77+
canShowDivider$: Observable<boolean>;
78+
7079
/**
7180
* Track subscription to unsubscribe on destroy
7281
* @private
@@ -106,6 +115,14 @@ export class LogInComponent implements OnInit, OnDestroy {
106115
});
107116

108117
this.canRegister$ = this.authorizationService.isAuthorized(FeatureID.EPersonRegistration);
118+
119+
this.canForgot$ = this.authorizationService.isAuthorized(FeatureID.EPersonForgotPassword).pipe(shareReplay(1));
120+
this.canShowDivider$ =
121+
combineLatest([this.canRegister$, this.canForgot$])
122+
.pipe(
123+
map(([canRegister, canForgot]) => canRegister || canForgot),
124+
filter(Boolean)
125+
);
109126
}
110127

111128
getRegisterRoute() {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import { AuthService } from '../../../../core/auth/auth.service';
1616
import { HardRedirectService } from '../../../../core/services/hard-redirect.service';
1717
import { CoreState } from '../../../../core/core-state.model';
1818
import { getForgotPasswordRoute, getRegisterRoute } from '../../../../app-routing-paths';
19-
import { FeatureID } from '../../../../core/data/feature-authorization/feature-id';
2019
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
20+
import { FeatureID } from '../../../../core/data/feature-authorization/feature-id';
2121

2222
/**
2323
* /users/sign-in
@@ -73,6 +73,7 @@ export class LogInPasswordComponent implements OnInit {
7373
*/
7474
public canRegister$: Observable<boolean>;
7575

76+
7677
constructor(
7778
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
7879
@Inject('isStandalonePage') public isStandalonePage: boolean,

0 commit comments

Comments
 (0)