Project

General

Profile

1

    
2
import {filter, mergeMap} from 'rxjs/operators';
3
import { Injectable } from '@angular/core';
4
import {
5
  Router,
6
  CanActivate,
7
  ActivatedRouteSnapshot,
8
  RouterStateSnapshot,
9
  CanLoad,
10
  Route
11
} from '@angular/router';
12
import {Observable} from 'rxjs';
13
import {CommunityService} from '../community/community.service';
14
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
15
import {ConnectHelper} from '../connectHelper';
16

    
17
@Injectable()
18
export class ConnectCommunityGuard implements  CanActivate {
19

    
20
  constructor(private router: Router,
21
              private communityService: CommunityService,
22
              private propertiesService: EnvironmentSpecificService) {
23
  }
24

    
25
  check(community: string): Observable<boolean> | boolean {
26
    const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
27
      return this.communityService.isCommunityType(properties, properties['communityAPI'] + community);
28
    }));
29
    obs.pipe(filter(enabled => !enabled))
30
        .subscribe(() => this.router.navigate(['errorcommunity']));
31
    return obs;
32
  }
33

    
34
  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
35
    return this.check(route.queryParams['communityId']);
36
  }
37
}
(4-4/7)