[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 { 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 {Observable} from 'rxjs/Observable';
|
||||||
import {Session} from '../../login/utils/helper.class';
|
import {Session} from '../../login/utils/helper.class';
|
||||||
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
||||||
|
@ -8,29 +15,44 @@ import { EnvironmentSpecificService} from '../../utils/properties/environment-sp
|
||||||
import { mergeMap } from 'rxjs/operators';
|
import { mergeMap } from 'rxjs/operators';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ConnectAdminLoginGuard implements CanActivate {
|
export class ConnectAdminLoginGuard implements CanActivate, CanLoad{
|
||||||
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 {
|
check(path: string): Observable<boolean> | boolean {
|
||||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||||
let community = (route.queryParams["communityId"]);
|
let community = this.route.queryParams["communityId"];
|
||||||
if(Session.isLoggedIn()){
|
if (Session.isLoggedIn()) {
|
||||||
if(Session.isPortalAdministrator() || Session.isCommunityCurator()) {
|
if (Session.isPortalAdministrator() || Session.isCommunityCurator()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
let obs = this.propertiesService.subscribeEnvironment().map(res=>res).mergeMap(properties => {
|
let obs = this.propertiesService.subscribeEnvironment().map(res => res).mergeMap(properties => {
|
||||||
return this.communityService.iscommunityManager(properties, properties["communityAPI"]+community,Session.getUserEmail())});
|
return this.communityService.iscommunityManager(properties, properties["communityAPI"] + community, Session.getUserEmail())
|
||||||
|
});
|
||||||
obs.filter(enabled => !enabled)
|
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;
|
return obs;
|
||||||
}
|
}
|
||||||
} else{
|
} else {
|
||||||
errorCode =LoginErrorCodes.NOT_LOGIN;
|
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;
|
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 { 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 {Observable} from 'rxjs/Observable';
|
||||||
import {Session} from '../../login/utils/helper.class';
|
import {Session} from '../../login/utils/helper.class';
|
||||||
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
||||||
import {CommunityService} from '../community/community.service';
|
import {CommunityService} from '../community/community.service';
|
||||||
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
|
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
|
||||||
import { mergeMap } from 'rxjs/operators';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ConnectRIGuard implements CanActivate {
|
export class ConnectRIGuard implements CanActivate, CanLoad {
|
||||||
constructor(private router: Router, private communityService: CommunityService, private propertiesService:EnvironmentSpecificService ) {}
|
|
||||||
|
|
||||||
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 errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||||
let community = (route.queryParams["communityId"]);
|
let community = (this.route.queryParams["communityId"]);
|
||||||
if(Session.isLoggedIn()){
|
|
||||||
|
if(Session.isLoggedIn()) {
|
||||||
if(Session.isPortalAdministrator()) {
|
if(Session.isPortalAdministrator()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
let obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => {
|
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)
|
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;
|
return obs;
|
||||||
}
|
}
|
||||||
} else{
|
} else{
|
||||||
errorCode = LoginErrorCodes.NOT_LOGIN;
|
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;
|
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 { 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 {Observable} from 'rxjs/Observable';
|
||||||
import {Session} from '../../login/utils/helper.class';
|
import {Session} from '../../login/utils/helper.class';
|
||||||
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
||||||
import {CommunityService} from '../community/community.service';
|
import {CommunityService} from '../community/community.service';
|
||||||
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
|
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
|
||||||
import { mergeMap } from 'rxjs/operators';
|
|
||||||
import {ConnectHelper} from '../connectHelper';
|
import {ConnectHelper} from '../connectHelper';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ConnectSubscriberGuard implements CanActivate {
|
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 {
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||||
//console.log(state.url);
|
let errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
||||||
var user;
|
let community = this.route.queryParams["communityId"];
|
||||||
var authorized = false;
|
|
||||||
var errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
|
||||||
|
|
||||||
let community = (route.queryParams["communityId"]);
|
|
||||||
if(!community && (typeof document !== 'undefined')){
|
if(!community && (typeof document !== 'undefined')){
|
||||||
community = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
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 } });
|
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// if(Session.isPortalAdministrator() || Session.isCommunityCurator() || Session.isClaimsCurator()){
|
else {
|
||||||
// authorized = true;
|
let obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => {
|
||||||
// return true;
|
return this.communityService.isSubscribedToCommunity(community, Session.getUserEmail(), properties["adminToolsAPIURL"])
|
||||||
//
|
});
|
||||||
// }else {
|
obs.filter(enabled => !enabled)
|
||||||
|
.subscribe(() => this.router.navigate(['/user-info'], {
|
||||||
let obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => {
|
queryParams: {
|
||||||
return this.communityService.isSubscribedToCommunity( community, Session.getUserEmail(), properties["adminToolsAPIURL"])});
|
"errorCode": errorCode,
|
||||||
obs.filter(enabled => !enabled)
|
"redirectUrl": state.url
|
||||||
.subscribe(() => this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }));
|
}
|
||||||
return obs;
|
}));
|
||||||
// }
|
return obs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,36 @@
|
||||||
import { Injectable } from '@angular/core';
|
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 {Observable} from 'rxjs/Observable';
|
||||||
import 'rxjs/add/operator/filter';
|
import 'rxjs/add/operator/filter';
|
||||||
|
|
||||||
@Injectable()
|
@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) {}
|
||||||
|
|
||||||
|
check(): Observable<boolean> | boolean {
|
||||||
|
let community = this.route.queryParams["communityId"];
|
||||||
|
if(community && community!="undefined"){
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
this.router.navigate(['errorcommunity']);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||||
let community = (route.queryParams["communityId"]);
|
return this.check();
|
||||||
if(community && community!="undefined"){
|
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
this.router.navigate(['errorcommunity']);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||||
|
return this.check();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
import { Injectable } from '@angular/core';
|
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 {Observable} from 'rxjs/Observable';
|
||||||
import 'rxjs/add/operator/filter';
|
import 'rxjs/add/operator/filter';
|
||||||
import { ConfigurationService } from '../utils/configuration/configuration.service';
|
import { ConfigurationService } from '../utils/configuration/configuration.service';
|
||||||
|
@ -7,29 +15,35 @@ import { EnvironmentSpecificService} from '../utils/properties/environment-speci
|
||||||
import {ConnectHelper} from '../connect/connectHelper';
|
import {ConnectHelper} from '../connect/connectHelper';
|
||||||
|
|
||||||
@Injectable()
|
@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 ) {}
|
constructor(private route: ActivatedRoute,private router: Router, private config: ConfigurationService, private propertiesService:EnvironmentSpecificService ) {}
|
||||||
|
|
||||||
|
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 obs = this.propertiesService.subscribeEnvironment().map(res=>res["adminToolsAPIURL"]).mergeMap(url => {
|
||||||
|
return this.config.isPageEnabled(url, community,"/" + path.split("?")[0].substring(1))});
|
||||||
|
obs.filter(enabled => !enabled)
|
||||||
|
.subscribe(() => this.router.navigate([redirect], { queryParams: { "page": path } }));
|
||||||
|
return obs;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||||
|
return this.check(state.url);
|
||||||
|
}
|
||||||
|
|
||||||
let customRedirect = route.data['redirect'];
|
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||||
let community = route.queryParams["communityId"];
|
return this.check('/' + route.path);
|
||||||
if(!community && route.data['community']){ // for openaire
|
}
|
||||||
let community = route.data['community']
|
|
||||||
}
|
|
||||||
if(!community && typeof document != 'undefined'){
|
|
||||||
community = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(community){
|
|
||||||
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))});
|
|
||||||
obs.filter(enabled => !enabled)
|
|
||||||
.subscribe(() => this.router.navigate([redirect], { queryParams: { "page": state.url } }));
|
|
||||||
return obs;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ export class ConfigurationService {
|
||||||
isPageEnabled(APIUrl:string, community:string,router: string){
|
isPageEnabled(APIUrl:string, community:string,router: string){
|
||||||
return this.http.get(APIUrl + "/community/" + community+"/pages?page_route="+router)
|
return this.http.get(APIUrl + "/community/" + community+"/pages?page_route="+router)
|
||||||
.map(res => res.json()).map(res => {
|
.map(res => res.json()).map(res => {
|
||||||
var result = false;
|
let result = false;
|
||||||
if(res.length >0 && res[0].route == router){
|
if(res.length >0 && res[0].route == router){
|
||||||
result = res[0].isEnabled;
|
result = res[0].isEnabled;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue