2020-11-11 15:43:13 +01:00
|
|
|
import {tap} 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';
|
2020-07-17 01:08:10 +02:00
|
|
|
import {Observable, Subscription} 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';
|
2020-07-17 01:08:10 +02:00
|
|
|
import {properties} from "../../../../environments/environment";
|
2018-03-27 10:22:55 +02:00
|
|
|
|
|
|
|
@Injectable()
|
2019-02-26 14:57:04 +01:00
|
|
|
export class ConnectRIGuard implements CanActivate, CanLoad {
|
2020-07-17 01:08:10 +02:00
|
|
|
sub: Subscription = null;
|
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 {
|
2020-11-11 15:43:13 +01:00
|
|
|
return this.communityService.isRITypeByState(properties, properties['communityAPI'] + community).pipe(tap(authorized => {
|
|
|
|
if (!authorized) {
|
|
|
|
this.router.navigate(['errorcommunity']);
|
|
|
|
}
|
|
|
|
}));
|
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
|
|
|
}
|
2020-07-17 01:08:10 +02:00
|
|
|
|
|
|
|
canDeactivate() {
|
|
|
|
if(this.sub) {
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-27 10:22:55 +02:00
|
|
|
}
|