1. Pass argument of type: EnvProperties in connect services (used for cache).
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51662 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
b830fb2a78
commit
30f9ee87a7
|
@ -4,6 +4,7 @@ import {Headers, RequestOptions} from '@angular/http';
|
|||
import {Observable} from 'rxjs/Rx';
|
||||
|
||||
import {CommunityInfo} from '../community/communityInfo';
|
||||
import{EnvProperties} from '../../utils/properties/env-properties';
|
||||
|
||||
@Injectable()
|
||||
export class CommunitiesService {
|
||||
|
@ -11,8 +12,9 @@ export class CommunitiesService {
|
|||
constructor(private http:Http) {
|
||||
}
|
||||
|
||||
getCommunities(url: string) {
|
||||
return this.http.get(url).map(res => <any> res.json()).map(res => this.parseCommunities(res));
|
||||
getCommunities(properties:EnvProperties, url: string) {
|
||||
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url)
|
||||
.map(res => <any> res.json()).map(res => this.parseCommunities(res));
|
||||
}
|
||||
|
||||
parseCommunities(data: any): CommunityInfo[] {
|
||||
|
|
|
@ -4,6 +4,7 @@ import { Observable } from 'rxjs/Rx';
|
|||
|
||||
import { ResultInfo } from '../results/resultInfo';
|
||||
import { CommunityInfo } from './communityInfo';
|
||||
import{EnvProperties} from '../../utils/properties/env-properties';
|
||||
|
||||
@Injectable()
|
||||
export class CommunityService {
|
||||
|
@ -11,8 +12,9 @@ export class CommunityService {
|
|||
constructor(private http:Http) {
|
||||
}
|
||||
|
||||
getCommunity(url: string) {
|
||||
return this.http.get(url).map(res => <any> res.json()).map(res => this.parseCommunity(res));
|
||||
getCommunity(properties:EnvProperties, url: string) {
|
||||
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url)
|
||||
.map(res => <any> res.json()).map(res => this.parseCommunity(res));
|
||||
}
|
||||
|
||||
updateCommunity(url: string, community:any) {
|
||||
|
@ -28,11 +30,13 @@ export class CommunityService {
|
|||
.do(request => console.log("Insert Response:"+request.status));
|
||||
}
|
||||
|
||||
iscommunityManager(url: string, manager:string){
|
||||
return this.http.get(url).map(res => <any> res.json()).map(res => this.parseCommunity(res)).map(community => community.managers.indexOf(manager)!=-1);
|
||||
iscommunityManager(properties:EnvProperties, url: string, manager:string){
|
||||
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url)
|
||||
.map(res => <any> res.json()).map(res => this.parseCommunity(res)).map(community => community.managers.indexOf(manager)!=-1);
|
||||
}
|
||||
iscommunityRI(url: string){
|
||||
return this.http.get(url).map(res => <any> res.json()).map(res => this.parseCommunity(res)).map(community => (community && community.type && community.type !="community"));
|
||||
iscommunityRI(properties:EnvProperties, url: string){
|
||||
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url)
|
||||
.map(res => <any> res.json()).map(res => this.parseCommunity(res)).map(community => (community && community.type && community.type !="community"));
|
||||
}
|
||||
parseCommunity(data:any): CommunityInfo {
|
||||
|
||||
|
|
|
@ -6,11 +6,20 @@ import {ErrorCodes} from '../../login/utils/guardHelper.class';
|
|||
import {CommunityService} from '../community/community.service';
|
||||
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
|
||||
import { mergeMap } from 'rxjs/operators';
|
||||
import { EnvProperties} from '../../utils/properties/env-properties';
|
||||
|
||||
@Injectable()
|
||||
export class ConnectAdminLoginGuard implements CanActivate {
|
||||
properties:EnvProperties;
|
||||
|
||||
constructor(private router: Router, private communityService: CommunityService, private propertiesService:EnvironmentSpecificService ) {}
|
||||
constructor(private route: ActivatedRouteSnapshot, private router: Router, private communityService: CommunityService, private propertiesService:EnvironmentSpecificService ) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { envSpecific: EnvProperties }) => {
|
||||
this.properties = data.envSpecific;
|
||||
});
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
console.log(state.url);
|
||||
|
@ -33,7 +42,7 @@ export class ConnectAdminLoginGuard implements CanActivate {
|
|||
return true;
|
||||
}else {
|
||||
let obs = this.propertiesService.subscribeEnvironment().map(res=>res["communityAPI"]).mergeMap(url => {
|
||||
return this.communityService.iscommunityManager(url+community,Session.getUserEmail())});
|
||||
return this.communityService.iscommunityManager(this.properties, url+community,Session.getUserEmail())});
|
||||
obs.filter(enabled => !enabled)
|
||||
.subscribe(() => this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }));
|
||||
return obs;
|
||||
|
|
|
@ -6,11 +6,20 @@ import {ErrorCodes} from '../../login/utils/guardHelper.class';
|
|||
import {CommunityService} from '../community/community.service';
|
||||
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
|
||||
import { mergeMap } from 'rxjs/operators';
|
||||
import { EnvProperties} from '../../utils/properties/env-properties';
|
||||
|
||||
@Injectable()
|
||||
export class ConnectRIGuard implements CanActivate {
|
||||
properties:EnvProperties;
|
||||
|
||||
constructor(private router: Router, private communityService: CommunityService, private propertiesService:EnvironmentSpecificService ) {}
|
||||
constructor(private route: ActivatedRouteSnapshot, private router: Router, private communityService: CommunityService, private propertiesService:EnvironmentSpecificService ) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { envSpecific: EnvProperties }) => {
|
||||
this.properties = data.envSpecific;
|
||||
});
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
console.log(state.url);
|
||||
|
@ -33,7 +42,7 @@ export class ConnectRIGuard implements CanActivate {
|
|||
}else {
|
||||
|
||||
let obs = this.propertiesService.subscribeEnvironment().map(res=>res["communityAPI"]).mergeMap(url => {
|
||||
return this.communityService.iscommunityRI(url+community)});
|
||||
return this.communityService.iscommunityRI(this.properties, url+community)});
|
||||
obs.filter(enabled => !enabled)
|
||||
.subscribe(() => this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }));
|
||||
return obs;
|
||||
|
|
Loading…
Reference in New Issue