Bläddra i källkod

HUE-8841 [metadata] Add read-only mode for descriptions

Johan Ahlen 6 år sedan
förälder
incheckning
ccc0b2318f

+ 6 - 9
apps/metastore/src/metastore/templates/metastore.mako

@@ -395,7 +395,7 @@ ${ components.menubar(is_embeddable) }
 </script>
 
 <script type="text/html" id="metastore-td-description">
-% if has_write_access:
+  <!-- ko ifnot: window.HAS_READ_ONLY_CATALOG -->
   <div data-bind="visibleOnHover: { selector: '.editable-inline-action' }">
     <div data-bind="editable: comment, editableOptions: {
         mode: 'inline',
@@ -414,14 +414,14 @@ ${ components.menubar(is_embeddable) }
       }">
       ${ _('Add a description...') }</div>
   </div>
-% else:
+  <!-- /ko -->
+  <!-- ko if: window.HAS_READ_ONLY_CATALOG -->
   <span style="white-space: pre;" data-bind="text: comment"></span>
-% endif
+  <!-- /ko -->
 </script>
 
 <script type="text/html" id="metastore-main-description">
-% if has_write_access:
-  <!-- ko if: $root.navigatorEnabled() -->
+  <!-- ko if: $root.navigatorEnabled() && !window.HAS_READ_ONLY_CATALOG -->
   <div class="hue-table-browser-desc-container" data-bind="visibleOnHover: { selector: '.editable-inline-action' }">
     <div class="hue-table-browser-desc">
       <div data-bind="editable: comment, editableOptions: {
@@ -443,12 +443,9 @@ ${ components.menubar(is_embeddable) }
     </div>
   </div>
   <!-- /ko -->
-  <!-- ko ifnot: $root.navigatorEnabled() -->
+  <!-- ko if: !$root.navigatorEnabled() || window.HAS_READ_ONLY_CATALOG -->
   <div data-bind="text: comment, attr: { title: comment }" class="table-description"></div>
   <!-- /ko -->
-% else:
-  <div data-bind="text: comment, attr: { title: comment }" class="table-description"></div>
-%endif
 </script>
 
 <script type="text/html" id="metastore-nav-tags">

+ 19 - 19
desktop/core/src/desktop/js/ko/components/contextPopover/ko.contextPopover.js

@@ -68,7 +68,7 @@ const SUPPORT_TEMPLATES = `
       </div>
     </div>
   </script>
-  
+
   <script type="text/html" id="context-popover-collection-stats-details">
     <div class="context-popover-flex-fill">
       <div style="padding: 8px">
@@ -111,7 +111,7 @@ const SUPPORT_TEMPLATES = `
       </div>
     </div>
   </script>
-  
+
   <script type="text/html" id="context-popover-collection-stats-facets">
     <table style="width: 100%">
       <tbody data-bind="foreach: Object.keys($parent.val[Object.keys($parent.val)[0]][$data])">
@@ -124,7 +124,7 @@ const SUPPORT_TEMPLATES = `
       </tbody>
     </table>
   </script>
-  
+
   <script type="text/html" id="context-popover-collection-terms-details">
     <div class="context-popover-flex-fill">
       <input type="text" data-bind="value: terms.prefix, clearable: terms.prefix, valueUpdate:'afterkeydown'" placeholder="${I18n(
@@ -152,13 +152,13 @@ const SUPPORT_TEMPLATES = `
       </div>
     </div>
   </script>
-  
+
   <script type="text/html" id="context-popover-asterisk-details">
     <div class="context-popover-flex-fill">
       <!-- ko component: { name: 'sql-columns-table', params: { columns: columns, scrollToColumns: false } } --><!-- /ko -->
     </div>
   </script>
-  
+
   <script type="text/html" id="context-popover-function-details">
     <!-- ko if: typeof details === 'undefined' -->
     <div class="context-popover-flex-fill">
