argiro.kokogiannaki 2019-03-01 11:29:52 +00:00
parent 84fdb271f5
commit 8edba0b65c
9 changed files with 87 additions and 62 deletions

View File

@ -33,8 +33,8 @@ export class ApprovedByCommunityComponent {
communityId => { communityId => {
this.communityId = communityId['communityId']; this.communityId = communityId['communityId'];
if(!this.communityId && (typeof document !== 'undefined')){ if(!this.communityId){
this.communityId = ConnectHelper.getCommunityFromDomain(document.location.hostname); this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
} }
if(this.communityId && this.communityId != "openaire") { if(this.communityId && this.communityId != "openaire") {

View File

@ -15,16 +15,16 @@ export class ConnectSubscriberGuard implements CanActivate, CanLoad {
check(community: string, path: string): Observable<boolean> | boolean { check(community: string, path: string): Observable<boolean> | boolean {
let errorCode = LoginErrorCodes.NOT_SUBSCRIBER; let errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
if (!community && (typeof document !== 'undefined')) {
community = ConnectHelper.getCommunityFromDomain(document.location.hostname);
}
if (!Session.isLoggedIn()) { if (!Session.isLoggedIn()) {
errorCode = LoginErrorCodes.NOT_LOGIN; errorCode = LoginErrorCodes.NOT_LOGIN;
this.router.navigate(['/user-info'], {queryParams: {'errorCode': errorCode, 'redirectUrl': path}}); this.router.navigate(['/user-info'], {queryParams: {'errorCode': errorCode, 'redirectUrl': path}});
return false; return false;
} else { } else {
const obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => { 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) obs.filter(enabled => !enabled)
.subscribe(() => this.router.navigate(['/user-info'], { .subscribe(() => this.router.navigate(['/user-info'], {
@ -40,10 +40,10 @@ export class ConnectSubscriberGuard implements CanActivate, CanLoad {
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.queryParams['communityId'], state.url);
} }
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean { canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
const path = '/' + route.path; const path = '/' + route.path;
return this.check(ConnectHelper.getCommunityFromPath(path), path); return this.check(ConnectHelper.getCommunityFromPath(path), path);
} }
} }

View File

@ -3,7 +3,7 @@ import {HttpParams} from '@angular/common/http';
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
if (domain.indexOf('openaire.eu') === -1) { if (domain.indexOf('openaire.eu') === -1) {
return null; return null;
} }
@ -15,7 +15,7 @@ export class ConnectHelper {
} else { } else {
domain = domain.substr(0, domain.indexOf('.')); domain = domain.substr(0, domain.indexOf('.'));
} }
if (domain === 'connect' || domain === 'explore') { if(domain == "connect" || domain == "explore" || domain == "monitor"){
return null; return null;
} }
return domain; return domain;

View File

@ -52,13 +52,11 @@ export class MailPrefsComponent {
this.route.data this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => { .subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific; this.properties = data.envSpecific;
});
this.sub = this.route.queryParams.subscribe(params => { this.sub = this.route.queryParams.subscribe(params => {
this.communityId = params['communityId']; this.communityId = params['communityId'];
if(!this.communityId && (typeof document !== 'undefined')){ if(!this.communityId){
this.communityId = ConnectHelper.getCommunityFromDomain(document.location.hostname); this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
} }
this.fetchId = Session.getUserEmail(); this.fetchId = Session.getUserEmail();
@ -66,6 +64,8 @@ export class MailPrefsComponent {
this.getEmailPreferences(); this.getEmailPreferences();
}); });
});
} }
getEmailPreferences() { getEmailPreferences() {

View File

@ -25,25 +25,26 @@ export class IsRouteEnabled implements CanActivate, CanLoad {
if (!community && data['community']) { // for openaire if (!community && data['community']) { // for openaire
community = data['community']; community = data['community'];
} }
if (!community && typeof document !== 'undefined') {
community = ConnectHelper.getCommunityFromDomain(document.location.hostname);
}
if (community) {
const redirect = customRedirect ? customRedirect : '/error'; const redirect = customRedirect ? customRedirect : '/error';
const obs = this.propertiesService.subscribeEnvironment().map(res => res['adminToolsAPIURL']).mergeMap(url => { const obs = this.propertiesService.subscribeEnvironment().map(res => {
return this.config.isPageEnabled(url, community, '/' + path.split('?')[0].substring(1)); 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) obs.filter(enabled => !enabled)
.subscribe(() => this.router.navigate([redirect], {queryParams: {'page': path}})); .subscribe(() => this.router.navigate([redirect], {queryParams: {'page': path}}));
return obs; return obs;
} }
return true;
}
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, route.queryParams['communityId'], state.url);
} }
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean { canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
const path = '/' + route; const path = '/' + route;
return this.check(route.data, ConnectHelper.getCommunityFromPath(path), path); return this.check(route.data, ConnectHelper.getCommunityFromPath(path), path);

View File

@ -41,8 +41,8 @@ export class HelperComponent {
this.route.queryParams.subscribe( this.route.queryParams.subscribe(
params => { params => {
this.communityId = params['communityId']; this.communityId = params['communityId'];
if(!this.communityId && (typeof document !== 'undefined')){ if(!this.communityId){
this.communityId = ConnectHelper.getCommunityFromDomain(document.location.hostname); this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
} }
if(!this.communityId){ if(!this.communityId){
this.communityId = this.properties.adminToolsCommunity; this.communityId = this.properties.adminToolsCommunity;

View File

@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
export class EnvProperties { export class EnvProperties {
environment:string; //{beta,test,production, development} environment:string; //{beta,test,production, development}
domain:string;
enablePiwikTrack:boolean ; enablePiwikTrack:boolean ;
enableHelper:boolean; enableHelper:boolean;
useCache:boolean ; useCache:boolean ;

View File

@ -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 { isPlatformBrowser} from '@angular/common';
import { Http, Response, Headers, RequestOptions } from '@angular/http'; import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable, Subscription, BehaviorSubject } from 'rxjs/Rx'; import { Observable, Subscription, BehaviorSubject } from 'rxjs/Rx';
@ -12,20 +12,13 @@ import { DOCUMENT } from '@angular/platform-browser';
export class EnvironmentSpecificService { export class EnvironmentSpecificService {
public envSpecific: EnvProperties; public envSpecific: EnvProperties;
public domain: string;
public envSpecificNull: EnvProperties = null; public envSpecificNull: EnvProperties = null;
testBrowser: boolean; testBrowser: boolean;
private envSpecificSubject: BehaviorSubject<EnvProperties> = new BehaviorSubject<EnvProperties>(null); private envSpecificSubject: BehaviorSubject<EnvProperties> = new BehaviorSubject<EnvProperties>(null);
private propertiesUrl = "/assets/env-properties.json"; private propertiesUrl = "/assets/env-properties.json";
constructor(private http: Http, @Inject(PLATFORM_ID) private platformId: string, private injector: Injector) {
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) {
this.testBrowser = isPlatformBrowser(platformId); this.testBrowser = isPlatformBrowser(platformId);
if (this.testBrowser) { if (this.testBrowser) {
//this is only executed on the browser //this is only executed on the browser
@ -33,35 +26,65 @@ export class EnvironmentSpecificService {
} }
public loadEnvironment() { public loadEnvironment() {
// Only want to do this once - if root page is revisited, it calls this again. // 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{ if (this.envSpecific === null || this.envSpecific === undefined) {
location = document.location.protocol +"//" + document.location.host+this.propertiesUrl; var domain = this.getDomain();
} var location = this.getFullUrl();
//console.log('Loading '+ location); // console.log('loadEnvironment: Loading '+ location);
return this.http.get(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>(); .toPromise<EnvProperties>();
} }
// console.log('loadEnvironment: already loaded ');
return Promise.resolve(this.envSpecificNull); return Promise.resolve(this.envSpecific);
} }
public subscribeEnvironment() { public subscribeEnvironment() {
// Only want to do this once - if root page is revisited, it calls this again. // Only want to do this once - if root page is revisited, it calls this again.
if (this.envSpecific === null || this.envSpecific === undefined) { if (this.envSpecific === null || this.envSpecific === undefined) {
//console.log('Loading env-properties.json'); var domain = this.getDomain();
var location = this.getFullUrl();
return this.http.get(this.propertiesUrl) // console.log('subscribeEnvironment: Loading '+ location);
.map((data) => data.json()); 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); 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) { public setEnvProperties(es: EnvProperties) {
// This has already been set so bail out. // This has already been set so bail out.

View File

@ -12,8 +12,8 @@ export class EnvironmentSpecificResolver implements Resolve<EnvProperties> {
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<EnvProperties> { resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<EnvProperties> {
return this.envSpecificSvc.loadEnvironment() return this.envSpecificSvc.loadEnvironment()
.then(es => { .then(es => {
this.envSpecificSvc.setEnvProperties(es);
return this.envSpecificSvc.envSpecific; return es;
}, error => { }, error => {
console.log(error); console.log(error);
return null; return null;