ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ababiic...@apache.org
Subject git commit: AMBARI-7771 Change the way UI requests privileges of logged user. (Ievgen Fialkovskyi via ababiichuk)
Date Wed, 15 Oct 2014 11:37:06 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-1.7.0 dc6b18412 -> 6a1d8de51


AMBARI-7771 Change the way UI requests privileges of logged user. (Ievgen Fialkovskyi via
ababiichuk)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/6a1d8de5
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/6a1d8de5
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/6a1d8de5

Branch: refs/heads/branch-1.7.0
Commit: 6a1d8de51f44c38365ed3eb966e4410f7b654c4d
Parents: dc6b184
Author: aBabiichuk <ababiichuk@cybervisiontech.com>
Authored: Wed Oct 15 14:09:22 2014 +0300
Committer: aBabiichuk <ababiichuk@cybervisiontech.com>
Committed: Wed Oct 15 14:09:22 2014 +0300

----------------------------------------------------------------------
 ambari-web/app/assets/test/tests.js    |  1 +
 ambari-web/app/mappers/users_mapper.js |  5 +--
 ambari-web/app/router.js               | 39 ++++------------------
 ambari-web/app/utils/ajax/ajax.js      |  2 +-
 ambari-web/test/router_test.js         | 50 +++++++++++++++++++++++++++++
 5 files changed, 61 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/6a1d8de5/ambari-web/app/assets/test/tests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js
