[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:
k.triantafyllou 2021-04-01 14:24:54 +00:00
parent 180f39dec7
commit 1d358d65fb
7 changed files with 39 additions and 136 deletions

View File

@ -28,7 +28,8 @@ export class ConnectCommunityGuard implements CanActivate, CanActivateChild {
}
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 {

View File

@ -1,6 +1,13 @@
import {filter, map, mergeMap, take} from 'rxjs/operators';
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 {LoginErrorCodes} from '../../login/utils/guardHelper.class';
import {properties} from "../../../../environments/environment";
@ -9,17 +16,19 @@ import {Session} from "../../login/utils/helper.class";
import {UserManagementService} from "../../services/user-management.service";
@Injectable()
export class ConnectSubscriberGuard implements CanActivate {
export class ConnectSubscriberGuard implements CanActivate, CanActivateChild {
constructor(private router: Router,
private userManagementService: UserManagementService) {
}
check(community: string, path: string): Observable<boolean> {
check(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
let errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
let communityDomain = ConnectHelper.getCommunityFromDomain(properties.domain);
if (communityDomain) {
community = communityDomain;
let community;
if(properties.isDashboard) {
community = route.params['community'];
} else {
community = ConnectHelper.getCommunityFromDomain(properties.domain);
}
const authorized = this.userManagementService.getUserInfo(false).pipe(take(1), map(user => {
if (user) {
@ -35,7 +44,7 @@ export class ConnectSubscriberGuard implements CanActivate {
this.router.navigate(['/user-info'], {
queryParams: {
'errorCode': errorCode,
'redirectUrl': path
'redirectUrl': state.url
}
})
});
@ -43,7 +52,10 @@ export class ConnectSubscriberGuard implements CanActivate {
}
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);
}
}

View File

@ -25,10 +25,7 @@ export class IsCommunity implements CanActivate, CanActivateChild {
if(properties.isDashboard) {
community = route.params['community'];
} else {
community = route.queryParams['communityId'];
if(!community) {
community = ConnectHelper.getCommunityFromDomain(properties.domain);
}
community = ConnectHelper.getCommunityFromDomain(properties.domain);
}
if (community) {
return this.communityService.getCommunity(community).pipe(map(community => {
@ -40,7 +37,7 @@ export class IsCommunity implements CanActivate, CanActivateChild {
}
}));
} else {
this.router.navigate(['error']);
this.router.navigate(['error'], {queryParams: {page: state.url}});
return false;
}
}

View File

@ -4,7 +4,7 @@ import {properties} from "../../../environments/environment";
export class ConnectHelper {
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
if (domain.indexOf('openaire.eu') === -1) {
return null;

View File

@ -1,69 +1,27 @@
import {Observable, Subscription} from 'rxjs';
import {tap, take} from 'rxjs/operators';
import { Injectable } from '@angular/core';
import {
Router,
CanActivate,
ActivatedRouteSnapshot,
RouterStateSnapshot,
Data
} from '@angular/router';
import { ConfigurationService } from '../utils/configuration/configuration.service';
import {Observable} from 'rxjs';
import {take, tap} from 'rxjs/operators';
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, CanActivate, Data, Router, RouterStateSnapshot} from '@angular/router';
import {ConfigurationService} from '../utils/configuration/configuration.service';
import {ConnectHelper} from '../connect/connectHelper';
import {properties} from "../../../environments/environment";
@Injectable()
export class IsRouteEnabled implements CanActivate {
sub: Subscription = null;
constructor(private router: Router,
private config: ConfigurationService) {}
// check(data: Data, community: string, 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 {
check(data: Data, path: string): Observable<boolean> | boolean {
const customRedirect = data['redirect'];
const redirect = customRedirect ? customRedirect : '/error';
let communityDomain = ConnectHelper.getCommunityFromDomain(properties.domain);
if(communityDomain) {
community = communityDomain;
} else if (!community && data['community']) { // for openaire or connect
let community = ConnectHelper.getCommunityFromDomain(properties.domain);
if (!community && data['community']) { // for openaire or connect
community = data['community'];
}
if (!community) {
community = properties.adminToolsCommunity;
}
return this.config.isPageEnabledByState(properties, community, '/'+path).pipe(take(1),tap((enabled) => {
if(!enabled){
this.router.navigate([redirect], {queryParams: {'page': path}});
@ -73,7 +31,7 @@ export class IsRouteEnabled implements CanActivate {
}
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);
}
}

View File

@ -1,21 +1,16 @@
import {Inject, Injectable, Optional} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {BehaviorSubject, of} from 'rxjs';
import {Request} from 'express';
import {REQUEST} from '@nguniversal/express-engine/tokens';
import {EnvProperties} from './env-properties';
import {properties} from "../../../../environments/environment";
import {ConnectHelper} from "../../connect/connectHelper";
@Injectable()
@Injectable({
providedIn: 'root'
})
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) {
if(properties.adminToolsCommunity == "connect") {
if(properties.environment == "development"){
@ -32,21 +27,7 @@ export class EnvironmentSpecificService {
}
}
public loadEnvironment() {
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() {
private getDomain() {
var domain = "";
if (typeof document == 'undefined') {
domain = this.request.get('host').split(":")[0];
@ -55,28 +36,4 @@ export class EnvironmentSpecificService {
}
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);
});
}
}

View File

@ -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;
});
}
}