mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
72541: Redirect through query param at EndUserAgreement
This commit is contained in:
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -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 = () =>
|
||||
|
@@ -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));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user