@@ -176,7 +176,7 @@ const SUPPORT_TEMPLATES = `
     </div>
     <!-- /ko -->
   </script>
-  
+
   <script type="text/html" id="generic-document-context-template">
     <div style="width:100%; text-align: center; margin-top: 40px; font-size: 100px; color: #787878;" data-bind="template: { name: 'document-icon-template', data: { document: { isDirectory: type === 'directory', definition: function() { return $data } } } }"></div>
     <div style="width: 100%; margin-top: 20px; text-align:center">
@@ -193,7 +193,7 @@ const SUPPORT_TEMPLATES = `
       <!-- /ko -->
     </div>
   </script>
-  
+
   <script type="text/html" id="context-hue-app-details">
     <div class="context-popover-flex-fill" style="overflow: auto;" data-bind="with: data">
       <div style="padding: 8px">
@@ -204,7 +204,7 @@ const SUPPORT_TEMPLATES = `
       </div>
     </div>
   </script>
-  
+
   <script type="text/html" id="context-document-details">
     <div class="context-popover-flex-fill" style="overflow: auto;">
       <div class="context-popover-inner-content">
@@ -230,7 +230,7 @@ const SUPPORT_TEMPLATES = `
       </div>
     </div>
   </script>
-  
+
   <script type="text/html" id="context-partition-details">
     <div class="context-popover-flex-fill" style="overflow: auto;">
       <div class="context-popover-inner-content">
@@ -265,7 +265,7 @@ const SUPPORT_TEMPLATES = `
       </div>
     </div>
   </script>
-  
+
   <script type="text/html" id="context-popover-contents">
     <div class="context-popover-content">
       <!-- ko with: contents -->
@@ -318,10 +318,10 @@ const SUPPORT_TEMPLATES = `
       <!-- /ko -->
     </div>
   </script>
-  
+
   <script type="text/html" id="context-catalog-doc-title">
   </script>
-  
+
   <script type="text/html" id="context-lang-ref-title">
     <div class="hue-popover-title" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-right: 20px;">
       <i class="fa fa-book muted" style="margin-top: 3px"></i> <span class="blue" style="padding-left: 4px;" data-bind="text: title"></span>
@@ -335,7 +335,7 @@ const SUPPORT_TEMPLATES = `
       </div>
     </div>
   </script>
-  
+
   <script type="text/html" id="context-lang-ref-contents">
     <div class="context-popover-content">
       <div class="context-popover-flex-fill context-popover-docs-details" data-bind="html: body"></div>
@@ -350,7 +350,7 @@ const SUPPORT_TEMPLATES = `
       </div>
     </div>
   </script>
-  
+
   <script type="text/html" id="context-catalog-entry-title">
     <div class="hue-popover-title">
       <i class="hue-popover-title-icon fa muted" data-bind="css: catalogEntry() && catalogEntry().isView() ? 'fa-eye' : 'fa-table'"></i>
@@ -387,7 +387,7 @@ const SUPPORT_TEMPLATES = `
       </div>
     </div>
   </script>
-  
+
   <script type="text/html" id="context-catalog-entry-contents">
     <div class="context-popover-content">
       <div class="context-popover-flex-fill" data-bind="visible: loading"><!-- ko hueSpinner: { spin: loading, center: true, size: 'xlarge' } --><!-- /ko --></div>
@@ -402,12 +402,12 @@ const SUPPORT_TEMPLATES = `
           <!-- ko if: $parent.comment() && !isTemporary  -->
           <div class="context-popover-comment" data-bind="attr: { 'title': $parent.comment }, multiLineEllipsis: { expanded: $parent.commentExpanded, expandable: true, expandClass: 'context-popover-comment-expanded' }, text: $parent.comment"></div>
           <!-- /ko -->
-  
+
           <!-- ko ifnot: $parent.commentExpanded -->
               <!-- ko if: window.HAS_CATALOG && window.HAS_CATALOG_TAGS && !isTemporary && (getSourceType() === 'hive' || getSourceType() === 'impala') -->
               <div data-bind="component: { name: 'nav-tags', params: { catalogEntry: $data, overflowEllipsis: true } }"></div>
               <!-- /ko -->
-  
+
             <!-- ko if: isView() && $parent.viewSql() -->
             <a href="javascript:void(0);" style="text-align: right; margin-bottom: 5px;" data-bind="toggle: $parent.viewSqlVisible, text: $parent.viewSqlVisible() ? '${I18n(
               'Show columns'
