2019-06-03 15:20:36 +02:00
|
|
|
|
|
|
|
import {filter, mergeMap} from 'rxjs/operators';
|
2018-03-27 10:22:55 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
2019-02-26 14:57:04 +01:00
|
|
|
import {
|
|
|
|
Router,
|
|
|
|
CanActivate,
|
|
|
|
ActivatedRouteSnapshot,
|
|
|
|
RouterStateSnapshot,
|
|
|
|
CanLoad,
|
2019-06-03 15:20:36 +02:00
|
|
|
Route, UrlSegment
|
2019-02-26 14:57:04 +01:00
|
|
|
} from '@angular/router';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {Observable} from 'rxjs';
|
2018-03-27 10:22:55 +02:00
|
|
|
import {CommunityService} from '../community/community.service';
|
|
|
|
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
|
2019-02-27 11:39:13 +01:00
|
|
|
import {ConnectHelper} from '../connectHelper';
|
2018-03-27 10:22:55 +02:00
|
|
|
|
|
|
|
@Injectable()
|
2019-02-26 14:57:04 +01:00
|
|
|
export class ConnectRIGuard implements CanActivate, CanLoad {
|
2018-03-27 10:22:55 +02:00
|
|
|
|
2019-02-26 16:25:52 +01:00
|
|
|
constructor(private router: Router,
|
|
|
|
private communityService: CommunityService,
|
|
|
|
private propertiesService: EnvironmentSpecificService) {
|
|
|
|
}
|
2019-02-26 14:57:04 +01:00
|
|
|
|
2019-03-07 16:43:54 +01:00
|
|
|
check(community: string): Observable<boolean> | boolean {
|
2019-06-03 15:20:36 +02:00
|
|
|
const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
|
2019-03-07 16:43:54 +01:00
|
|
|
return this.communityService.isRIType(properties, properties['communityAPI'] + community);
|
2019-06-03 15:20:36 +02:00
|
|
|
}));
|
|
|
|
obs.pipe(filter(enabled => !enabled))
|
2019-03-07 16:43:54 +01:00
|
|
|
.subscribe(() => this.router.navigate(['errorcommunity']));
|
|
|
|
return obs;
|
2019-02-26 14:57:04 +01:00
|
|
|
}
|
2018-03-27 10:22:55 +02:00
|
|
|
|
2019-02-26 14:57:04 +01:00
|
|
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
2019-03-07 16:43:54 +01:00
|
|
|
return this.check(route.queryParams['communityId']);
|
2019-02-26 14:57:04 +01:00
|
|
|
}
|
2018-03-27 10:22:55 +02:00
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
canLoad(route: Route, segments: UrlSegment[]): Observable<boolean> | Promise<boolean> | boolean {
|
2019-03-04 14:23:01 +01:00
|
|
|
const path = '/' + route.path + document.location.search;
|
2019-03-07 16:43:54 +01:00
|
|
|
return this.check(ConnectHelper.getCommunityFromPath(path));
|
2018-03-27 10:22:55 +02:00
|
|
|
}
|
|
|
|
}
|