You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by dg...@apache.org on 2020/05/26 15:22:36 UTC

[incubator-dlab] branch develop updated: [DLAB-1817]: Fixed token issue (#765)

This is an automated email from the ASF dual-hosted git repository.

dgnatyshyn pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git


The following commit(s) were added to refs/heads/develop by this push:
     new 8a90f9e   [DLAB-1817]: Fixed token issue (#765)
8a90f9e is described below

commit 8a90f9e16a59e286fbe4197c97690c1bf0177949
Author: Dmytro Gnatyshyn <42...@users.noreply.github.com>
AuthorDate: Tue May 26 18:22:28 2020 +0300

     [DLAB-1817]: Fixed token issue (#765)
    
    [DLAB-1817]: Fixed token issue
---
 .../bucket-browser/bucket-browser.component.ts     | 54 ++++++++++++++++++----
 .../resources-grid/resources-grid.component.ts     |  2 +-
 2 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/services/self-service/src/main/resources/webapp/src/app/resources/bucket-browser/bucket-browser.component.ts b/services/self-service/src/main/resources/webapp/src/app/resources/bucket-browser/bucket-browser.component.ts
index 21c8125..80869cd 100644
--- a/services/self-service/src/main/resources/webapp/src/app/resources/bucket-browser/bucket-browser.component.ts
+++ b/services/self-service/src/main/resources/webapp/src/app/resources/bucket-browser/bucket-browser.component.ts
@@ -21,7 +21,7 @@ import { Component, OnInit, ViewChild, Inject } from '@angular/core';
 import { FormGroup, FormBuilder } from '@angular/forms';
 import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
 import { ToastrService } from 'ngx-toastr';
-import {ApplicationSecurityService, ManageUngitService} from '../../core/services';
+import {ApplicationSecurityService, ManageUngitService, StorageService} from '../../core/services';
 
 import {FolderTreeComponent} from './folder-tree/folder-tree.component';
 import {BucketBrowserService, TodoItemNode} from '../../core/services/bucket-browser.service';
@@ -56,7 +56,10 @@ export class BucketBrowserComponent implements OnInit {
   public selectedItems;
   public searchValue: string;
   public isQueueFull: boolean;
-  date = new Date(2020, 2, 2, 10, 57, 2);
+  // public refreshTokenLimit = 300000;
+  public refreshTokenLimit = 150000;
+  private isTokenRefreshing = false;
+
 
   @ViewChild(FolderTreeComponent, {static: true}) folderTreeComponent;
   public isSelectionOpened: any;
@@ -77,7 +80,8 @@ export class BucketBrowserComponent implements OnInit {
     private _fb: FormBuilder,
     private bucketBrowserService: BucketBrowserService,
     private bucketDataService: BucketDataService,
-    private auth: ApplicationSecurityService
+    private auth: ApplicationSecurityService,
+    private storage: StorageService,
   ) {
 
   }
@@ -90,6 +94,19 @@ export class BucketBrowserComponent implements OnInit {
     this.buckets = this.data.buckets;
   }
 
+  public getTokenValidTime() {
+    const token = JSON.parse(atob(this.storage.getToken().split('.')[1]));
+    return token.exp * 1000 - new Date().getTime();
+  }
+
+  private refreshToken() {
+    this.isTokenRefreshing = true;
+    this.auth.refreshToken().subscribe(v => {
+      this.isTokenRefreshing = true;
+    });
+    this.sendFile();
+  }
+
   public showItem(item) {
     const flatItem = this.folderTreeComponent.nestedNodeMap.get(item);
     this.folderTreeComponent.showItem(flatItem);
@@ -132,10 +149,28 @@ export class BucketBrowserComponent implements OnInit {
           items: {toBig: toBigFile, toMany: toMany}, type: 'uploading-error'
           } , width: '550px'})
           .afterClosed().subscribe((res) => {
-            res && this.uploadingQueue(files);
+         if (res) {
+           if (this.refreshTokenLimit > this.getTokenValidTime()) {
+             this.isTokenRefreshing = true;
+             this.auth.refreshToken().subscribe(v => {
+               this.uploadingQueue(files);
+               this.isTokenRefreshing = false;
+             });
+           } else {
+             this.uploadingQueue(files);
+           }
+         }
         });
       } else {
-        this.uploadingQueue(files);
+        if (this.refreshTokenLimit > this.getTokenValidTime()) {
+          this.isTokenRefreshing = true;
+          this.auth.refreshToken().subscribe(v => {
+            this.uploadingQueue(files);
+            this.isTokenRefreshing = false;
+          });
+        } else {
+          this.uploadingQueue(files);
+        }
       }
     }
     event.target.value = '';
@@ -145,7 +180,7 @@ export class BucketBrowserComponent implements OnInit {
     if (files.length) {
       let askForAll = true;
       let skipAll = false;
-      // this.auth.refreshToken().subscribe();
+
       const folderFiles = this.folderItems.filter(v => !v.children).map(v => v.item);
       for (const file of files) {
         const existFile = folderFiles.filter(v => v === file['name'])[0];
@@ -259,7 +294,10 @@ export class BucketBrowserComponent implements OnInit {
     const uploading = this.addedFiles.filter(v => v.status === 'uploading');
     this.isQueueFull = !!waitUploading.length;
     this.isFileUploading = !!this.addedFiles.filter(v => v.status === 'uploading').length;
-    if (waitUploading.length && uploading.length < 10) {
+    if (this.refreshTokenLimit > this.getTokenValidTime() && !this.isTokenRefreshing) {
+      this.refreshToken();
+    }
+    if (waitUploading.length && uploading.length < 10 && !this.isTokenRefreshing) {
       if (!file) {
         file = waitUploading[0];
       }
@@ -353,7 +391,7 @@ export class BucketBrowserComponent implements OnInit {
         res && this.bucketBrowserService.deleteFile({
           bucket: this.bucketName, endpoint: this.endpoint, 'objects': dataForServer
         }).subscribe(() => {
-            this.bucketDataService.refreshBucketdata(this.data.bucket, this.data.endpoint);
+            this.bucketDataService.refreshBucketdata(this.bucketName, this.data.endpoint);
             this.toastr.success('Objects successfully deleted!', 'Success!');
             this.clearSelection();
           }, error => {
diff --git a/services/self-service/src/main/resources/webapp/src/app/resources/resources-grid/resources-grid.component.ts b/services/self-service/src/main/resources/webapp/src/app/resources/resources-grid/resources-grid.component.ts
index c1c623e..19b1eb5 100644
--- a/services/self-service/src/main/resources/webapp/src/app/resources/resources-grid/resources-grid.component.ts
+++ b/services/self-service/src/main/resources/webapp/src/app/resources/resources-grid/resources-grid.component.ts
@@ -172,7 +172,7 @@ export class ResourcesGridComponent implements OnInit {
 
   public printDetailEnvironmentModal(data): void {
     this.dialog.open(DetailDialogComponent, { data:
-        {notebook: data, bucketStatus: this.healthStatus.bucketBrowser, buckets: this.bucketsList},
+        {notebook: data, bucketStatus: this.healthStatus.bucketBrowser, buckets: this.bucketsList, type: 'resource'},
       panelClass: 'modal-lg'
     })
       .afterClosed().subscribe(() => this.buildGrid());


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org