@@ -423,7 +423,7 @@ const SUPPORT_TEMPLATES = `
           <!-- /ko -->
         </div>
       </div>
-  
+
       <div class="context-popover-flex-bottom-links">
         <div class="context-popover-link-row">
           <!-- ko if: catalogEntry -->
@@ -452,7 +452,7 @@ const SUPPORT_TEMPLATES = `
       <!-- /ko -->
     </div>
   </script>
-  
+
   <script type="text/html" id="context-storage-entry-title">
     <div class="hue-popover-title">
       <i class="hue-popover-title-icon fa muted" data-bind="css: storageEntry() && storageEntry().definition.type === 'dir' ? 'fa-folder-o' : 'fa-file-o'"></i>

+ 10 - 10
desktop/core/src/desktop/js/ko/components/ko.catalogEntriesList.js

@@ -24,7 +24,7 @@ import I18n from 'utils/i18n';
 const TEMPLATE = `
   <script type="text/html" id="entries-table-td-description">
     <td data-bind="attr: { 'title': comment }">
-    <!-- ko if: $parent.editableDescriptions -->
+    <!-- ko if: $parent.editableDescriptions && !window.HAS_READ_ONLY_CATALOG -->
       <div class="hue-catalog-entries-table-desc" data-bind="visibleOnHover: { selector: '.editable-inline-action' }">
         <div data-bind="editable: comment, editableOptions: {
           mode: 'inline',
@@ -44,12 +44,12 @@ const TEMPLATE = `
         }">${I18n('Add a description...')}</div>
       </div>
     <!-- /ko -->
-    <!-- ko ifnot: $parent.editableDescriptions -->
+    <!-- ko if: !$parent.editableDescriptions || window.HAS_READ_ONLY_CATALOG -->
       <div class="entries-table-description" data-bind="text: comment, multiLineEllipsis"></div>
     <!-- /ko -->
     </td>
   </script>
-  
+
   <script type="text/html" id="entries-table-tbody-no-entries">
     <tbody>
       <tr>
@@ -64,7 +64,7 @@ const TEMPLATE = `
       </tr>
     </tbody>
   </script>
-  
+
   <script type="text/html" id="entries-table-shared-headers">
     <!-- ko if: typeof selectedEntries !== 'undefined' -->
     <th width="1%" class="select-column"><div class="hue-checkbox fa" data-bind="hueCheckAll: { allValues: filteredEntries, selectedValues: selectedEntries }"></div></th>
@@ -73,7 +73,7 @@ const TEMPLATE = `
     <th width="1%">&nbsp;</th>
     <!-- /ko -->
   </script>
-  
+
   <script type="text/html" id="entries-table-shared-columns">
     <!-- ko if: typeof $parent.selectedEntries !== 'undefined' -->
     <td width="1%" class="select-column"><div class="hue-checkbox fa" data-bind="multiCheck: '#entryTable', value: $data, hueChecked: $parent.selectedEntries"></div></td>
@@ -82,7 +82,7 @@ const TEMPLATE = `
     <td width="1%"><a href="javascript: void(0);" data-bind="click: showContextPopover"><i class="fa fa-info"></i></a></td>
     <!-- /ko -->
   </script>
-  
+
   <!-- ko if: !loading() && (!catalogEntry().isField() || catalogEntry().isComplex())-->
   <div class="context-popover-inline-autocomplete">
     <div class="context-popover-sample-filter">
@@ -98,7 +98,7 @@ const TEMPLATE = `
     </div>
   </div>
   <!-- /ko -->
-  
+
   <div class="catalog-entries-list-container">
     <!-- ko hueSpinner: { spin: loading, center: true, size: 'xlarge' } --><!-- /ko -->
     <!-- ko if: !loading() && catalogEntry().isSource() -->
@@ -126,7 +126,7 @@ const TEMPLATE = `
       <!-- /ko -->
     </table>
     <!-- /ko -->
-  
+
     <!-- ko if: !loading() && catalogEntry().isDatabase() -->
     <table id="entryTable" class="table table-condensed table-nowrap">
       <thead>
@@ -154,7 +154,7 @@ const TEMPLATE = `
       <!-- /ko -->
     </table>
     <!-- /ko -->
