From 18f5b27100e9c2791deb54c7567c7922b478bb77 Mon Sep 17 00:00:00 2001 From: Alex ORLUC <alex.orluc@maarch.org> Date: Wed, 8 Apr 2020 19:50:35 +0200 Subject: [PATCH] FEAT #13667 TIME 1:30 fix error 401 state + fix jstree --- .../app/basket/basket-home.component.ts | 2 -- .../folder-pinned/folder-pinned.component.ts | 10 ++++---- src/frontend/app/notification.service.ts | 4 ++-- .../print-separator.component.ts | 6 ++--- src/frontend/service/app.guard.ts | 24 ++++++++++++++++--- .../service/auth-interceptor.service.ts | 6 ++--- 6 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/frontend/app/basket/basket-home.component.ts b/src/frontend/app/basket/basket-home.component.ts index f2f443a9807..d2274c84458 100755 --- a/src/frontend/app/basket/basket-home.component.ts +++ b/src/frontend/app/basket/basket-home.component.ts @@ -62,8 +62,6 @@ export class BasketHomeComponent implements OnInit, OnDestroy { this.http.get('../../rest/home').pipe( tap((data: any) => { this.homeData = data; - }), - finalize(() => { this.loading = false; }) ).subscribe(); diff --git a/src/frontend/app/folder/folder-pinned/folder-pinned.component.ts b/src/frontend/app/folder/folder-pinned/folder-pinned.component.ts index 9fc9a6a06b9..5355cd6c9e4 100644 --- a/src/frontend/app/folder/folder-pinned/folder-pinned.component.ts +++ b/src/frontend/app/folder/folder-pinned/folder-pinned.component.ts @@ -7,25 +7,25 @@ import { FoldersService } from '../folders.service'; @Component({ selector: 'folder-pinned', - templateUrl: "folder-pinned.component.html", + templateUrl: 'folder-pinned.component.html', styleUrls: ['folder-pinned.component.scss'], }) export class FolderPinnedComponent implements OnInit { lang: any = LANG; - + subscription: Subscription; @Input('noInit') noInit: boolean = false; - + constructor( public http: HttpClient, public foldersService: FoldersService ) { - // Event after process action + // Event after process action this.subscription = this.foldersService.catchEvent().subscribe((result: any) => { //console.log(result); - }); + }); } ngOnInit(): void { diff --git a/src/frontend/app/notification.service.ts b/src/frontend/app/notification.service.ts index d0cf400b4cb..ca1b1cd2e79 100755 --- a/src/frontend/app/notification.service.ts +++ b/src/frontend/app/notification.service.ts @@ -44,11 +44,11 @@ export class NotificationService { handleErrors(err: any) { console.log(err); - if (err.status === 401 && this.router.url !== '/home') { + /*if (err.status === 401 && this.router.url !== '/home') { this.router.navigate(['/home']); window.location.reload(true); this.error(this.lang.mustReconnect); - } else if (err.status === 0 && err.statusText === 'Unknown Error') { + } else*/ if (err.status === 0 && err.statusText === 'Unknown Error') { this.error(this.lang.connectionFailed); } else { if (err.error !== undefined) { diff --git a/src/frontend/app/separator/print-separator/print-separator.component.ts b/src/frontend/app/separator/print-separator/print-separator.component.ts index 2c4bd40acb1..b7bc4df7fbd 100644 --- a/src/frontend/app/separator/print-separator/print-separator.component.ts +++ b/src/frontend/app/separator/print-separator/print-separator.component.ts @@ -65,10 +65,10 @@ export class PrintSeparatorComponent implements OnInit { setTimeout(() => { $('#jstree') .on('select_node.jstree', (e: any, data: any) => { - this.separator.entities = $('#jstree').jstree(true).get_checked([true]); // to trigger disable button if no entities + this.separator.entities = $('#jstree').jstree('get_checked', null, true); // to trigger disable button if no entities }) .on('deselect_node.jstree', (e: any, data: any) => { - this.separator.entities = $('#jstree').jstree(true).get_checked([true]); // to trigger disable button if no entities + this.separator.entities = $('#jstree').jstree('get_checked', null, true); // to trigger disable button if no entities }) .jstree({ 'checkbox': { @@ -100,7 +100,7 @@ export class PrintSeparatorComponent implements OnInit { generateSeparators() { this.loading = true; - this.separator.entities = $('#jstree').jstree(true).get_checked([true]); + this.separator.entities = $('#jstree').jstree('get_checked', null, true); this.http.post('../../rest/entitySeparators', this.separator) .subscribe((data: any) => { this.docData = data; diff --git a/src/frontend/service/app.guard.ts b/src/frontend/service/app.guard.ts index 02713202ccc..f4177697d01 100644 --- a/src/frontend/service/app.guard.ts +++ b/src/frontend/service/app.guard.ts @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core'; import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, CanDeactivate } from '@angular/router'; import { HttpClient } from '@angular/common/http'; import { Observable, of } from 'rxjs'; -import { map, tap, catchError } from 'rxjs/operators'; +import { map, tap, catchError, exhaustMap } from 'rxjs/operators'; import { HeaderService } from './header.service'; import { ProcessComponent } from '../app/process/process.component'; import { PrivilegeService } from './privileges.service'; @@ -74,13 +74,31 @@ export class AppGuard implements CanActivate { tokenInfo = this.authService.getToken(); if (tokenInfo !== null) { - this.authService.user = JSON.parse(atob(tokenInfo.split('.')[1])).user; + this.http.get('../../rest/currentUser/profile') + .pipe( + map((dataUser: any) => { + this.headerService.user = { + id: dataUser.id, + userId: dataUser.user_id, + firstname: dataUser.firstname, + lastname: dataUser.lastname, + entities: dataUser.entities, + groups: dataUser.groups, + preferences: dataUser.preferences, + privileges: dataUser.privileges[0] === 'ALL_PRIVILEGES' ? this.privilegeService.getAllPrivileges() : dataUser.privileges + }; + + this.headerService.nbResourcesFollowed = dataUser.nbFollowedResources; + this.privilegeService.resfreshUserShortcuts(); + return true; + }) + ).subscribe(); return true; } else { this.authService.logout(); return false; } - }) + }), ); } diff --git a/src/frontend/service/auth-interceptor.service.ts b/src/frontend/service/auth-interceptor.service.ts index a5982031f67..009b23f5e51 100644 --- a/src/frontend/service/auth-interceptor.service.ts +++ b/src/frontend/service/auth-interceptor.service.ts @@ -1,7 +1,6 @@ import { Injectable } from '@angular/core'; import { HttpHandler, HttpInterceptor, HttpRequest, HttpClient } from '@angular/common/http'; import { LANG } from '../app/translate.component'; -import { Router } from '@angular/router'; import { catchError, switchMap } from 'rxjs/operators'; import { NotificationService } from '../app/notification.service'; import { AuthService } from './auth.service'; @@ -11,11 +10,10 @@ import { of } from 'rxjs/internal/observable/of'; @Injectable() export class AuthInterceptor implements HttpInterceptor { lang: any = LANG; - excludeUrls: string[] = ['../rest/authenticate', '../rest/authenticate/token', '../rest/authenticationInformations', '../rest/password', '../rest/passwordRules']; + excludeUrls: string[] = ['../../rest/authenticate', '../../rest/authenticate/token', '../../rest/authenticationInformations', '../../rest/password', '../../rest/passwordRules']; constructor( public http: HttpClient, - private router: Router, public notificationService: NotificationService, public authService: AuthService ) { } @@ -55,7 +53,7 @@ export class AuthInterceptor implements HttpInterceptor { // Disconnect user if bad token process if (error.status === 401) { console.log('Auth error !'); - return this.http.get('../rest/authenticate/token', { + return this.http.get('../../rest/authenticate/token', { params: { refreshToken: this.authService.getRefreshToken() } -- GitLab