Преглед изворни кода

HUE-9397 [ui] Only show share action when sharing is enabled or for admins

Johan Ahlen пре 5 година
родитељ
комит
beaa889d7f

+ 11 - 0
apps/oozie/src/oozie/static/oozie/js/bundle-editor.ko.js

@@ -56,6 +56,17 @@ var Bundle = function (vm, bundle) {
 var BundleEditorViewModel = function (bundle_json, coordinators_json, can_edit_json) {
   var self = this;
 
+  self.sharingEnabled = ko.observable(false);
+
+  var updateFromConfig = function (hueConfig) {
+    self.sharingEnabled(
+      hueConfig && (hueConfig.hue_config.is_admin || hueConfig.hue_config.enable_sharing)
+    );
+  };
+
+  updateFromConfig(window.getLastKnownConfig());
+  huePubSub.subscribe('cluster.config.set.config', updateFromConfig);
+
   self.canEdit = ko.mapping.fromJS(can_edit_json);
   self.isEditing = ko.observable(bundle_json.id == null);
   self.isEditing.subscribe(function (newVal) {

+ 12 - 0
apps/oozie/src/oozie/static/oozie/js/coordinator-editor.ko.js

@@ -186,6 +186,18 @@ var CoordinatorEditorViewModel = (function () {
     if (! coordinator_json['properties']['timezone']) {
       coordinator_json['properties']['timezone'] = tzdetect.matches()[0];
     }
+
+    self.sharingEnabled = ko.observable(false);
+
+    var updateFromConfig = function (hueConfig) {
+      self.sharingEnabled(
+        hueConfig && (hueConfig.hue_config.is_admin || hueConfig.hue_config.enable_sharing)
+      );
+    };
+
+    updateFromConfig(window.getLastKnownConfig());
+    huePubSub.subscribe('cluster.config.set.config', updateFromConfig);
+
     self.canEdit = ko.mapping.fromJS(can_edit_json);
     self.isEditing = ko.observable(coordinator_json.id == null);
     self.isEditing.subscribe(function (newVal) {

+ 11 - 0
apps/oozie/src/oozie/static/oozie/js/workflow-editor.ko.js

@@ -503,6 +503,17 @@ var WorkflowEditorViewModel = function (layout_json, workflow_json, credentials_
     huePubSub.publish('oozie.draggable.section.change', newVal);
   });
 
+  self.sharingEnabled = ko.observable(false);
+
+  var updateFromConfig = function (hueConfig) {
+    self.sharingEnabled(
+      hueConfig && (hueConfig.hue_config.is_admin || hueConfig.hue_config.enable_sharing)
+    );
+  };
+
+  updateFromConfig(window.getLastKnownConfig());
+  huePubSub.subscribe('cluster.config.set.config', updateFromConfig);
+
   self.canEdit = ko.mapping.fromJS(can_edit_json);
   self.isEditing = ko.observable(workflow_json.id == null);
   self.isEditing.subscribe(function (newVal) {

+ 2 - 0
apps/oozie/src/oozie/templates/editor2/bundle_editor.mako

@@ -71,11 +71,13 @@ ${ commonheader(_("Bundle Editor"), "Oozie", user, request) | n,unicode }
             <i class="fa fa-fw fa-cog"></i> ${ _('Settings') }
           </a>
         </li>
+        <!-- ko if: sharingEnabled -->
         <li data-bind="visible: bundle.id() != null && canEdit()">
           <a class="pointer share-link" rel="tooltip" data-placement="bottom" data-bind="click: openShareModal, css: {'isShared': isShared()}">
             <i class="fa fa-fw fa-users"></i> ${ _("Share") }
           </a>
         </li>
+        <!-- /ko -->
       </ul>
     </div>
   </div>

+ 2 - 0
apps/oozie/src/oozie/templates/editor2/coordinator_editor.mako

@@ -73,11 +73,13 @@ ${ commonheader(_("Coordinator Editor"), "Oozie", user, request) | n,unicode }
             <i class="fa fa-fw fa-cog"></i> ${ _('Settings') }
           </a>
         </li>
+        <!-- ko if: sharingEnabled -->
         <li data-bind="visible: coordinator.id() != null && canEdit()">
           <a class="pointer share-link" rel="tooltip" data-placement="bottom" data-bind="click: openShareModal, css: {'isShared': isShared()}">
             <i class="fa fa-fw fa-users"></i> ${ _("Share") }
           </a>
         </li>
+        <!-- /ko -->
       </ul>
     </div>
 

+ 2 - 0
apps/oozie/src/oozie/templates/editor2/workflow_editor.mako

@@ -88,11 +88,13 @@ ${ commonheader(_("Workflow Editor"), "Oozie", user, request, "40px") | n,unicod
             <i class="fa fa-fw fa-folder-open"></i> ${ _('Workspace') }
           </a>
         </li>
+        <!-- ko if: sharingEnabled -->
         <li data-bind="visible: workflow.id() != null && canEdit()">
           <a class="pointer share-link" rel="tooltip" data-placement="bottom" data-bind="click: openShareModal, css: {'isShared': isShared()}">
             <i class="fa fa-fw fa-users"></i> ${ _("Share") }
           </a>
         </li>
+        <!-- /ko -->
       </ul>
     </div>
 

+ 12 - 1
desktop/core/src/desktop/js/apps/notebook/editorViewModel.js

@@ -29,7 +29,7 @@ import {
   ACTIVE_SNIPPET_CONNECTOR_CHANGED_EVENT,
   GET_ACTIVE_SNIPPET_CONNECTOR_EVENT
 } from 'apps/notebook2/events';
-import { findEditorConnector } from 'utils/hueConfig';
+import { CONFIG_REFRESHED_EVENT, findEditorConnector, getLastKnownConfig } from 'utils/hueConfig';
 
 class EditorViewModel {
   constructor(editor_id, notebooks, options, CoordinatorEditorViewModel, RunningCoordinatorModel) {
@@ -58,6 +58,17 @@ class EditorViewModel {
 
     updateConnector(self.editorType());
 
+    self.sharingEnabled = ko.observable(false);
+
+    const updateFromConfig = hueConfig => {
+      self.sharingEnabled(
+        hueConfig && (hueConfig.hue_config.is_admin || hueConfig.hue_config.enable_sharing)
+      );
+    };
+
+    updateFromConfig(getLastKnownConfig());
+    huePubSub.subscribe(CONFIG_REFRESHED_EVENT, updateFromConfig);
+
     self.editorType.subscribe(newVal => {
       if (!this.activeConnector() || this.activeConnector().id !== newVal) {
         updateConnector(newVal);

+ 6 - 0
desktop/core/src/desktop/js/apps/notebook2/editorViewModel.js

@@ -59,6 +59,12 @@ class EditorViewModel {
     this.editorMode = ko.observable(options.mode === 'editor');
     this.config = ko.observable();
 
+    this.sharingEnabled = ko.pureComputed(
+      () =>
+        this.config() &&
+        (this.config().hue_config.is_admin || this.config().hue_config.sharing_enabled)
+    );
+
     huePubSub.publish(GET_KNOWN_CONFIG_EVENT, this.config);
     huePubSub.subscribe(CONFIG_REFRESHED_EVENT, this.config);
 

+ 2 - 1
desktop/core/src/desktop/js/hue.js

@@ -71,7 +71,7 @@ import SqlAutocompleter from 'sql/sqlAutocompleter';
 import sqlStatementsParser from 'parse/sqlStatementsParser'; // In search.ko and notebook.ko
 import HueFileEntry from 'doc/hueFileEntry';
 import HueDocument from 'doc/hueDocument';
-import { refreshConfig } from 'utils/hueConfig';
+import { getLastKnownConfig, refreshConfig } from 'utils/hueConfig';
 import { simpleGet } from 'api/apiUtils'; // In analytics.mako, metrics.mako, threads.mako
 
 // import all the other Vue SFCs here
@@ -110,6 +110,7 @@ if (window.ENABLE_NOTEBOOK_2) {
   window.EditorViewModel = EditorViewModel;
 }
 window.filesize = filesize;
+window.getLastKnownConfig = getLastKnownConfig;
 window.HdfsAutocompleter = HdfsAutocompleter;
 window.hueAnalytics = hueAnalytics;
 window.HueColors = HueColors;

+ 1 - 0
desktop/core/src/desktop/js/ko/bindings/ko.appAwareTemplateContextMenu.js

@@ -21,6 +21,7 @@ import huePubSub from 'utils/huePubSub';
 ko.bindingHandlers.appAwareTemplateContextMenu = {
   init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
     viewModel.$currentApp = ko.observable('');
+    viewModel.$containerContext = valueAccessor().containerContext || bindingContext;
     huePubSub.publish('get.current.app.name', viewModel.$currentApp);
     huePubSub.subscribe('set.current.app.name', viewModel.$currentApp);
     ko.bindingHandlers.templateContextMenu.init(

+ 14 - 1
desktop/core/src/desktop/js/ko/components/assist/ko.assistDocumentsPanel.js

@@ -24,6 +24,7 @@ import huePubSub from 'utils/huePubSub';
 import I18n from 'utils/i18n';
 import { DOCUMENT_TYPES } from 'doc/docSupport';
 import { ASSIST_DOC_HIGHLIGHT_EVENT, ASSIST_SHOW_DOC_EVENT } from './events';
+import { CONFIG_REFRESHED_EVENT, getLastKnownConfig } from 'utils/hueConfig';
 
 export const REFRESH_DOC_ASSIST_EVENT = 'assist.document.refresh';
 
@@ -46,9 +47,11 @@ const TEMPLATE = `
       'Delete document'
     )}</a></li>
     <!-- /ko -->
+    <!-- ko if: $containerContext.sharingEnabled -->
     <li><a href="javascript: void(0);" data-bind="publish: { 'doc.show.share.modal': $data }"><i class="fa fa-fw fa-users"></i> ${I18n(
       'Share'
     )}</a></li>
+    <!-- /ko -->
   </script>
 
   <script type="text/html" id="assist-document-header-actions">
@@ -198,7 +201,7 @@ const TEMPLATE = `
       </ul>
       <!-- /ko -->
       <ul class="assist-tables" data-bind="foreachVisible: { data: filteredEntries, minHeight: 27, container: '.assist-file-scrollable' }">
-        <li class="assist-entry assist-file-entry" data-bind="appAwareTemplateContextMenu: { template: 'document-context-items', scrollContainer: '.assist-file-scrollable', beforeOpen: beforeContextOpen }, assistFileDroppable, assistFileDraggable, visibleOnHover: { 'selector': '.assist-file-actions' }">
+        <li class="assist-entry assist-file-entry" data-bind="appAwareTemplateContextMenu: { template: 'document-context-items', containerContext: $parents[2], scrollContainer: '.assist-file-scrollable', beforeOpen: beforeContextOpen }, assistFileDroppable, assistFileDraggable, visibleOnHover: { 'selector': '.assist-file-actions' }">
           <div class="assist-file-actions table-actions">
             <a class="inactive-action" href="javascript:void(0)" data-bind="popoverOnHover: showContextPopover, css: { 'blue': statsVisible }"><i class="fa fa-fw fa-info" title="${I18n(
               'Show details'
@@ -237,6 +240,16 @@ class AssistDocumentsPanel {
     self.activeEntry = ko.observable();
     self.activeSort = ko.observable('defaultAsc');
     self.typeFilter = ko.observable(DOCUMENT_TYPES[0]); // all is first
+    self.sharingEnabled = ko.observable(false);
+
+    const updateFromConfig = hueConfig => {
+      self.sharingEnabled(
+        hueConfig && (hueConfig.hue_config.is_admin || hueConfig.hue_config.enable_sharing)
+      );
+    };
+
+    updateFromConfig(getLastKnownConfig());
+    huePubSub.subscribe(CONFIG_REFRESHED_EVENT, updateFromConfig);
 
     self.highlightTypeFilter = ko.observable(false);
 

+ 11 - 0
desktop/core/src/desktop/static/desktop/js/home.vm.js

@@ -24,6 +24,17 @@ function HomeViewModel(json_tags, json_docs) {
   self.page = ko.observable(1);
   self.documentsPerPage = ko.observable(50);
 
+  self.sharingEnabled = ko.observable(false);
+
+  var updateFromConfig = function (hueConfig) {
+    self.sharingEnabled(
+      hueConfig && (hueConfig.hue_config.is_admin || hueConfig.hue_config.enable_sharing)
+    );
+  };
+
+  updateFromConfig(window.getLastKnownConfig());
+  huePubSub.subscribe('cluster.config.set.config', updateFromConfig);
+
   self.selectedTag = ko.observable({});
   self.selectedTagForDelete = ko.observable({
     name: ''

+ 11 - 0
desktop/core/src/desktop/static/desktop/js/home2.vm.js

@@ -33,6 +33,17 @@ var HomeViewModel = (function () {
     // Uncomment to enable the assist panel
     // self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
 
+    self.sharingEnabled = ko.observable(false);
+
+    var updateFromConfig = function (hueConfig) {
+      self.sharingEnabled(
+        hueConfig && (hueConfig.hue_config.is_admin || hueConfig.hue_config.enable_sharing)
+      );
+    };
+
+    updateFromConfig(window.getLastKnownConfig());
+    huePubSub.subscribe('cluster.config.set.config', updateFromConfig);
+
     self.serverTypeFilter = ko.observable();
 
     var initialType = window.location.getParameter('type') !== '' ? window.location.getParameter('type') : 'all';

+ 4 - 0
desktop/core/src/desktop/templates/document_browser.mako

@@ -159,8 +159,10 @@ from desktop.views import _ko
                 <!-- /ko -->
 
                 <!-- ko if: app === 'documents' -->
+                <!-- ko if: $root.sharingEnabled() -->
                 <a class="btn" title="${_('Share')}" href="javascript:void(0);" data-bind="tooltip: { placement: 'bottom', delay: 750 }, click: function() { showSharingModal() }, css: { 'disabled': selectedEntries().length !== 1 || (selectedEntries().length === 1 && selectedEntries()[0].isTrashed) }"><i class="fa fa-fw fa-users"></i></a>
                 <!-- /ko -->
+                <!-- /ko -->
 
                 <!-- ko if: app === 'documents' -->
                 <div class="margin-left-20 margin-right-20 pull-right doc-browser-type-filter" data-bind="contextMenu: { menuSelector: '.hue-context-menu' }">
@@ -294,8 +296,10 @@ from desktop.views import _ko
                 <li data-bind="css: { 'disabled' : $parent.sharedWithMeSelected()  && ! $parent.superuser }"><a href="javascript:void(0);" data-bind="click: function () { huePubSub.publish('doc.show.delete.modal', $parent); }, css: { 'disabled' : $parent.sharedWithMeSelected() && ! $parent.superuser }">
                   <i class="fa fa-fw fa-times"></i> ${ _('Move to trash') } <span data-bind="visible: $parent.selectedEntries().length > 1, text: '(' + $parent.selectedEntries().length + ')'"></span></a>
                 </li>
+                <!-- ko if: $root.sharingEnabled() -->
                 <li data-bind="css: { 'disabled': $parent.selectedEntries().length !== 1 }"><a href="javascript:void(0);" data-bind="click: function() { $parent.showSharingModal(); }, css: { 'disabled': $parent.selectedEntries().length !== 1 }"><i class="fa fa-fw fa-users"></i> ${ _('Share') }</a> </li>
                 <!-- /ko -->
+                <!-- /ko -->
               </ul>
               <div class="doc-browser-primary-col">
                 <!-- ko template: { name: 'document-icon-template', data: { document: $data, showShareAddon: true } } --><!-- /ko -->

+ 11 - 0
desktop/libs/dashboard/src/dashboard/static/dashboard/js/search.ko.js

@@ -2038,6 +2038,17 @@ var SearchViewModel = function (collection_json, query_json, initial_json, has_g
 
   var self = this;
 
+  self.sharingEnabled = ko.observable(false);
+
+  var updateFromConfig = function (hueConfig) {
+    self.sharingEnabled(
+      hueConfig && (hueConfig.hue_config.is_admin || hueConfig.hue_config.enable_sharing)
+    );
+  };
+
+  updateFromConfig(window.getLastKnownConfig());
+  huePubSub.subscribe('cluster.config.set.config', updateFromConfig);
+
   self.collectionJson = collection_json;
   self.queryJson = query_json;
   self.initialJson = initial_json;

+ 2 - 0
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -202,11 +202,13 @@ from dashboard.conf import USE_GRIDSTER, USE_NEW_ADD_METHOD, HAS_REPORT_ENABLED,
             </a>
           </li>
           <li data-bind="visible: columns().length != 0" class="divider"></li>
+          <!-- ko if: $root.sharingEnabled -->
           <li data-bind="visible: isSaved()">
             <a class="share-link" data-bind="click: prepareShareModal, css: {'isShared': isShared()}">
               <i class="fa fa-fw fa-users"></i> ${ _('Share') }
             </a>
           </li>
+          <!-- /ko -->
           %if not is_embeddable:
             <li>
               <a class="pointer" data-bind="click: function(){ hueUtils.goFullScreen(); $root.isEditing(false); $root.isPlayerMode(true); }">

+ 2 - 0
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -282,6 +282,7 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
         </li>
         <li class="divider"></li>
         <!-- ko if: $root.canSave -->
+        <!-- ko if: sharingEnabled -->
         <li>
           <a class="share-link pointer" data-bind="click: prepareShareModal,
               css: {'isShared': isShared()}">
@@ -289,6 +290,7 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
           </a>
         </li>
         <!-- /ko -->
+        <!-- /ko -->
         <li>
           <a class="pointer" data-bind="publish: {'context.panel.visible': true}">
             <i class="fa fa-fw fa-cogs"></i> ${ _('Session') }

+ 2 - 0
desktop/libs/notebook/src/notebook/templates/editor_components2.mako

@@ -282,6 +282,7 @@
           </li>
           <li class="divider"></li>
           <!-- ko if: $root.canSave -->
+          <!-- ko if: sharingEnabled -->
           <li>
             <a href="javascript:void(0)" class="share-link" data-bind="click: prepareShareModal,
               css: {'isShared': isShared()}">
@@ -289,6 +290,7 @@
             </a>
           </li>
           <!-- /ko -->
+          <!-- /ko -->
           <li>
             <a href="javascript:void(0)" data-bind="click: showSessionPanel">
               <i class="fa fa-fw fa-cogs"></i> ${ _('Sessions') }