[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:
k.triantafyllou 2020-07-02 15:02:14 +00:00
parent 885999c8ad
commit 34fbdcf44b
7 changed files with 10 additions and 12 deletions

View File

@ -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().pipe(map(user => {
return this.userManagementService.getUserInfo(false).pipe(map(user => {
if (user) {
email = user.email;
if (Session.isPortalAdministrator(user) || Session.isCommunityCurator(user)) {

View File

@ -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().pipe(map(user => {
return this.userManagementService.getUserInfo(false).pipe(map(user => {
if (user) {
errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
email = user.email;

View File

@ -19,7 +19,7 @@ export class IsCommunityOrAdmin implements CanActivate {
return true;
} else {
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);
}));
}));

View File

@ -15,7 +15,7 @@ export class AdminLoginGuard implements CanActivate {
check(path: string): Observable<boolean> {
let errorCode = LoginErrorCodes.NOT_LOGIN;
const obs = this.userManagementService.getUserInfo().pipe(map(user => {
const obs = this.userManagementService.getUserInfo(false).pipe(map(user => {
if (user) {
errorCode = LoginErrorCodes.NOT_ADMIN;
}

View File

@ -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().pipe(map(user => {
const obs = this.userManagementService.getUserInfo(false).pipe(map(user => {
if (user) {
errorCode = LoginErrorCodes.NOT_ADMIN;
}

View File

@ -15,7 +15,7 @@ export class LoginGuard implements CanActivate, CanLoad {
check(path: string): Observable<boolean> | boolean {
if (Session.isLoggedIn()) {
const obs = this.userManagementService.getUserInfo().pipe(map(user => {
const obs = this.userManagementService.getUserInfo(false).pipe(map(user => {
return user !== null;
}));
obs.pipe(filter(isLoggedIn => !isLoggedIn)).subscribe(() => {

View File

@ -13,12 +13,11 @@ 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);
@ -33,7 +32,7 @@ export class UserManagementService {
resolve();
});
}
});
}));
this.router.events.subscribe(event => {
if (event instanceof NavigationEnd) {
const token = COOKIE.getCookie('AccessToken');
@ -44,8 +43,8 @@ export class UserManagementService {
})
}
public getUserInfo(): Observable<User> {
if(this.initialized) {
public getUserInfo(subject: boolean = true): Observable<User> {
if(subject) {
return this.getUserInfoSubject.asObservable();
} else {
return from(this.getUserInfoAsync());
@ -54,7 +53,6 @@ export class UserManagementService {
private async getUserInfoAsync(): Promise<User> {
await this.promise;
this.initialized = true;
return this.getUserInfoSubject.getValue();
}