72541: Redirect through query param at EndUserAgreement

This commit is contained in:
Kristof De Langhe
2020-09-04 17:46:05 +02:00
parent bd522038a1
commit aa1b568bf4
3 changed files with 11 additions and 16 deletions

View File

@@ -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<boolean | UrlTree> {
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)
);
}

View File

@@ -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<boolean>): Observable<boolean | UrlTree> =>
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 = () =>

View File

@@ -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<AppState>,
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));
}
});
}