-  
+
     <!-- ko if: !loading() && (catalogEntry().isTableOrView() || catalogEntry().isComplex()) -->
     <table class="table table-condensed table-nowrap">
       <thead>
@@ -205,7 +205,7 @@ const TEMPLATE = `
       <!-- /ko -->
     </table>
     <!-- /ko -->
-  
+
     <!-- ko if: !loading() && catalogEntry().isField() && !catalogEntry().isComplex() -->
     <!-- ko component: { name: 'field-samples', params: {
         catalogEntry: catalogEntry,

+ 6 - 4
desktop/core/src/desktop/js/ko/components/ko.navProperties.js

@@ -45,7 +45,7 @@ const TEMPLATE = `
   <!-- /ko -->
   <!-- ko ifnot: loading -->
   <!-- ko ifnot: editMode -->
- 
+
   <!-- ko ifnot: window.HAS_READ_ONLY_CATALOG -->
   <div class="hue-nav-properties" data-bind="click: startEdit, visibleOnHover: { selector: '.editable-inline-action' }">
     <!-- ko if: !properties().length -->
@@ -54,10 +54,12 @@ const TEMPLATE = `
     <!-- ko foreach: properties -->
     <div class="hue-nav-property"><div class="hue-nav-property-key" data-bind="text: key, attr: { 'title': key }"></div><div class="hue-nav-property-value" data-bind="text: value, attr: { 'title': value }"></div></div>
     <!-- /ko -->
-    <div class="editable-inline-action" title="${I18n('Edit')}"><a href="javascript: void(0);" data-bind="click: startEdit"><i class="fa fa-pencil"></i></a></div>
+    <div class="editable-inline-action" title="${I18n(
+      'Edit'
+    )}"><a href="javascript: void(0);" data-bind="click: startEdit"><i class="fa fa-pencil"></i></a></div>
   </div>
   <!-- /ko -->
-  
+
   <!-- ko if: window.HAS_READ_ONLY_CATALOG && properties().length -->
   <div class="hue-nav-properties">
     <!-- ko foreach: properties -->
@@ -65,7 +67,7 @@ const TEMPLATE = `
     <!-- /ko -->
   </div>
   <!-- /ko -->
-  
+
   <!-- /ko -->
   <!-- ko if: editMode -->
   <div class="hue-nav-properties hue-nav-properties-edit">

+ 2 - 1
desktop/core/src/desktop/js/ko/components/ko.navTags.js

@@ -63,7 +63,8 @@ class NavTags {
 
     self.catalogEntry = params.catalogEntry;
     self.overflowEllipsis = params.overflowEllipsis;
-    self.readOnly = !window.USER_HAS_METADATA_WRITE_PERM || !!params.readOnly;
+    self.readOnly =
+      !window.USER_HAS_METADATA_WRITE_PERM || !!params.readOnly || window.HAS_READ_ONLY_CATALOG;
 
     self.getSelectizeTags = function(query, callback) {
       callback(

+ 3 - 1
desktop/core/src/desktop/templates/global_js_constants.mako

@@ -26,6 +26,8 @@
   from indexer.conf import ENABLE_NEW_INDEXER
   from metadata.conf import has_catalog, has_catalog_tags, has_readonly_catalog, has_optimizer, has_workload_analytics, OPTIMIZER
   from notebook.conf import ENABLE_NOTEBOOK_2, ENABLE_QUERY_ANALYSIS, ENABLE_QUERY_SCHEDULING
+
+  from metastore.views import has_write_access
 %>
 
 <%namespace name="impalaDocIndex" file="/impala_doc_index.mako" />
@@ -64,7 +66,7 @@
 
   window.HAS_CATALOG = '${ has_catalog(request.user) }' === 'True';
   window.HAS_CATALOG_TAGS = '${ has_catalog_tags(request.user) }' === 'True';
-  window.HAS_READ_ONLY_CATALOG = '${ has_readonly_catalog(request.user) }' === 'True';
+  window.HAS_READ_ONLY_CATALOG = '${ has_readonly_catalog(request.user) }' === 'True' || '${ has_write_access(request.user) }' === 'False';
 
   window.HAS_OPTIMIZER = '${ has_optimizer() }' === 'True';