index bcc835b..8ab531c 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -96,6 +96,7 @@ var files = ['test/init_model_test',
   'test/controllers/wizard/step10_test',
   'test/controllers/wizard/stack_upgrade/step3_controller_test',
   'test/login_test',
+  'test/router_test',
   'test/mappers/server_data_mapper_test',
   'test/mappers/hosts_mapper_test',
   'test/mappers/service_mapper_test',

http://git-wip-us.apache.org/repos/asf/ambari/blob/6a1d8de5/ambari-web/app/mappers/users_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/users_mapper.js b/ambari-web/app/mappers/users_mapper.js
index 00ac6c3..b90c20f 100644
--- a/ambari-web/app/mappers/users_mapper.js
+++ b/ambari-web/app/mappers/users_mapper.js
@@ -34,8 +34,9 @@ App.usersMapper = App.QuickDataMapper.create({
       var result= [];
       if(!App.User.find().someProperty("userName", item.Users.user_name)) {
         item.permissions = [];
-        if (!!Em.get(item.privileges, 'items.length')) {
-          item.permissions = item.privileges.items.mapProperty('PrivilegeInfo.permission_name');
+        var privileges = item.privileges;
+        if (!!Em.get(privileges, 'length')) {
+          item.permissions = privileges.mapProperty('PrivilegeInfo.permission_name');
         }
         item.Users.admin = self.isAdmin(item.permissions);
         item.Users.operator = self.isOperator(item.permissions);

http://git-wip-us.apache.org/repos/asf/ambari/blob/6a1d8de5/ambari-web/app/router.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/router.js b/ambari-web/app/router.js
index b347512..25a142a 100644
--- a/ambari-web/app/router.js
+++ b/ambari-web/app/router.js
@@ -168,30 +168,6 @@ App.Router = Em.Router.extend({
     return App.db.getUser();
   },
 
-  /**
-   * Get user privileges.
-   *
-   * @param {String} userName
-   * @returns {$.Deferred}
-   **/
-  getUserPrivileges: function(userName) {
-    return App.ajax.send({
-      name: 'router.user.privileges',
-      sender: this,
-      data: {
-        userName: userName
-      },
-      success: 'getUserPrivilegesSuccess',
-      error: 'getUserPrivilegesError'
-    });
-  },
-
-  getUserPrivilegesSuccess: function() {},
-
-  getUserPrivilegesError: function(req) {
-    console.log("Get user privileges error: " + req.statusCode);
-  },
-
   setUserLoggedIn: function(userName) {
     this.setAuthenticated(true);
     this.setLoginName(userName);
@@ -243,6 +219,9 @@ App.Router = Em.Router.extend({
 
   loginSuccessCallback: function(data, opt, params) {
     console.log('login success');
+    App.usersMapper.map({"items": [data]});
+    this.setUserLoggedIn(params.loginName);
+    App.router.get('mainViewsController').loadAmbariViews();
     App.ajax.send({
       name: 'router.login.clusters',
       sender: this,
@@ -276,14 +255,9 @@ App.Router = Em.Router.extend({
     //TODO: Replace hard coded value with query. Same in templates/application.hbs
     var loginController = this.get('loginController');
     var loginData = params.loginData;
+    var privileges = loginData.privileges;
     var router = this;
-
-    this.getUserPrivileges(params.loginName).done(function(privileges) {
-      loginData.privileges = privileges;
-      App.usersMapper.map({"items": [loginData]});
-      router.setUserLoggedIn(params.loginName);
-      App.router.get('mainViewsController').loadAmbariViews();
-      var permissionList = privileges.items.mapProperty('PrivilegeInfo.permission_name');
+    var permissionList = privileges.mapProperty('PrivilegeInfo.permission_name');
       var isAdmin = permissionList.contains('AMBARI.ADMIN');
       var transitionToApp = false;
       if (isAdmin) {
@@ -300,7 +274,7 @@ App.Router = Em.Router.extend({
           router.setClusterInstalled(clustersData);
           //TODO: Iterate over clusters
           var clusterName = clustersData.items[0].Clusters.cluster_name;
-          var clusterPermissions = privileges.items.filterProperty('PrivilegeInfo.cluster_name',
clusterName).mapProperty('PrivilegeInfo.permission_name');
+          var clusterPermissions = privileges.filterProperty('PrivilegeInfo.cluster_name',
clusterName).mapProperty('PrivilegeInfo.permission_name');
           if (clusterPermissions.contains('CLUSTER.OPERATE')) {
             App.set('isAdmin', true);
             App.set('isOperator', true);
@@ -324,7 +298,6 @@ App.Router = Em.Router.extend({
         router.transitionTo('main.views.index');
         loginController.postLogin(true,true);
       }
-    });
   },
 
   loginGetClustersErrorCallback: function (req) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/6a1d8de5/ambari-web/app/utils/ajax/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax/ajax.js b/ambari-web/app/utils/ajax/ajax.js
index 2b836e4..2df9b42 100644
--- a/ambari-web/app/utils/ajax/ajax.js
+++ b/ambari-web/app/utils/ajax/ajax.js
@@ -1394,7 +1394,7 @@ var urls = {
     }
   },
   'router.login': {
-    'real': '/users/{loginName}',
+    'real': '/users/{loginName}?fields=*,privileges/PrivilegeInfo/cluster_name,privileges/PrivilegeInfo/permission_name',
     'mock': '/data/users/user_{usr}.json',
     'format': function (data) {
       var statusCode = jQuery.extend({}, require('data/statusCodes'));

http://git-wip-us.apache.org/repos/asf/ambari/blob/6a1d8de5/ambari-web/test/router_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/router_test.js b/ambari-web/test/router_test.js
new file mode 100644
index 0000000..ec76aff
--- /dev/null
+++ b/ambari-web/test/router_test.js
@@ -0,0 +1,50 @@
+/**
+ * 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');
+
+require('router');
+
+describe('App.Router', function () {
+  var router = App.Router.create();
+
+  describe('#loginSuccessCallback()', function() {
+    it('should log in user and load views', function () {
+      var mainViewsControllerMock = Em.Object.create({
+        loadAmbariViews: sinon.stub()
+      });
+      var userName = 'test';
+      sinon.stub(App.usersMapper, 'map');
+      sinon.stub(router, 'setUserLoggedIn');
+      sinon.stub(App.router, 'get').withArgs('mainViewsController').returns(mainViewsControllerMock);
+      sinon.stub(App.ajax, 'send');
+
+      router.loginSuccessCallback({},{},{loginName: userName});
+
+      expect(mainViewsControllerMock.loadAmbariViews.calledOnce).to.be.true;
+      expect(router.setUserLoggedIn.calledOnce).to.be.true;
+      expect(router.setUserLoggedIn.calledWith(userName)).to.be.true;
+
+      App.usersMapper.map.restore();
+      router.setUserLoggedIn.restore();
+      App.router.get.restore();
+      App.ajax.send.restore();
+    })
+  });
+
+});


Mime
View raw message