diff --git a/src/app/core/end-user-agreement/abstract-end-user-agreement.guard.ts b/src/app/core/end-user-agreement/abstract-end-user-agreement.guard.ts index 2f6bde11b9..7fc4cc3172 100644 --- a/src/app/core/end-user-agreement/abstract-end-user-agreement.guard.ts +++ b/src/app/core/end-user-agreement/abstract-end-user-agreement.guard.ts @@ -2,7 +2,6 @@ import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTr import { Observable } from 'rxjs/internal/Observable'; import { AuthService } from '../auth/auth.service'; import { returnEndUserAgreementUrlTreeOnFalse } from '../shared/operators'; -import { tap } from 'rxjs/operators'; /** * An abstract guard for redirecting users to the user agreement page if a certain condition is met @@ -22,13 +21,7 @@ export abstract class AbstractEndUserAgreementGuard implements CanActivate { */ canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { return this.hasAccepted().pipe( - returnEndUserAgreementUrlTreeOnFalse(this.router), - tap((result) => { - if (result instanceof UrlTree) { - this.authService.setRedirectUrl(state.url); - this.router.navigateByUrl(result); - } - }) + returnEndUserAgreementUrlTreeOnFalse(this.router, state.url) ); } diff --git a/src/app/core/shared/operators.ts b/src/app/core/shared/operators.ts index e9fe5fea2c..1018cee4ab 100644 --- a/src/app/core/shared/operators.ts +++ b/src/app/core/shared/operators.ts @@ -197,11 +197,12 @@ export const returnUnauthorizedUrlTreeOnFalse = (router: Router) => * Operator that returns a UrlTree to the unauthorized page when the boolean received is false * @param router */ -export const returnEndUserAgreementUrlTreeOnFalse = (router: Router) => +export const returnEndUserAgreementUrlTreeOnFalse = (router: Router, redirect: string) => (source: Observable): Observable => source.pipe( map((hasAgreed: boolean) => { - return hasAgreed ? hasAgreed : router.parseUrl(getEndUserAgreementPath()) + const queryParams = { redirect: encodeURIComponent(redirect) }; + return hasAgreed ? hasAgreed : router.createUrlTree([getEndUserAgreementPath()], { queryParams }); })); export const getFinishedRemoteData = () => diff --git a/src/app/info/end-user-agreement/end-user-agreement.component.ts b/src/app/info/end-user-agreement/end-user-agreement.component.ts index e258ba8878..539ca3308c 100644 --- a/src/app/info/end-user-agreement/end-user-agreement.component.ts +++ b/src/app/info/end-user-agreement/end-user-agreement.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { AuthService } from '../../core/auth/auth.service'; -import { switchMap, take } from 'rxjs/operators'; -import { Router } from '@angular/router'; +import { map, switchMap, take } from 'rxjs/operators'; +import { ActivatedRoute, Router } from '@angular/router'; import { Store } from '@ngrx/store'; import { AppState } from '../../app.reducer'; import { LogOutAction } from '../../core/auth/auth.actions'; @@ -9,7 +9,7 @@ import { EndUserAgreementService } from '../../core/end-user-agreement/end-user- import { NotificationsService } from '../../shared/notifications/notifications.service'; import { TranslateService } from '@ngx-translate/core'; import { of as observableOf } from 'rxjs'; -import { isNotEmpty } from '../../shared/empty.util'; +import { hasValue, isNotEmpty } from '../../shared/empty.util'; @Component({ selector: 'ds-end-user-agreement', @@ -31,7 +31,8 @@ export class EndUserAgreementComponent implements OnInit { protected translate: TranslateService, protected authService: AuthService, protected store: Store, - protected router: Router) { + protected router: Router, + protected route: ActivatedRoute) { } /** @@ -59,7 +60,7 @@ export class EndUserAgreementComponent implements OnInit { switchMap((success) => { if (success) { this.notificationsService.success(this.translate.instant('info.end-user-agreement.accept.success')); - return this.authService.getRedirectUrl(); + return this.route.queryParams.pipe(map((params) => params.redirect)); } else { this.notificationsService.error(this.translate.instant('info.end-user-agreement.accept.error')); return observableOf(undefined); @@ -68,7 +69,7 @@ export class EndUserAgreementComponent implements OnInit { take(1) ).subscribe((redirectUrl) => { if (isNotEmpty(redirectUrl)) { - this.router.navigateByUrl(redirectUrl); + this.router.navigateByUrl(decodeURIComponent(redirectUrl)); } }); }