fix issue where create com/col guards would redirect to 404 for the wrong reason

This commit is contained in:
Art Lowel
2020-07-02 18:28:30 +02:00
parent c36877ae3a
commit fe785f6d2f
2 changed files with 18 additions and 25 deletions

View File

@@ -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,12 +28,9 @@ export class CreateCollectionPageGuard implements CanActivate {
this.router.navigate(['/404']);
return observableOf(false);
}
const parent: Observable<RemoteData<Community>> = this.communityService.findById(parentID)
return this.communityService.findById(parentID)
.pipe(
getFinishedRemoteData(),
);
return parent.pipe(
find((communityRD: RemoteData<Community>) => hasValue(communityRD.payload) || hasValue(communityRD.error)),
map((communityRD: RemoteData<Community>) => hasValue(communityRD) && communityRD.hasSucceeded && hasValue(communityRD.payload)),
tap((isValid: boolean) => {
if (!isValid) {

View File

@@ -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<RemoteData<Community>> = this.communityService.findById(parentID)
return this.communityService.findById(parentID)
.pipe(
getFinishedRemoteData(),
);
return parent.pipe(
find((communityRD: RemoteData<Community>) => hasValue(communityRD.payload) || hasValue(communityRD.error)),
map((communityRD: RemoteData<Community>) => hasValue(communityRD) && communityRD.hasSucceeded && hasValue(communityRD.payload)),
tap((isValid: boolean) => {
if (!isValid) {
this.router.navigate(['/404']);
}
})
}
)
);
}
}