From fe785f6d2f7a18392fea35c706fbe7f7a9852e7f Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Thu, 2 Jul 2020 18:28:30 +0200 Subject: [PATCH] fix issue where create com/col guards would redirect to 404 for the wrong reason --- .../create-collection-page.guard.ts | 22 ++++++++----------- .../create-community-page.guard.ts | 21 ++++++++---------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/app/+collection-page/create-collection-page/create-collection-page.guard.ts b/src/app/+collection-page/create-collection-page/create-collection-page.guard.ts index 4cd842e926..5bcad1cbd7 100644 --- a/src/app/+collection-page/create-collection-page/create-collection-page.guard.ts +++ b/src/app/+collection-page/create-collection-page/create-collection-page.guard.ts @@ -5,8 +5,7 @@ import { hasNoValue, hasValue } from '../../shared/empty.util'; import { CommunityDataService } from '../../core/data/community-data.service'; import { RemoteData } from '../../core/data/remote-data'; import { Community } from '../../core/shared/community.model'; -import { getFinishedRemoteData } from '../../core/shared/operators'; -import { map, tap } from 'rxjs/operators'; +import { map, tap, find } from 'rxjs/operators'; import { Observable, of as observableOf } from 'rxjs'; /** @@ -29,18 +28,15 @@ export class CreateCollectionPageGuard implements CanActivate { this.router.navigate(['/404']); return observableOf(false); } - const parent: Observable> = this.communityService.findById(parentID) + return this.communityService.findById(parentID) .pipe( - getFinishedRemoteData(), - ); - - return parent.pipe( - map((communityRD: RemoteData) => hasValue(communityRD) && communityRD.hasSucceeded && hasValue(communityRD.payload)), - tap((isValid: boolean) => { - if (!isValid) { - this.router.navigate(['/404']); - } - }) + find((communityRD: RemoteData) => hasValue(communityRD.payload) || hasValue(communityRD.error)), + map((communityRD: RemoteData) => hasValue(communityRD) && communityRD.hasSucceeded && hasValue(communityRD.payload)), + tap((isValid: boolean) => { + if (!isValid) { + this.router.navigate(['/404']); + } + }) ); } } diff --git a/src/app/+community-page/create-community-page/create-community-page.guard.ts b/src/app/+community-page/create-community-page/create-community-page.guard.ts index 2ee5cb6064..de7026c887 100644 --- a/src/app/+community-page/create-community-page/create-community-page.guard.ts +++ b/src/app/+community-page/create-community-page/create-community-page.guard.ts @@ -5,8 +5,7 @@ import { hasNoValue, hasValue } from '../../shared/empty.util'; import { CommunityDataService } from '../../core/data/community-data.service'; import { RemoteData } from '../../core/data/remote-data'; import { Community } from '../../core/shared/community.model'; -import { getFinishedRemoteData } from '../../core/shared/operators'; -import { map, tap } from 'rxjs/operators'; +import { map, tap, find } from 'rxjs/operators'; import { Observable, of as observableOf } from 'rxjs'; /** @@ -29,18 +28,16 @@ export class CreateCommunityPageGuard implements CanActivate { return observableOf(true); } - const parent: Observable> = this.communityService.findById(parentID) + return this.communityService.findById(parentID) .pipe( - getFinishedRemoteData(), - ); - - return parent.pipe( - map((communityRD: RemoteData) => hasValue(communityRD) && communityRD.hasSucceeded && hasValue(communityRD.payload)), - tap((isValid: boolean) => { - if (!isValid) { - this.router.navigate(['/404']); + find((communityRD: RemoteData) => hasValue(communityRD.payload) || hasValue(communityRD.error)), + map((communityRD: RemoteData) => hasValue(communityRD) && communityRD.hasSucceeded && hasValue(communityRD.payload)), + tap((isValid: boolean) => { + if (!isValid) { + this.router.navigate(['/404']); + } } - }) + ) ); } }