Browse Source

AMBARI-4565. Jobs: Admin config to turn Apps on/off for non-admin users. (alexantonenko)

Alex Antonenko 11 years ago
parent
commit
9d9e70486f

+ 1 - 0
ambari-web/app/controllers.js

@@ -47,6 +47,7 @@ require('controllers/main/admin/cluster');
 require('controllers/main/admin/stack_upgrade_controller');
 require('controllers/main/admin/user');
 require('controllers/main/admin/misc_controller');
+require('controllers/main/admin/access_controller');
 require('controllers/main/admin/user/edit');
 require('controllers/main/admin/user/create');
 require('controllers/main/admin/advanced');

+ 37 - 0
ambari-web/app/controllers/main/admin/access_controller.js

@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+App.MainAdminAccessController = Em.Controller.extend({
+  name:'mainAdminAccessController',
+
+  showJobs: true,
+
+  /* Handle Save button click event*/
+  save: function() {
+    App.db.setShowJobsForNonAdmin(this.get('showJobs'));
+    App.clusterStatus.setClusterStatus({
+      localdb: App.db.data
+    });
+  },
+
+  loadData: function() {
+    this.set('showJobs',  App.db.getShowJobsForNonAdmin());
+  }
+});

+ 3 - 0
ambari-web/app/messages.js

@@ -51,6 +51,7 @@ Em.I18n.translations = {
   'add': 'Add',
 
 
+  'common.access':'Access',
   'common.learnMore':'Learn more',
   'common.back':'Back',
   'common.prev':'Prev',
@@ -940,6 +941,8 @@ Em.I18n.translations = {
   'admin.users.createError.userNameExists': 'User with the same name is already exists',
   'admin.users.editError.requiredField': 'This is required',
 
+  'admin.access.showJobs':'Enable Jobs tab for non-admin users',
+
   'admin.confirmUninstall':'Confirm Uninstall',
   'admin.cluster.stackVersion':'Cluster Stack Version',
   'admin.cluster.upgradeAvailable':'Upgrade available',

+ 14 - 0
ambari-web/app/routes/main.js

@@ -114,6 +114,13 @@ module.exports = Em.Route.extend({
 
   jobs : Em.Route.extend({
     route : '/jobs',
+    enter: function () {
+      if(!App.db.getShowJobsForNonAdmin() && !App.get('isAdmin')){
+        Em.run.next(function () {
+          router.transitionTo('main.dashboard');
+        });
+      }
+    },
     index: Ember.Route.extend({
       route: '/',
       connectOutlets : function(router) {
@@ -525,6 +532,13 @@ module.exports = Em.Route.extend({
         router.get('mainAdminController').connectOutlet('mainAdminMisc');
       }
     }),
+    adminAccess: Em.Route.extend({
+      route: '/access',
+      connectOutlets: function (router) {
+        router.set('mainAdminController.category', "access");
+        router.get('mainAdminController').connectOutlet('mainAdminAccess');
+      }
+    }),
 
     adminAudit: Em.Route.extend({
       route: '/audit',

+ 11 - 0
ambari-web/app/styles/application.less

@@ -3384,6 +3384,17 @@ background: url(	data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByU
 }
 /*End Admin*/
 
+/* Start Admin Access*/
+#access{
+  .checkbox{
+    margin: 0;
+  }
+  .acces-values{
+    padding-bottom: 15px;
+  }
+}
+/* End Admin Access*/
+
 /*Start About*/
 .about {
   .logo {

+ 33 - 0
ambari-web/app/templates/main/admin/access.hbs

@@ -0,0 +1,33 @@
+{{!
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+}}
+<div id="access">
+  <div class="header">
+      <strong>{{t common.access}}</strong>
+  </div>
+  <div class="acces-values">
+      <label>
+        {{view Ember.Checkbox checkedBinding="showJobs" class="checkbox"}}
+        {{t admin.access.showJobs}}
+      </label>
+  </div>
+  <div class="control-group">
+      <div class="controls">
+          <button type="submit" class="btn btn-primary" {{action save target="controller"}}>{{t common.save}}</button>
+      </div>
+  </div>
+</div>

+ 19 - 0
ambari-web/app/utils/db.js

@@ -27,6 +27,9 @@ var InitialData =  {
       'displayLength': {},
       'startIndex': {},
       'sortingConditions': {}
+    },
+    'access': {
+      'showJobsForNonAdmin': ''
     }
   },
 
@@ -176,6 +179,13 @@ App.db.setDisplayLength = function(name, displayLength) {
   localStorage.setObject('ambari', App.db.data);
 };
 
+App.db.setShowJobsForNonAdmin = function(showJobsForNonAdmin) {
+  console.log('TRACE: Entering db:setShowJobsForNonAdmin function');
+  App.db.data = localStorage.getObject('ambari');
+  App.db.data.app.access.showJobsForNonAdmin = showJobsForNonAdmin;
+  localStorage.setObject('ambari', App.db.data);
+};
+
 App.db.setStartIndex = function(name, startIndex) {
   console.log('TRACE: Entering db:setStartIndex function');
   App.db.data = localStorage.getObject('ambari');
@@ -554,6 +564,15 @@ App.db.getDisplayLength = function(name) {
   return null;
 };
 
+App.db.getShowJobsForNonAdmin = function() {
+  console.log('TRACE: Entering db:getShowJobsForNonAdmin function');
+  App.db.data = localStorage.getObject('ambari');
+  if (App.db.data.app.access && typeof (App.db.data.app.access.showJobsForNonAdmin) ==  "boolean") {
+    return App.db.data.app.access.showJobsForNonAdmin;
+  }
+  return true;
+};
+
 App.db.getStartIndex = function(name) {
   console.log('TRACE: Entering db:getStartIndex function');
   App.db.data = localStorage.getObject('ambari');

+ 1 - 0
ambari-web/app/views.js

@@ -79,6 +79,7 @@ require('views/main/admin/cluster');
 require('views/main/admin/misc_view');
 require('views/main/admin/stack_upgrade');
 require('views/main/admin/advanced');
+require('views/main/admin/access_view');
 require('views/main/admin/advanced/password');
 require('views/main/admin/audit');
 require('views/main/admin/authentication');

+ 5 - 0
ambari-web/app/views/main/admin.js

@@ -51,6 +51,11 @@ App.MainAdminView = Em.View.extend({
       url: 'adminMisc',
       label: Em.I18n.t('common.misc')
     });
+    items.push({
+      name: 'access',
+      url: 'adminAccess',
+      label: Em.I18n.t('common.access')
+    });
     return items;
   }.property(''),
 

+ 26 - 0
ambari-web/app/views/main/admin/access_view.js

@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+App.MainAdminAccessView = Em.View.extend({
+  templateName: require('templates/main/admin/access'),
+  didInsertElement: function() {
+    this.get('controller').loadData();
+  }
+});

+ 1 - 1
ambari-web/app/views/main/menu.js

@@ -39,7 +39,7 @@ App.MainMenuView = Em.CollectionView.extend({
 
     if (!App.get('isHadoop2Stack')) {
       result.push({ label:Em.I18n.t('menu.item.jobs'), routing:'apps'});
-    } else if(App.supports.jobs) {
+    } else if(App.supports.jobs && (App.db.getShowJobsForNonAdmin() || App.get('isAdmin'))) {
       result.push({ label:Em.I18n.t('menu.item.jobs'), routing:'jobs'});
     }