37 lines
925 B
TypeScript
37 lines
925 B
TypeScript
|
import { Injectable } from '@angular/core';
|
||
|
import {
|
||
|
Router,
|
||
|
CanActivate,
|
||
|
ActivatedRouteSnapshot,
|
||
|
RouterStateSnapshot,
|
||
|
CanLoad, Route, UrlSegment
|
||
|
} from '@angular/router';
|
||
|
import {Observable} from 'rxjs';
|
||
|
|
||
|
import {ConnectHelper} from '../connectHelper';
|
||
|
import {Session} from '../../login/utils/helper.class';
|
||
|
|
||
|
@Injectable()
|
||
|
export class IsCommunityOrAdmin implements CanActivate {
|
||
|
|
||
|
constructor(private router: Router) {
|
||
|
}
|
||
|
|
||
|
check(community: string): Observable<boolean> | boolean {
|
||
|
if(Session.isLoggedIn() && Session.isPortalAdministrator()) {
|
||
|
return true;
|
||
|
}
|
||
|
else if (community && community !== 'undefined') {
|
||
|
return true;
|
||
|
} else {
|
||
|
this.router.navigate(['errorcommunity']);
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||
|
return this.check(route.queryParams['communityId']);
|
||
|
}
|
||
|
|
||
|
}
|