git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@54948 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
84fdb271f5
commit
8edba0b65c
|
@ -33,8 +33,8 @@ export class ApprovedByCommunityComponent {
|
|||
communityId => {
|
||||
this.communityId = communityId['communityId'];
|
||||
|
||||
if(!this.communityId && (typeof document !== 'undefined')){
|
||||
this.communityId = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
||||
if(!this.communityId){
|
||||
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
|
||||
}
|
||||
|
||||
if(this.communityId && this.communityId != "openaire") {
|
||||
|
|
|
@ -15,16 +15,16 @@ export class ConnectSubscriberGuard implements CanActivate, CanLoad {
|
|||
|
||||
check(community: string, path: string): Observable<boolean> | boolean {
|
||||
let errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
||||
if (!community && (typeof document !== 'undefined')) {
|
||||
community = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
||||
}
|
||||
if (!Session.isLoggedIn()) {
|
||||
errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
this.router.navigate(['/user-info'], {queryParams: {'errorCode': errorCode, 'redirectUrl': path}});
|
||||
return false;
|
||||
} else {
|
||||
const obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => {
|
||||
return this.communityService.isSubscribedToCommunity(community, Session.getUserEmail(), properties['adminToolsAPIURL']);
|
||||
if(!community){
|
||||
community = ConnectHelper.getCommunityFromDomain(properties.domain);
|
||||
}
|
||||
return this.communityService.isSubscribedToCommunity( community, Session.getUserEmail(), properties["adminToolsAPIURL"])
|
||||
});
|
||||
obs.filter(enabled => !enabled)
|
||||
.subscribe(() => this.router.navigate(['/user-info'], {
|
||||
|
@ -40,10 +40,10 @@ export class ConnectSubscriberGuard implements CanActivate, CanLoad {
|
|||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
return this.check(route.queryParams['communityId'], state.url);
|
||||
}
|
||||
|
||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||
const path = '/' + route.path;
|
||||
return this.check(ConnectHelper.getCommunityFromPath(path), path);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import {HttpParams} from '@angular/common/http';
|
|||
export class ConnectHelper {
|
||||
|
||||
public static getCommunityFromDomain(domain: string): string{
|
||||
// domain = "beta.egi.openaire.eu"; for testing
|
||||
// domain = "beta.egi.openaire.eu"; //for testing
|
||||
if (domain.indexOf('openaire.eu') === -1) {
|
||||
return null;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ export class ConnectHelper {
|
|||
} else {
|
||||
domain = domain.substr(0, domain.indexOf('.'));
|
||||
}
|
||||
if (domain === 'connect' || domain === 'explore') {
|
||||
if(domain == "connect" || domain == "explore" || domain == "monitor"){
|
||||
return null;
|
||||
}
|
||||
return domain;
|
||||
|
|
|
@ -52,13 +52,11 @@ export class MailPrefsComponent {
|
|||
this.route.data
|
||||
.subscribe((data: { envSpecific: EnvProperties }) => {
|
||||
this.properties = data.envSpecific;
|
||||
});
|
||||
|
||||
this.sub = this.route.queryParams.subscribe(params => {
|
||||
this.communityId = params['communityId'];
|
||||
|
||||
if(!this.communityId && (typeof document !== 'undefined')){
|
||||
this.communityId = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
||||
if(!this.communityId){
|
||||
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
|
||||
}
|
||||
|
||||
this.fetchId = Session.getUserEmail();
|
||||
|
@ -66,6 +64,8 @@ export class MailPrefsComponent {
|
|||
this.getEmailPreferences();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
getEmailPreferences() {
|
||||
|
|
|
@ -25,25 +25,26 @@ export class IsRouteEnabled implements CanActivate, CanLoad {
|
|||
if (!community && data['community']) { // for openaire
|
||||
community = data['community'];
|
||||
}
|
||||
if (!community && typeof document !== 'undefined') {
|
||||
community = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
||||
}
|
||||
if (community) {
|
||||
const redirect = customRedirect ? customRedirect : '/error';
|
||||
const obs = this.propertiesService.subscribeEnvironment().map(res => res['adminToolsAPIURL']).mergeMap(url => {
|
||||
return this.config.isPageEnabled(url, community, '/' + path.split('?')[0].substring(1));
|
||||
const obs = this.propertiesService.subscribeEnvironment().map(res => {
|
||||
if(!community){
|
||||
community = ConnectHelper.getCommunityFromDomain(res.domain);
|
||||
}
|
||||
return res["adminToolsAPIURL"]
|
||||
}).mergeMap(url => {
|
||||
if(!community){ // no community to check - return true
|
||||
return Observable.of(true);
|
||||
}
|
||||
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 {
|
||||
return this.check(route.data, route.queryParams['communityId'], state.url);
|
||||
}
|
||||
|
||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||
const path = '/' + route;
|
||||
return this.check(route.data, ConnectHelper.getCommunityFromPath(path), path);
|
||||
|
|
|
@ -41,8 +41,8 @@ export class HelperComponent {
|
|||
this.route.queryParams.subscribe(
|
||||
params => {
|
||||
this.communityId = params['communityId'];
|
||||
if(!this.communityId && (typeof document !== 'undefined')){
|
||||
this.communityId = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
||||
if(!this.communityId){
|
||||
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
|
||||
}
|
||||
if(!this.communityId){
|
||||
this.communityId = this.properties.adminToolsCommunity;
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
|
|||
|
||||
export class EnvProperties {
|
||||
environment:string; //{beta,test,production, development}
|
||||
domain:string;
|
||||
enablePiwikTrack:boolean ;
|
||||
enableHelper:boolean;
|
||||
useCache:boolean ;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Injectable, OnInit, PLATFORM_ID, Inject,InjectionToken , Optional } from '@angular/core';
|
||||
import { Injectable, OnInit, PLATFORM_ID, Inject,InjectionToken , Optional, Injector } from '@angular/core';
|
||||
import { isPlatformBrowser} from '@angular/common';
|
||||
import { Http, Response, Headers, RequestOptions } from '@angular/http';
|
||||
import { Observable, Subscription, BehaviorSubject } from 'rxjs/Rx';
|
||||
|
@ -12,20 +12,13 @@ import { DOCUMENT } from '@angular/platform-browser';
|
|||
export class EnvironmentSpecificService {
|
||||
|
||||
public envSpecific: EnvProperties;
|
||||
public domain: string;
|
||||
public envSpecificNull: EnvProperties = null;
|
||||
testBrowser: boolean;
|
||||
private envSpecificSubject: BehaviorSubject<EnvProperties> = new BehaviorSubject<EnvProperties>(null);
|
||||
private propertiesUrl = "/assets/env-properties.json";
|
||||
|
||||
|
||||
private serverUrl = "http://scoobydoo.di.uoa.gr:4000";
|
||||
// private serverUrl = "https://beta.explore.openaire.eu";
|
||||
// private serverUrl = "https://beta.connect.openaire.eu";
|
||||
// private serverUrl = "https://beta.admin.connect.openaire.eu";
|
||||
// private serverUrl = "https://explore.openaire.eu";
|
||||
// private serverUrl = "https://connect.openaire.eu";
|
||||
// private serverUrl = "https://test.explore.openaire.eu";
|
||||
constructor(private http: Http, @Inject(PLATFORM_ID) private platformId: string) {
|
||||
constructor(private http: Http, @Inject(PLATFORM_ID) private platformId: string, private injector: Injector) {
|
||||
this.testBrowser = isPlatformBrowser(platformId);
|
||||
if (this.testBrowser) {
|
||||
//this is only executed on the browser
|
||||
|
@ -33,35 +26,65 @@ export class EnvironmentSpecificService {
|
|||
}
|
||||
public loadEnvironment() {
|
||||
// Only want to do this once - if root page is revisited, it calls this again.
|
||||
if (this.envSpecific === null || this.envSpecific === undefined) {
|
||||
var location = this.propertiesUrl;
|
||||
if(typeof document == 'undefined'){
|
||||
location = this.serverUrl + this.propertiesUrl;
|
||||
|
||||
}else{
|
||||
location = document.location.protocol +"//" + document.location.host+this.propertiesUrl;
|
||||
}
|
||||
//console.log('Loading '+ location);
|
||||
if (this.envSpecific === null || this.envSpecific === undefined) {
|
||||
var domain = this.getDomain();
|
||||
var location = this.getFullUrl();
|
||||
// console.log('loadEnvironment: Loading '+ location);
|
||||
return this.http.get(location)
|
||||
.map((data) => data.json())
|
||||
.map((data) => {
|
||||
var properties:EnvProperties=data.json();
|
||||
properties.domain = domain;
|
||||
this.envSpecific = properties;
|
||||
return properties;
|
||||
})
|
||||
.toPromise<EnvProperties>();
|
||||
}
|
||||
|
||||
return Promise.resolve(this.envSpecificNull);
|
||||
// console.log('loadEnvironment: already loaded ');
|
||||
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) {
|
||||
//console.log('Loading env-properties.json');
|
||||
|
||||
return this.http.get(this.propertiesUrl)
|
||||
.map((data) => data.json());
|
||||
var domain = this.getDomain();
|
||||
var location = this.getFullUrl();
|
||||
// console.log('subscribeEnvironment: Loading '+ location);
|
||||
return this.http.get(location)
|
||||
.map((data) => {
|
||||
var properties:EnvProperties=data.json();
|
||||
properties.domain = domain;
|
||||
this.envSpecific = properties;
|
||||
return properties;
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// console.log('subscribeEnvironment: already loaded ');
|
||||
return Observable.of(this.envSpecific);
|
||||
}
|
||||
|
||||
getFullUrl(){
|
||||
var location ="";
|
||||
var domain = "";
|
||||
if (typeof document == 'undefined') {
|
||||
let req = this.injector.get('request');
|
||||
domain = req.get('host').split(":")[0];
|
||||
location = (domain.indexOf(".openaire.eu")!=-1?"https://":"http://")+ req.get('host') + this.propertiesUrl;
|
||||
}else{
|
||||
location = document.location.protocol +"//" + document.location.host+this.propertiesUrl;
|
||||
domain = document.location.hostname;
|
||||
}
|
||||
return location;
|
||||
}
|
||||
getDomain(){
|
||||
var domain = "";
|
||||
if (typeof document == 'undefined') {
|
||||
let req = this.injector.get('request');
|
||||
domain = req.get('host').split(":")[0];
|
||||
}else{
|
||||
domain = document.location.hostname;
|
||||
}
|
||||
return domain;
|
||||
}
|
||||
|
||||
public setEnvProperties(es: EnvProperties) {
|
||||
// This has already been set so bail out.
|
||||
|
|
|
@ -12,8 +12,8 @@ export class EnvironmentSpecificResolver implements Resolve<EnvProperties> {
|
|||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<EnvProperties> {
|
||||
return this.envSpecificSvc.loadEnvironment()
|
||||
.then(es => {
|
||||
this.envSpecificSvc.setEnvProperties(es);
|
||||
return this.envSpecificSvc.envSpecific;
|
||||
|
||||
return es;
|
||||
}, error => {
|
||||
console.log(error);
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue