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