Browse Source

HUE-9058 [frontend] Update the left assist after a doc share settings have been changed

Johan Ahlen 6 years ago
parent
commit
1130d904d2

+ 15 - 1
desktop/core/src/desktop/js/doc/hueDocument.js

@@ -44,6 +44,17 @@ class HueDocument {
     this.items = [];
   }
 
+  isShared() {
+    const perms = this.definition() && this.definition().perms;
+    return (
+      perms &&
+      (perms.read.users.length > 0 ||
+        perms.read.groups.length > 0 ||
+        perms.write.users.length > 0 ||
+        perms.write.groups.length > 0)
+    );
+  }
+
   onShareAutocompleteUserEnter() {
     const self = this;
     const searchAutoCompInput = $('#shareDocUserInput').val();
@@ -145,7 +156,7 @@ class HueDocument {
     });
   }
 
-  load() {
+  load(callback) {
     const self = this;
     if (self.loading()) {
       return;
@@ -183,6 +194,9 @@ class HueDocument {
         fetchDocumentsSuccessCallback(data);
         self.loading(false);
         self.loaded(true);
+        if (callback) {
+          callback();
+        }
       })
       .fail(() => {
         self.hasErrors(true);

+ 2 - 2
desktop/core/src/desktop/js/doc/hueFileEntry.js

@@ -408,9 +408,9 @@ class HueFileEntry {
     copyNext();
   }
 
-  loadDocument() {
+  loadDocument(callback) {
     this.document(new HueDocument({ fileEntry: this }));
-    this.document().load();
+    this.document().load(callback);
   }
 
   /**

+ 13 - 1
desktop/core/src/desktop/js/ko/components/ko.shareDocModal.js

@@ -20,6 +20,7 @@ import ko from 'knockout';
 import componentUtils from './componentUtils';
 import huePubSub from 'utils/huePubSub';
 import I18n from 'utils/i18n';
+import HueFileEntry from 'doc/hueFileEntry';
 
 // prettier-ignore
 const TEMPLATE = `
@@ -142,8 +143,14 @@ componentUtils.registerComponent('share-doc-modal', undefined, TEMPLATE).then(()
       $shareDocMocal.remove();
     }
 
+    let isSharedBefore;
+
     if (!hueFileEntry.document()) {
-      hueFileEntry.loadDocument();
+      hueFileEntry.loadDocument(() => {
+        isSharedBefore = hueFileEntry.document().isShared();
+      });
+    } else {
+      isSharedBefore = hueFileEntry.document().isShared();
     }
 
     $shareDocMocal = $(
@@ -153,5 +160,10 @@ componentUtils.registerComponent('share-doc-modal', undefined, TEMPLATE).then(()
 
     ko.applyBindings(hueFileEntry, $shareDocMocal[0]);
     $shareDocMocal.modal('show');
+    $shareDocMocal.on('hide', () => {
+      if (isSharedBefore !== hueFileEntry.document().isShared()) {
+        huePubSub.publish('assist.document.refresh');
+      }
+    });
   });
 });