[Library | Trunk]: Fix parse roles for userinfo

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59250 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2020-08-11 12:54:14 +00:00
parent 99198fb0d9
commit c1977b1404
3 changed files with 26 additions and 30 deletions

View File

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

View File

@ -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 {

View File

@ -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<any>((resolve => {
const token = COOKIE.getCookie('AccessToken');
if (!token) {
this.getUserInfoSubject.next(null);
resolve();
} else {
this.http.get<User>(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,7 +38,14 @@ export class UserManagementService {
}
public updateUserInfo(resolve: Function = null) {
this.http.get<User>(properties.userInfoUrl, CustomOptions.registryOptions()).pipe(map(userInfo => {
const token = COOKIE.getCookie('AccessToken');
if (!token) {
this.getUserInfoSubject.next(null);
if(resolve) {
resolve();
}
} else {
this.http.get<User>(properties.userInfoUrl + token).pipe(map(userInfo => {
return this.parseUserInfo(userInfo);
})).pipe(timeout(3000), catchError(() => {
return of(null);
@ -63,6 +56,7 @@ export class UserManagementService {
}
});
}
}
private async getUserInfoAsync(): Promise<User> {
await this.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;