2018-04-16 13:49:35 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
|
|
|
|
import {Observable} from 'rxjs/Observable';
|
|
|
|
import {Session} from '../../login/utils/helper.class';
|
2018-11-01 18:20:05 +01:00
|
|
|
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
2018-04-16 13:49:35 +02:00
|
|
|
import {CommunityService} from '../community/community.service';
|
|
|
|
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
|
|
|
|
import { mergeMap } from 'rxjs/operators';
|
|
|
|
import {ConnectHelper} from '../connectHelper';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ConnectSubscriberGuard implements CanActivate {
|
|
|
|
constructor(private router: Router, private communityService: CommunityService, private propertiesService:EnvironmentSpecificService ) {}
|
|
|
|
|
|
|
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
|
|
|
console.log(state.url);
|
|
|
|
var user;
|
|
|
|
var authorized = false;
|
2018-11-01 18:20:05 +01:00
|
|
|
var errorCode = LoginErrorCodes.NOT_SUBSCIBER;
|
2018-04-16 13:49:35 +02:00
|
|
|
|
|
|
|
let community = (route.queryParams["communityId"]);
|
|
|
|
if(!community){
|
|
|
|
community = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
|
|
|
}
|
|
|
|
if(!Session.isLoggedIn()){
|
2018-11-01 18:20:05 +01:00
|
|
|
errorCode = LoginErrorCodes.NOT_LOGGIN;
|
2018-04-16 13:49:35 +02:00
|
|
|
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } });
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// if(Session.isPortalAdministrator() || Session.isCommunityCurator() || Session.isClaimsCurator()){
|
|
|
|
// authorized = true;
|
|
|
|
// return true;
|
|
|
|
//
|
|
|
|
// }else {
|
|
|
|
|
|
|
|
let obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => {
|
|
|
|
return this.communityService.isSubscribedToCommunity( community, Session.getUserEmail(), properties["adminToolsAPIURL"])});
|
|
|
|
obs.filter(enabled => !enabled)
|
|
|
|
.subscribe(() => this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }));
|
|
|
|
return obs;
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|