Эх сурвалжийг харах

HUE-9096 [doc] Wire the link sharing API to the permission modal

Romain 6 жил өмнө
parent
commit
d1c2147afa

+ 3 - 4
desktop/core/src/desktop/api2.py

@@ -655,7 +655,7 @@ def share_document_link(request):
   """
   Globally activate of de-activate access to a document for logged-in users.
 
-  Example of input: {'name': 'link_read', 'is_link_on': true}
+  Example of input: {"uuid": "xxxx", "data": "read" / "write" / "off"}
   """
   uuid = request.POST.get('uuid')
   perm = request.POST.get('data')
@@ -663,12 +663,11 @@ def share_document_link(request):
   if not uuid or not perm:
     raise PopupException(_('share_document_link requires uuid and permission data'))
   else:
-    perm = json.loads(perm)
     uuid = json.loads(uuid)
+    perm = json.loads(perm)
 
   doc = Document2.objects.get_by_uuid(user=request.user, uuid=uuid)
-
-  doc = doc.share(request.user, name=perm['name'], is_link_on=perm['is_link_on'])
+  doc = doc.share_link(request.user, perm=perm)
 
   return JsonResponse({
     'status': 0,

+ 1 - 1
desktop/core/src/desktop/js/apps/notebook2/components/ko.snippetEditorActions.js

@@ -45,7 +45,7 @@ const TEMPLATE = `
         <a href="javascript:void(0)" data-bind="click: createGist, css: { 'disabled': !createGistEnabled() }" title="${I18n(
           'Share the query selection via a link'
         )}">
-          <i class="fa fa-wf fa-link"></i> ${I18n('Share link')}
+          <i class="fa fa-wf fa-link"></i> ${I18n('Share as gist')}
         </a>
       </li>
       <!-- /ko -->

+ 30 - 0
desktop/core/src/desktop/js/doc/hueDocument.js

@@ -156,6 +156,36 @@ class HueDocument {
     });
   }
 
+  persistLinkSharingPerms(perm) {
+    // Perm is either: read, write, off
+    const self = this;
+
+    $.post(
+      '/desktop/api2/doc/share/link',
+      {
+        uuid: JSON.stringify(self.fileEntry.definition().uuid),
+        data: JSON.stringify(perm)
+      },
+      response => {
+        if (response != null) {
+          if (response.status !== 0) {
+            $(document).trigger(
+              'error',
+              'There was an error processing your action: ' + response.message
+            );
+          } else {
+            // self.load();
+          }
+        }
+      }
+    ).fail(response => {
+      $(document).trigger(
+        'error',
+        'There was an error processing your action: ' + response.responseText
+      );
+    });
+  }
+
   load(callback) {
     const self = this;
     if (self.loading()) {

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

@@ -35,18 +35,24 @@ const TEMPLATE = `
   <div class="modal-body" style="overflow: visible; height: 240px">
 
     <!-- ko if: window.HAS_LINK_SHARING -->
-    Has Link sharing on: <span data-bind="text: $parent.definition().perms.link_sharing_on"></span>
-    Has Link Read: <span data-bind="text: $parent.definition().perms.link_read"></span>
-    Has link Write: <span data-bind="text: $parent.definition().perms.link_write"></span>
+    <a href="javascript:void(0)" data-bind="visible: !$parent.definition().perms.link_sharing_on" title="${ I18n(
+      'Share the query via a link'
+    ) }">
+      <i class="fa fa-wf fa-link"></i> ${ I18n('Get link') }
+    </a>
 
-    <a href="javascript:void(0)"  title="${ I18n(
-      'Share the query selection via a link'
+    <!-- ko with: $parent.definition().perms.link_sharing_on -->
+    <a href="javascript:void(0)" title="${ I18n(
+      'Deactivate the link sharing'
     ) }">
-      <i class="fa fa-wf fa-link"></i> ${ I18n('Share link') }
+      <i class="fa fa-wf fa-link"></i> ${ I18n('Deactivate link') }
     </a>
 
     <div class="row-fluid">
       <div class="span12">
+        Anyone logged and with the link can:
+        <br/>
+        Read: <span data-bind="text: $parent.definition().perms.link_read"></span> | Write: <span data-bind="text: $parent.definition().perms.link_write"></span>
         <h4 class="muted" style="margin-top: 0">${ I18n('Shareable link') }</h4>
         <div class="input-group">
           <input class="input-xxlarge" onfocus="this.select()" name="gist-link" id="gist-link" type="text" placeholder="${ I18n('Link') }"/>
@@ -60,6 +66,7 @@ const TEMPLATE = `
       </div>
     </div>
     <!-- /ko -->
+    <!-- /ko -->
 
     <!-- ko with: definition -->
     <div class="row-fluid" data-bind="visible: !$parent.hasErrors()" style="max-height: 114px;" id="scrolldiv">

+ 10 - 0
desktop/core/src/desktop/models.py

@@ -1389,6 +1389,16 @@ class Document2(models.Model):
       raise PopupException(_("Failed to share document: %s") % e)
     return self
 
+  def share_link(self, user, perm='read'):
+    if perm == 'read':
+      doc = doc.share(user, name=Document2Permission.LINK_READ_PERM, is_link_on=True)
+    elif perm == 'write':
+      doc = doc.share(user, name=Document2Permission.LINK_WRITE_PERM, is_link_on=True)
+    else:
+      doc = doc.share(user, name=Document2Permission.LINK_READ_PERM, is_link_on=False)
+      doc = doc.share(user, name=Document2Permission.LINK_WRITE_PERM, is_link_on=False)
+    return doc
+
   def update_permission(self, user, name='read', users=None, groups=None, is_link_on=False):
     # Check if user has access to grant permissions
     if users or groups:

+ 2 - 0
desktop/core/src/desktop/templates/global_js_constants.mako

@@ -299,6 +299,8 @@
     'Foreign keys': '${_('Foreign keys')}',
     'Format the current SQL query': '${ _('Format the current SQL query') }',
     'Share the query selection via a link': '${ _('Share the query selection via a link') }',
+    'Share link': '${ _('Share link') }',
+    'Share as a gist': '${ _('Share as a gist') }',
     'Format': '${ _('Format') }',
     'France': '${ _('France') }',
     'Functions': '${ _('Functions') }',

+ 1 - 1
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1796,7 +1796,7 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
         % if conf.ENABLE_GIST.get():
         <li>
           <a href="javascript:void(0)" data-bind="click: createGist, css: {'disabled': ! isReady() }" title="${ _('Share the query selection via a link') }">
-            <i class="fa fa-fw fa-link"></i> ${_('Share link')}
+            <i class="fa fa-fw fa-link"></i> ${_('Share as a gist')}
           </a>
         </li>
         % endif