[Trunk|Library]: All guards implement CanLoad. Need to be tested! CanActivate is now enabled
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@54906 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
5a685c160c
commit
0bddc14435
|
@ -1,5 +1,12 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
|
||||
import {
|
||||
Router,
|
||||
CanActivate,
|
||||
ActivatedRouteSnapshot,
|
||||
RouterStateSnapshot,
|
||||
ActivatedRoute,
|
||||
CanLoad, Route
|
||||
} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Session} from '../../login/utils/helper.class';
|
||||
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
||||
|
@ -8,29 +15,44 @@ import { EnvironmentSpecificService} from '../../utils/properties/environment-sp
|
|||
import { mergeMap } from 'rxjs/operators';
|
||||
|
||||
@Injectable()
|
||||
export class ConnectAdminLoginGuard implements CanActivate {
|
||||
constructor(private router: Router, private communityService: CommunityService, private propertiesService:EnvironmentSpecificService ) {}
|
||||
export class ConnectAdminLoginGuard implements CanActivate, CanLoad{
|
||||
constructor(private router: Router,
|
||||
private communityService: CommunityService,
|
||||
private propertiesService:EnvironmentSpecificService,
|
||||
private route: ActivatedRoute) {}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
check(path: string): Observable<boolean> | boolean {
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
let community = (route.queryParams["communityId"]);
|
||||
if(Session.isLoggedIn()){
|
||||
if(Session.isPortalAdministrator() || Session.isCommunityCurator()) {
|
||||
let community = this.route.queryParams["communityId"];
|
||||
if (Session.isLoggedIn()) {
|
||||
if (Session.isPortalAdministrator() || Session.isCommunityCurator()) {
|
||||
return true;
|
||||
} else {
|
||||
let obs = this.propertiesService.subscribeEnvironment().map(res=>res).mergeMap(properties => {
|
||||
return this.communityService.iscommunityManager(properties, properties["communityAPI"]+community,Session.getUserEmail())});
|
||||
let obs = this.propertiesService.subscribeEnvironment().map(res => res).mergeMap(properties => {
|
||||
return this.communityService.iscommunityManager(properties, properties["communityAPI"] + community, Session.getUserEmail())
|
||||
});
|
||||
obs.filter(enabled => !enabled)
|
||||
.subscribe(() => this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }));
|
||||
.subscribe(() => this.router.navigate(['/user-info'], {
|
||||
queryParams: {
|
||||
"errorCode": errorCode,
|
||||
"redirectUrl": path
|
||||
}
|
||||
}));
|
||||
return obs;
|
||||
}
|
||||
} else{
|
||||
errorCode =LoginErrorCodes.NOT_LOGIN;
|
||||
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } });
|
||||
} else {
|
||||
errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
this.router.navigate(['/user-info'], {queryParams: {"errorCode": errorCode, "redirectUrl": path}});
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
return this.check(state.url);
|
||||
}
|
||||
|
||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||
return this.check('/' + route.path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,36 +1,56 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
|
||||
import {
|
||||
Router,
|
||||
CanActivate,
|
||||
ActivatedRouteSnapshot,
|
||||
RouterStateSnapshot,
|
||||
CanLoad,
|
||||
Route, ActivatedRoute
|
||||
} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Session} from '../../login/utils/helper.class';
|
||||
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
||||
import {CommunityService} from '../community/community.service';
|
||||
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
|
||||
import { mergeMap } from 'rxjs/operators';
|
||||
|
||||
@Injectable()
|
||||
export class ConnectRIGuard implements CanActivate {
|
||||
constructor(private router: Router, private communityService: CommunityService, private propertiesService:EnvironmentSpecificService ) {}
|
||||
export class ConnectRIGuard implements CanActivate, CanLoad {
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
constructor(private router: Router, private communityService: CommunityService, private propertiesService:EnvironmentSpecificService, private route:ActivatedRoute) {}
|
||||
|
||||
check(path: string) : Observable<boolean> | boolean {
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
let community = (route.queryParams["communityId"]);
|
||||
if(Session.isLoggedIn()){
|
||||
let community = (this.route.queryParams["communityId"]);
|
||||
|
||||
if(Session.isLoggedIn()) {
|
||||
if(Session.isPortalAdministrator()) {
|
||||
return true;
|
||||
} else {
|
||||
let obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => {
|
||||
return this.communityService.iscommunityRI(properties, properties["communityAPI"]+community)});
|
||||
return this.communityService.iscommunityRI(properties, properties["communityAPI"] + community)
|
||||
});
|
||||
obs.filter(enabled => !enabled)
|
||||
.subscribe(() => this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }));
|
||||
.subscribe(() => this.router.navigate(['/user-info'], {
|
||||
queryParams: {
|
||||
"errorCode": errorCode,
|
||||
"redirectUrl": path
|
||||
}
|
||||
}));
|
||||
return obs;
|
||||
}
|
||||
} else{
|
||||
errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } });
|
||||
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": path } });
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
return this.check(state.url);
|
||||
}
|
||||
|
||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||
return this.check('/' + route.path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,22 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
|
||||
import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, ActivatedRoute} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Session} from '../../login/utils/helper.class';
|
||||
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
||||
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 ) {}
|
||||
constructor(private router: Router,
|
||||
private communityService: CommunityService,
|
||||
private propertiesService:EnvironmentSpecificService,
|
||||
private route: ActivatedRoute) {}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
//console.log(state.url);
|
||||
var user;
|
||||
var authorized = false;
|
||||
var errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
||||
|
||||
let community = (route.queryParams["communityId"]);
|
||||
let errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
||||
let community = this.route.queryParams["communityId"];
|
||||
if(!community && (typeof document !== 'undefined')){
|
||||
community = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
||||
}
|
||||
|
@ -27,19 +25,19 @@ export class ConnectSubscriberGuard implements CanActivate {
|
|||
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 {
|
||||
|
||||
else {
|
||||
let obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => {
|
||||
return this.communityService.isSubscribedToCommunity( community, Session.getUserEmail(), properties["adminToolsAPIURL"])});
|
||||
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 } }));
|
||||
.subscribe(() => this.router.navigate(['/user-info'], {
|
||||
queryParams: {
|
||||
"errorCode": errorCode,
|
||||
"redirectUrl": state.url
|
||||
}
|
||||
}));
|
||||
return obs;
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,23 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {ActivatedRoute, Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
|
||||
import {
|
||||
ActivatedRoute,
|
||||
Router,
|
||||
CanActivate,
|
||||
ActivatedRouteSnapshot,
|
||||
RouterStateSnapshot,
|
||||
CanLoad, Route
|
||||
} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import 'rxjs/add/operator/filter';
|
||||
|
||||
@Injectable()
|
||||
export class IsCommunity implements CanActivate {
|
||||
export class IsCommunity implements CanActivate, CanLoad {
|
||||
|
||||
constructor(private route: ActivatedRoute,private router: Router) {}
|
||||
constructor(private router: Router,
|
||||
private route: ActivatedRoute) {}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
let community = (route.queryParams["communityId"]);
|
||||
check(): Observable<boolean> | boolean {
|
||||
let community = this.route.queryParams["communityId"];
|
||||
if(community && community!="undefined"){
|
||||
return true;
|
||||
}else{
|
||||
|
@ -17,4 +25,12 @@ export class IsCommunity implements CanActivate {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
return this.check();
|
||||
}
|
||||
|
||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||
return this.check();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {ActivatedRoute, Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
|
||||
import {
|
||||
ActivatedRoute,
|
||||
Router,
|
||||
CanActivate,
|
||||
CanLoad,
|
||||
ActivatedRouteSnapshot,
|
||||
RouterStateSnapshot,
|
||||
Route
|
||||
} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import 'rxjs/add/operator/filter';
|
||||
import { ConfigurationService } from '../utils/configuration/configuration.service';
|
||||
|
@ -7,29 +15,35 @@ import { EnvironmentSpecificService} from '../utils/properties/environment-speci
|
|||
import {ConnectHelper} from '../connect/connectHelper';
|
||||
|
||||
@Injectable()
|
||||
export class IsRouteEnabled implements CanActivate {
|
||||
export class IsRouteEnabled implements CanActivate, CanLoad {
|
||||
|
||||
constructor(private route: ActivatedRoute,private router: Router, private config: ConfigurationService, private propertiesService:EnvironmentSpecificService ) {}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
|
||||
let customRedirect = route.data['redirect'];
|
||||
let community = route.queryParams["communityId"];
|
||||
if(!community && route.data['community']){ // for openaire
|
||||
let community = route.data['community']
|
||||
check(path: string): Observable<boolean> | boolean {
|
||||
let customRedirect = this.route.data['redirect'];
|
||||
let community = this.route.queryParams["communityId"];
|
||||
if(!community && this.route.data['community']){ // for openaire
|
||||
community = this.route.data['community'];
|
||||
}
|
||||
if(!community && typeof document != 'undefined'){
|
||||
community = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
||||
}
|
||||
|
||||
if(community){
|
||||
let redirect = !!customRedirect ? customRedirect : '/error';
|
||||
let redirect = customRedirect ? customRedirect : '/error';
|
||||
let obs = this.propertiesService.subscribeEnvironment().map(res=>res["adminToolsAPIURL"]).mergeMap(url => {
|
||||
return this.config.isPageEnabled(url, community,"/"+state.url.split("?")[0].substring(1))});
|
||||
return this.config.isPageEnabled(url, community,"/" + path.split("?")[0].substring(1))});
|
||||
obs.filter(enabled => !enabled)
|
||||
.subscribe(() => this.router.navigate([redirect], { queryParams: { "page": state.url } }));
|
||||
.subscribe(() => this.router.navigate([redirect], { queryParams: { "page": path } }));
|
||||
return obs;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
return this.check(state.url);
|
||||
}
|
||||
|
||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||
return this.check('/' + route.path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ export class ConfigurationService {
|
|||
isPageEnabled(APIUrl:string, community:string,router: string){
|
||||
return this.http.get(APIUrl + "/community/" + community+"/pages?page_route="+router)
|
||||
.map(res => res.json()).map(res => {
|
||||
var result = false;
|
||||
let result = false;
|
||||
if(res.length >0 && res[0].route == router){
|
||||
result = res[0].isEnabled;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue