[Library | Trunk]: Remove parameter from userInfo.
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59040 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
09fa6aa94b
commit
885999c8ad
|
@ -28,7 +28,7 @@ export class ConnectAdminLoginGuard implements CanActivate, CanLoad {
|
|||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
let email = null;
|
||||
const authorized = this.propertiesService.subscribeEnvironment().pipe(map(res => res), mergeMap(properties => {
|
||||
return this.userManagementService.getUserInfo(false).pipe(map(user => {
|
||||
return this.userManagementService.getUserInfo().pipe(map(user => {
|
||||
if (user) {
|
||||
email = user.email;
|
||||
if (Session.isPortalAdministrator(user) || Session.isCommunityCurator(user)) {
|
||||
|
|
|
@ -23,7 +23,7 @@ export class ConnectSubscriberGuard implements CanActivate {
|
|||
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 => {
|
||||
return this.userManagementService.getUserInfo().pipe(map(user => {
|
||||
if (user) {
|
||||
errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
||||
email = user.email;
|
||||
|
|
|
@ -19,7 +19,7 @@ export class IsCommunityOrAdmin implements CanActivate {
|
|||
return true;
|
||||
} else {
|
||||
const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
|
||||
return this.userManagementService.getUserInfo(false).pipe(map(user => {
|
||||
return this.userManagementService.getUserInfo().pipe(map(user => {
|
||||
return Session.isPortalAdministrator(user);
|
||||
}));
|
||||
}));
|
||||
|
|
|
@ -15,7 +15,7 @@ export class AdminLoginGuard implements CanActivate {
|
|||
|
||||
check(path: string): Observable<boolean> {
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
const obs = this.userManagementService.getUserInfo(false).pipe(map(user => {
|
||||
const obs = this.userManagementService.getUserInfo().pipe(map(user => {
|
||||
if (user) {
|
||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ export class ClaimsCuratorGuard implements CanActivate {
|
|||
|
||||
check(path: string): Observable<boolean> | boolean {
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
const obs = this.userManagementService.getUserInfo(false).pipe(map(user => {
|
||||
const obs = this.userManagementService.getUserInfo().pipe(map(user => {
|
||||
if (user) {
|
||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ export class LoginGuard implements CanActivate, CanLoad {
|
|||
|
||||
check(path: string): Observable<boolean> | boolean {
|
||||
if (Session.isLoggedIn()) {
|
||||
const obs = this.userManagementService.getUserInfo(false).pipe(map(user => {
|
||||
const obs = this.userManagementService.getUserInfo().pipe(map(user => {
|
||||
return user !== null;
|
||||
}));
|
||||
obs.pipe(filter(isLoggedIn => !isLoggedIn)).subscribe(() => {
|
||||
|
|
|
@ -13,11 +13,12 @@ import {properties} from "../../../environments/environment";
|
|||
export class UserManagementService {
|
||||
|
||||
private getUserInfoSubject: BehaviorSubject<User> = new BehaviorSubject<User>(null);
|
||||
private initialized = false
|
||||
private readonly promise: Promise<User>;
|
||||
|
||||
constructor(private http: HttpClient,
|
||||
private router: Router) {
|
||||
this.promise = new Promise<any>((resolve => {
|
||||
this.promise = new Promise<any>(resolve => {
|
||||
const token = COOKIE.getCookie('AccessToken');
|
||||
if (!token) {
|
||||
this.getUserInfoSubject.next(null);
|
||||
|
@ -32,7 +33,7 @@ export class UserManagementService {
|
|||
resolve();
|
||||
});
|
||||
}
|
||||
}));
|
||||
});
|
||||
this.router.events.subscribe(event => {
|
||||
if (event instanceof NavigationEnd) {
|
||||
const token = COOKIE.getCookie('AccessToken');
|
||||
|
@ -43,8 +44,8 @@ export class UserManagementService {
|
|||
})
|
||||
}
|
||||
|
||||
public getUserInfo(subject: boolean = true): Observable<User> {
|
||||
if(subject) {
|
||||
public getUserInfo(): Observable<User> {
|
||||
if(this.initialized) {
|
||||
return this.getUserInfoSubject.asObservable();
|
||||
} else {
|
||||
return from(this.getUserInfoAsync());
|
||||
|
@ -53,6 +54,7 @@ export class UserManagementService {
|
|||
|
||||
private async getUserInfoAsync(): Promise<User> {
|
||||
await this.promise;
|
||||
this.initialized = true;
|
||||
return this.getUserInfoSubject.getValue();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue