2017-12-19 13:53:46 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
2018-02-05 14:14:59 +01:00
|
|
|
import {ActivatedRoute, Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {Observable} from 'rxjs/Observable';
|
|
|
|
import 'rxjs/add/operator/filter';
|
|
|
|
import { ConfigurationService } from '../utils/configuration/configuration.service';
|
2018-03-19 15:33:08 +01:00
|
|
|
import { EnvironmentSpecificService} from '../utils/properties/environment-specific.service';
|
2018-04-16 13:49:35 +02:00
|
|
|
import {ConnectHelper} from '../connect/connectHelper';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class IsRouteEnabled implements CanActivate {
|
|
|
|
|
2018-03-19 15:33:08 +01:00
|
|
|
constructor(private route: ActivatedRoute,private router: Router, private config: ConfigurationService, private propertiesService:EnvironmentSpecificService ) {}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
2018-03-13 17:02:22 +01:00
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
let customRedirect = route.data['redirect'];
|
2018-03-19 15:33:08 +01:00
|
|
|
let community = route.queryParams["communityId"];
|
|
|
|
if(!community && route.data['community']){ // for openaire
|
|
|
|
let community = route.data['community']
|
|
|
|
}
|
2018-06-12 12:40:51 +02:00
|
|
|
if(!community && typeof document != 'undefined'){
|
2018-04-16 13:49:35 +02:00
|
|
|
community = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
|
|
|
}
|
2018-03-19 15:33:08 +01:00
|
|
|
|
2018-03-13 17:02:22 +01:00
|
|
|
if(community){
|
|
|
|
let redirect = !!customRedirect ? customRedirect : '/error';
|
2018-03-19 15:33:08 +01:00
|
|
|
let obs = this.propertiesService.subscribeEnvironment().map(res=>res["adminToolsAPIURL"]).mergeMap(url => {
|
|
|
|
return this.config.isPageEnabled(url, community,"/"+state.url.split("?")[0].substring(1))});
|
|
|
|
obs.filter(enabled => !enabled)
|
2018-03-13 17:02:22 +01:00
|
|
|
.subscribe(() => this.router.navigate([redirect], { queryParams: { "page": state.url } }));
|
2018-03-19 15:33:08 +01:00
|
|
|
return obs;
|
2018-03-13 17:02:22 +01:00
|
|
|
}
|
|
|
|
return true;
|
2018-02-05 14:14:59 +01:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|