[Library]: Add guard to check if there is community or user is Portal Administrator.

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@56516 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-07-12 13:16:30 +00:00
parent c90a895e07
commit d75b540775
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
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']);
}
}