[Library | Trunk]: Delete properties resolver. Delete query param community id
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60771 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
180f39dec7
commit
1d358d65fb
|
@ -28,7 +28,8 @@ export class ConnectCommunityGuard implements CanActivate, CanActivateChild {
|
||||||
}
|
}
|
||||||
|
|
||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||||
return this.check(route.queryParams['communityId'], state.url);
|
let community = route.params['community'];
|
||||||
|
return community && this.check(community, state.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
import {filter, map, mergeMap, take} from 'rxjs/operators';
|
import {filter, map, mergeMap, take} from 'rxjs/operators';
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router';
|
import {
|
||||||
|
ActivatedRouteSnapshot,
|
||||||
|
CanActivate,
|
||||||
|
CanActivateChild,
|
||||||
|
Router,
|
||||||
|
RouterStateSnapshot,
|
||||||
|
UrlTree
|
||||||
|
} from '@angular/router';
|
||||||
import {Observable, of} from 'rxjs';
|
import {Observable, of} from 'rxjs';
|
||||||
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
||||||
import {properties} from "../../../../environments/environment";
|
import {properties} from "../../../../environments/environment";
|
||||||
|
@ -9,17 +16,19 @@ import {Session} from "../../login/utils/helper.class";
|
||||||
import {UserManagementService} from "../../services/user-management.service";
|
import {UserManagementService} from "../../services/user-management.service";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ConnectSubscriberGuard implements CanActivate {
|
export class ConnectSubscriberGuard implements CanActivate, CanActivateChild {
|
||||||
|
|
||||||
constructor(private router: Router,
|
constructor(private router: Router,
|
||||||
private userManagementService: UserManagementService) {
|
private userManagementService: UserManagementService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
check(community: string, path: string): Observable<boolean> {
|
check(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
|
||||||
let errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
let errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
||||||
let communityDomain = ConnectHelper.getCommunityFromDomain(properties.domain);
|
let community;
|
||||||
if (communityDomain) {
|
if(properties.isDashboard) {
|
||||||
community = communityDomain;
|
community = route.params['community'];
|
||||||
|
} else {
|
||||||
|
community = ConnectHelper.getCommunityFromDomain(properties.domain);
|
||||||
}
|
}
|
||||||
const authorized = this.userManagementService.getUserInfo(false).pipe(take(1), map(user => {
|
const authorized = this.userManagementService.getUserInfo(false).pipe(take(1), map(user => {
|
||||||
if (user) {
|
if (user) {
|
||||||
|
@ -35,7 +44,7 @@ export class ConnectSubscriberGuard implements CanActivate {
|
||||||
this.router.navigate(['/user-info'], {
|
this.router.navigate(['/user-info'], {
|
||||||
queryParams: {
|
queryParams: {
|
||||||
'errorCode': errorCode,
|
'errorCode': errorCode,
|
||||||
'redirectUrl': path
|
'redirectUrl': state.url
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -43,7 +52,10 @@ export class ConnectSubscriberGuard implements CanActivate {
|
||||||
}
|
}
|
||||||
|
|
||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||||
return this.check(route.queryParams['communityId'], state.url);
|
return this.check(route, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||||
|
return this.check(childRoute, state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,10 +25,7 @@ export class IsCommunity implements CanActivate, CanActivateChild {
|
||||||
if(properties.isDashboard) {
|
if(properties.isDashboard) {
|
||||||
community = route.params['community'];
|
community = route.params['community'];
|
||||||
} else {
|
} else {
|
||||||
community = route.queryParams['communityId'];
|
community = ConnectHelper.getCommunityFromDomain(properties.domain);
|
||||||
if(!community) {
|
|
||||||
community = ConnectHelper.getCommunityFromDomain(properties.domain);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (community) {
|
if (community) {
|
||||||
return this.communityService.getCommunity(community).pipe(map(community => {
|
return this.communityService.getCommunity(community).pipe(map(community => {
|
||||||
|
@ -40,7 +37,7 @@ export class IsCommunity implements CanActivate, CanActivateChild {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
this.router.navigate(['error']);
|
this.router.navigate(['error'], {queryParams: {page: state.url}});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {properties} from "../../../environments/environment";
|
||||||
export class ConnectHelper {
|
export class ConnectHelper {
|
||||||
|
|
||||||
public static getCommunityFromDomain(domain: string): string{
|
public static getCommunityFromDomain(domain: string): string{
|
||||||
// domain = "beta.egi.openaire.eu"; //for testing
|
domain = "beta.egi.openaire.eu"; //for testing
|
||||||
domain = domain.indexOf("//") != -1? domain.split("//")[1]:domain; //remove https:// prefix
|
domain = domain.indexOf("//") != -1? domain.split("//")[1]:domain; //remove https:// prefix
|
||||||
if (domain.indexOf('openaire.eu') === -1) {
|
if (domain.indexOf('openaire.eu') === -1) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1,69 +1,27 @@
|
||||||
import {Observable, Subscription} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import {tap, take} from 'rxjs/operators';
|
import {take, tap} from 'rxjs/operators';
|
||||||
import { Injectable } from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {
|
import {ActivatedRouteSnapshot, CanActivate, Data, Router, RouterStateSnapshot} from '@angular/router';
|
||||||
Router,
|
import {ConfigurationService} from '../utils/configuration/configuration.service';
|
||||||
CanActivate,
|
|
||||||
ActivatedRouteSnapshot,
|
|
||||||
RouterStateSnapshot,
|
|
||||||
Data
|
|
||||||
} from '@angular/router';
|
|
||||||
|
|
||||||
import { ConfigurationService } from '../utils/configuration/configuration.service';
|
|
||||||
import {ConnectHelper} from '../connect/connectHelper';
|
import {ConnectHelper} from '../connect/connectHelper';
|
||||||
import {properties} from "../../../environments/environment";
|
import {properties} from "../../../environments/environment";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class IsRouteEnabled implements CanActivate {
|
export class IsRouteEnabled implements CanActivate {
|
||||||
sub: Subscription = null;
|
|
||||||
|
|
||||||
constructor(private router: Router,
|
constructor(private router: Router,
|
||||||
private config: ConfigurationService) {}
|
private config: ConfigurationService) {}
|
||||||
|
|
||||||
// check(data: Data, community: string, path: string): Observable<boolean> | boolean {
|
check(data: Data, path: string): Observable<boolean> | boolean {
|
||||||
// const customRedirect = data['redirect'];
|
|
||||||
//
|
|
||||||
// const redirect = customRedirect ? customRedirect : '/error';
|
|
||||||
// const obs = this.propertiesService.subscribeEnvironment().pipe(map(res => {
|
|
||||||
// let communityDomain = null;
|
|
||||||
// //if (!community) {
|
|
||||||
// communityDomain = ConnectHelper.getCommunityFromDomain(res.domain);
|
|
||||||
// //}
|
|
||||||
// if(communityDomain) {
|
|
||||||
// community = communityDomain;
|
|
||||||
// } else if (!community && data['community']) { // for openaire or connect
|
|
||||||
// community = data['community'];
|
|
||||||
// }
|
|
||||||
// return res;
|
|
||||||
// }),mergeMap(prop => {
|
|
||||||
// if (!community) {
|
|
||||||
// community = prop.adminToolsCommunity;
|
|
||||||
// }
|
|
||||||
// return this.config.isPageEnabled(prop, community, '/' + path);
|
|
||||||
// }),);
|
|
||||||
// console.log("check isRouteEnabled.guard : call isPageEnabled");
|
|
||||||
//
|
|
||||||
// obs.pipe(filter(enabled => !enabled))
|
|
||||||
// .subscribe(() => this.router.navigate([redirect], {queryParams: {'page': path}}));
|
|
||||||
// return obs;
|
|
||||||
// }
|
|
||||||
|
|
||||||
check(data: Data, community: string, path: string): Observable<boolean> | boolean {
|
|
||||||
const customRedirect = data['redirect'];
|
const customRedirect = data['redirect'];
|
||||||
|
|
||||||
const redirect = customRedirect ? customRedirect : '/error';
|
const redirect = customRedirect ? customRedirect : '/error';
|
||||||
let communityDomain = ConnectHelper.getCommunityFromDomain(properties.domain);
|
let community = ConnectHelper.getCommunityFromDomain(properties.domain);
|
||||||
|
if (!community && data['community']) { // for openaire or connect
|
||||||
if(communityDomain) {
|
|
||||||
community = communityDomain;
|
|
||||||
} else if (!community && data['community']) { // for openaire or connect
|
|
||||||
community = data['community'];
|
community = data['community'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!community) {
|
if (!community) {
|
||||||
community = properties.adminToolsCommunity;
|
community = properties.adminToolsCommunity;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.config.isPageEnabledByState(properties, community, '/'+path).pipe(take(1),tap((enabled) => {
|
return this.config.isPageEnabledByState(properties, community, '/'+path).pipe(take(1),tap((enabled) => {
|
||||||
if(!enabled){
|
if(!enabled){
|
||||||
this.router.navigate([redirect], {queryParams: {'page': path}});
|
this.router.navigate([redirect], {queryParams: {'page': path}});
|
||||||
|
@ -73,7 +31,7 @@ export class IsRouteEnabled implements CanActivate {
|
||||||
}
|
}
|
||||||
|
|
||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||||
return this.check(route.data, route.queryParams['communityId'], state.url);
|
return this.check(route.data, state.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,16 @@
|
||||||
import {Inject, Injectable, Optional} from '@angular/core';
|
import {Inject, Injectable, Optional} from '@angular/core';
|
||||||
import {HttpClient} from "@angular/common/http";
|
import {HttpClient} from "@angular/common/http";
|
||||||
import {BehaviorSubject, of} from 'rxjs';
|
|
||||||
|
|
||||||
import {Request} from 'express';
|
import {Request} from 'express';
|
||||||
import {REQUEST} from '@nguniversal/express-engine/tokens';
|
import {REQUEST} from '@nguniversal/express-engine/tokens';
|
||||||
|
|
||||||
import {EnvProperties} from './env-properties';
|
|
||||||
import {properties} from "../../../../environments/environment";
|
import {properties} from "../../../../environments/environment";
|
||||||
import {ConnectHelper} from "../../connect/connectHelper";
|
import {ConnectHelper} from "../../connect/connectHelper";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
export class EnvironmentSpecificService {
|
export class EnvironmentSpecificService {
|
||||||
|
|
||||||
public envSpecific: EnvProperties;
|
|
||||||
public domain: string;
|
|
||||||
private envSpecificSubject: BehaviorSubject<EnvProperties> = new BehaviorSubject<EnvProperties>(null);
|
|
||||||
|
|
||||||
constructor(private http: HttpClient, @Optional() @Inject(REQUEST) private request: Request) {
|
constructor(private http: HttpClient, @Optional() @Inject(REQUEST) private request: Request) {
|
||||||
if(properties.adminToolsCommunity == "connect") {
|
if(properties.adminToolsCommunity == "connect") {
|
||||||
if(properties.environment == "development"){
|
if(properties.environment == "development"){
|
||||||
|
@ -32,21 +27,7 @@ export class EnvironmentSpecificService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public loadEnvironment() {
|
private getDomain() {
|
||||||
this.envSpecific = properties;
|
|
||||||
return Promise.resolve(this.envSpecific);
|
|
||||||
}
|
|
||||||
|
|
||||||
public subscribeEnvironment() {
|
|
||||||
// Only want to do this once - if root page is revisited, it calls this again.
|
|
||||||
if (this.envSpecific === null || this.envSpecific === undefined) {
|
|
||||||
this.envSpecific = properties;
|
|
||||||
}
|
|
||||||
// console.log('subscribeEnvironment: already loaded ');
|
|
||||||
return of(this.envSpecific);
|
|
||||||
}
|
|
||||||
|
|
||||||
getDomain() {
|
|
||||||
var domain = "";
|
var domain = "";
|
||||||
if (typeof document == 'undefined') {
|
if (typeof document == 'undefined') {
|
||||||
domain = this.request.get('host').split(":")[0];
|
domain = this.request.get('host').split(":")[0];
|
||||||
|
@ -55,28 +36,4 @@ export class EnvironmentSpecificService {
|
||||||
}
|
}
|
||||||
return domain;
|
return domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public setEnvProperties(es: EnvProperties) {
|
|
||||||
// This has already been set so bail out.
|
|
||||||
if (es === null || es === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.envSpecific = es;
|
|
||||||
if (this.envSpecificSubject) {
|
|
||||||
this.envSpecificSubject.next(this.envSpecific);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Call this if you want to know when EnvProperties is set.
|
|
||||||
*/
|
|
||||||
public subscribe(caller: any, callback: (caller: any, es: EnvProperties) => void) {
|
|
||||||
this.envSpecificSubject
|
|
||||||
.subscribe((es) => {
|
|
||||||
if (es === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
callback(caller, es);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
import { Injectable } from '@angular/core';
|
|
||||||
import { Router, Resolve, RouterStateSnapshot,
|
|
||||||
ActivatedRouteSnapshot } from '@angular/router';
|
|
||||||
|
|
||||||
import { EnvProperties } from './env-properties';
|
|
||||||
import { EnvironmentSpecificService } from './environment-specific.service';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class EnvironmentSpecificResolver implements Resolve<EnvProperties> {
|
|
||||||
constructor(private envSpecificSvc: EnvironmentSpecificService, private router: Router) {}
|
|
||||||
|
|
||||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<EnvProperties> {
|
|
||||||
return this.envSpecificSvc.loadEnvironment()
|
|
||||||
.then(es => {
|
|
||||||
|
|
||||||
return es;
|
|
||||||
}, error => {
|
|
||||||
console.log(error);
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue