[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:
parent
ae76e56dab
commit
59ff1cc209
|
@ -30,13 +30,10 @@ export class ConnectAdminLoginGuard implements CanActivate, CanLoad {
|
||||||
check(community: string, path: string): Observable<boolean> | boolean {
|
check(community: string, path: string): Observable<boolean> | boolean {
|
||||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||||
let email = null;
|
let email = null;
|
||||||
const authorized =
|
const authorized = this.userManagementService.getUserInfo(false).pipe(map(user => {
|
||||||
//this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
|
|
||||||
//return
|
|
||||||
this.userManagementService.getUserInfo(false).pipe(map(user => {
|
|
||||||
if (user) {
|
if (user) {
|
||||||
email = user.email;
|
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);
|
return of(true);
|
||||||
} else {
|
} else {
|
||||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
|
|
||||||
import {filter, map, mergeMap} from 'rxjs/operators';
|
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 {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanLoad, Route} from '@angular/router';
|
||||||
import {Observable, of} from 'rxjs';
|
import {Observable, of} from 'rxjs';
|
||||||
import {Session} from '../../login/utils/helper.class';
|
import {Session} from '../../login/utils/helper.class';
|
||||||
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
||||||
import {CommunityService} from '../community/community.service';
|
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 {ConnectHelper} from '../connectHelper';
|
||||||
import {UserManagementService} from "../../services/user-management.service";
|
import {UserManagementService} from "../../services/user-management.service";
|
||||||
import {SubscribeService} from "../../utils/subscribe/subscribe.service";
|
import {SubscribeService} from "../../utils/subscribe/subscribe.service";
|
||||||
|
import {properties} from "../../../../environments/environment";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ConnectSubscriberGuard implements CanActivate {
|
export class ConnectSubscriberGuard implements CanActivate {
|
||||||
|
@ -17,40 +17,43 @@ export class ConnectSubscriberGuard implements CanActivate {
|
||||||
private communityService: CommunityService,
|
private communityService: CommunityService,
|
||||||
private subscribeService: SubscribeService,
|
private subscribeService: SubscribeService,
|
||||||
private userManagementService: UserManagementService,
|
private userManagementService: UserManagementService,
|
||||||
private propertiesService: EnvironmentSpecificService) {}
|
private propertiesService: EnvironmentSpecificService) {
|
||||||
|
}
|
||||||
check(community: string, path: string): Observable<boolean> | boolean {
|
|
||||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
check(community: string, path: string): Observable<boolean> | boolean {
|
||||||
let email = null;
|
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||||
const subscribed = this.propertiesService.subscribeEnvironment().pipe(map(res => res), mergeMap(properties => {
|
let email = null;
|
||||||
return this.userManagementService.getUserInfo(false).pipe(map(user => {
|
const subscribed = this.userManagementService.getUserInfo(false).pipe(map(user => {
|
||||||
if (user) {
|
if (user) {
|
||||||
errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
||||||
email = user.email;
|
email = user.email;
|
||||||
let communityDomain = ConnectHelper.getCommunityFromDomain(properties.domain);
|
let communityDomain = ConnectHelper.getCommunityFromDomain(properties.domain);
|
||||||
if(communityDomain) {
|
if (communityDomain) {
|
||||||
community = communityDomain;
|
community = communityDomain;
|
||||||
}
|
}
|
||||||
return this.subscribeService.isSubscribedToCommunity(properties, community)
|
if (Session.isSubscriber('community', community, user)) {
|
||||||
} else {
|
return of(true);
|
||||||
return of(false);
|
}
|
||||||
}
|
return this.subscribeService.isSubscribedToCommunity(properties, community)
|
||||||
}), mergeMap( authorized => {
|
} else {
|
||||||
return authorized;
|
return of(false);
|
||||||
}));
|
}
|
||||||
}));
|
}), mergeMap(authorized => {
|
||||||
subscribed.pipe(filter(subscribed => !subscribed)).subscribe(() => {
|
return authorized;
|
||||||
this.router.navigate(['/user-info'], {
|
}));
|
||||||
queryParams: {
|
subscribed.pipe(filter(subscribed => !subscribed)).subscribe(() => {
|
||||||
'errorCode': errorCode,
|
this.router.navigate(['/user-info'], {
|
||||||
'redirectUrl': path
|
queryParams: {
|
||||||
}
|
'errorCode': errorCode,
|
||||||
})});
|
'redirectUrl': path
|
||||||
return subscribed;
|
}
|
||||||
}
|
})
|
||||||
|
});
|
||||||
|
return subscribed;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue