[Library | Trunk]: Add new session methods on guards

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59232 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2020-08-06 20:01:37 +00:00
parent ae76e56dab
commit 59ff1cc209
2 changed files with 41 additions and 41 deletions

View File

@ -30,13 +30,10 @@ export class ConnectAdminLoginGuard implements CanActivate, CanLoad {
check(community: string, path: string): Observable<boolean> | boolean {
let errorCode = LoginErrorCodes.NOT_LOGIN;
let email = null;
const authorized =
//this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
//return
this.userManagementService.getUserInfo(false).pipe(map(user => {
const authorized = this.userManagementService.getUserInfo(false).pipe(map(user => {
if (user) {
email = user.email;
if (Session.isPortalAdministrator(user) || Session.isCommunityCurator(user)) {
if (Session.isPortalAdministrator(user) || Session.isCommunityCurator(user) || Session.isManager('community', community, user)) {
return of(true);
} else {
errorCode = LoginErrorCodes.NOT_ADMIN;

View File

@ -1,15 +1,15 @@
import {filter, map, mergeMap} from 'rxjs/operators';
import { Injectable } from '@angular/core';
import {Injectable} from '@angular/core';
import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanLoad, Route} from '@angular/router';
import {Observable, of} from 'rxjs';
import {Session} from '../../login/utils/helper.class';
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
import {CommunityService} from '../community/community.service';
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
import {EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
import {ConnectHelper} from '../connectHelper';
import {UserManagementService} from "../../services/user-management.service";
import {SubscribeService} from "../../utils/subscribe/subscribe.service";
import {properties} from "../../../../environments/environment";
@Injectable()
export class ConnectSubscriberGuard implements CanActivate {
@ -17,40 +17,43 @@ export class ConnectSubscriberGuard implements CanActivate {
private communityService: CommunityService,
private subscribeService: SubscribeService,
private userManagementService: UserManagementService,
private propertiesService: EnvironmentSpecificService) {}
check(community: string, path: string): Observable<boolean> | boolean {
let errorCode = LoginErrorCodes.NOT_LOGIN;
let email = null;
const subscribed = this.propertiesService.subscribeEnvironment().pipe(map(res => res), mergeMap(properties => {
return this.userManagementService.getUserInfo(false).pipe(map(user => {
if (user) {
errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
email = user.email;
let communityDomain = ConnectHelper.getCommunityFromDomain(properties.domain);
if(communityDomain) {
community = communityDomain;
}
return this.subscribeService.isSubscribedToCommunity(properties, community)
} else {
return of(false);
}
}), mergeMap( authorized => {
return authorized;
}));
}));
subscribed.pipe(filter(subscribed => !subscribed)).subscribe(() => {
this.router.navigate(['/user-info'], {
queryParams: {
'errorCode': errorCode,
'redirectUrl': path
}
})});
return subscribed;
}
private propertiesService: EnvironmentSpecificService) {
}
check(community: string, path: string): Observable<boolean> | boolean {
let errorCode = LoginErrorCodes.NOT_LOGIN;
let email = null;
const subscribed = this.userManagementService.getUserInfo(false).pipe(map(user => {
if (user) {
errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
email = user.email;
let communityDomain = ConnectHelper.getCommunityFromDomain(properties.domain);
if (communityDomain) {
community = communityDomain;
}
if (Session.isSubscriber('community', community, user)) {
return of(true);
}
return this.subscribeService.isSubscribedToCommunity(properties, community)
} else {
return of(false);
}
}), mergeMap(authorized => {
return authorized;
}));
subscribed.pipe(filter(subscribed => !subscribed)).subscribe(() => {
this.router.navigate(['/user-info'], {
queryParams: {
'errorCode': errorCode,
'redirectUrl': path
}
})
});
return subscribed;
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
return this.check(route.queryParams['communityId'], state.url);
}
}