diff --git a/connect/communityGuard/connectSubscriber.guard.ts b/connect/communityGuard/connectSubscriber.guard.ts index 42ff048d..54ac06cb 100644 --- a/connect/communityGuard/connectSubscriber.guard.ts +++ b/connect/communityGuard/connectSubscriber.guard.ts @@ -31,7 +31,7 @@ export class ConnectSubscriberGuard implements CanActivate { if (communityDomain) { community = communityDomain; } - if (Session.isSubscriber('community', community, user)) { + if (Session.isSubscribedTo('community', community, user)) { return of(true); } return this.subscribeService.isSubscribedToCommunity(properties, community) diff --git a/login/utils/helper.class.ts b/login/utils/helper.class.ts index 1a1c161a..96c08c73 100644 --- a/login/utils/helper.class.ts +++ b/login/utils/helper.class.ts @@ -80,8 +80,8 @@ export class Session{ user.role.indexOf('USER_MANAGER') !== -1); } - public static isSubscriber(type: string, id: string, user: User): boolean { - return user && user.role.indexOf(type.toUpperCase() + '_' + id.toUpperCase()) !== -1 + public static isSubscribedTo(type: string, id: string, user: User): boolean { + return user && user.role.indexOf(type.toUpperCase() + '_' + id.toUpperCase()) !== -1; } public static isManager(type: string, id: string, user: User): boolean { diff --git a/services/user-management.service.ts b/services/user-management.service.ts index 8d85468c..6c9d365a 100644 --- a/services/user-management.service.ts +++ b/services/user-management.service.ts @@ -5,7 +5,6 @@ import {COOKIE, User} from "../login/utils/helper.class"; import {catchError, map, timeout} from "rxjs/operators"; import {NavigationEnd, Router} from "@angular/router"; import {properties} from "../../../environments/environment"; -import {CustomOptions} from "./servicesUtils/customOptions.class"; @Injectable({ providedIn: 'root' @@ -18,20 +17,7 @@ export class UserManagementService { constructor(private http: HttpClient, private router: Router) { this.promise = new Promise((resolve => { - const token = COOKIE.getCookie('AccessToken'); - if (!token) { - this.getUserInfoSubject.next(null); - resolve(); - } else { - this.http.get(properties.userInfoUrl + token).pipe(map(userInfo => { - return this.parseUserInfo(userInfo); - })).pipe(timeout(3000), catchError(() => { - return of(null); - })).subscribe(user => { - this.getUserInfoSubject.next(user); - resolve(); - }); - } + this.updateUserInfo(resolve); })); this.router.events.subscribe(event => { if (event instanceof NavigationEnd) { @@ -52,16 +38,24 @@ export class UserManagementService { } public updateUserInfo(resolve: Function = null) { - this.http.get(properties.userInfoUrl, CustomOptions.registryOptions()).pipe(map(userInfo => { - return this.parseUserInfo(userInfo); - })).pipe(timeout(3000), catchError(() => { - return of(null); - })).subscribe(user => { - this.getUserInfoSubject.next(user); - if (resolve) { + const token = COOKIE.getCookie('AccessToken'); + if (!token) { + this.getUserInfoSubject.next(null); + if(resolve) { resolve(); } - }); + } else { + this.http.get(properties.userInfoUrl + token).pipe(map(userInfo => { + return this.parseUserInfo(userInfo); + })).pipe(timeout(3000), catchError(() => { + return of(null); + })).subscribe(user => { + this.getUserInfoSubject.next(user); + if(resolve) { + resolve(); + } + }); + } } private async getUserInfoAsync(): Promise { @@ -87,12 +81,14 @@ export class UserManagementService { user.fullname = "Anonymous user"; } } + user.role = []; if (info.edu_person_entitlements) { user.role = info.edu_person_entitlements; - } else if (info.roles) { - user.role = info.roles; - } else { - user.role = []; + } + if (info.roles) { + info.roles.forEach(role => { + user.role.push(role); + }); } user.expirationDate = info.exp_date; return user;