You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by al...@apache.org on 2015/11/17 20:02:40 UTC

ambari git commit: AMBARI-13924. Admin View: Handle user_type from users endpoint.

Repository: ambari
Updated Branches:
  refs/heads/trunk e32482997 -> 27cbe86a6


AMBARI-13924. Admin View: Handle user_type from users endpoint.


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

Branch: refs/heads/trunk
Commit: 27cbe86a68b25f655737a158b8990627ffed5322
Parents: e324829
Author: Alex Antonenko <hi...@gmail.com>
Authored: Tue Nov 17 20:45:07 2015 +0200
Committer: Alex Antonenko <hi...@gmail.com>
Committed: Tue Nov 17 21:02:36 2015 +0200

----------------------------------------------------------------------
 .../main/resources/ui/admin-web/app/index.html  |  1 +
 .../scripts/controllers/users/UsersListCtrl.js  | 27 +++++++-------
 .../scripts/controllers/users/UsersShowCtrl.js  |  5 ++-
 .../ui/admin-web/app/scripts/services/User.js   | 21 +++++++++--
 .../app/scripts/services/UserConstants.js       | 38 ++++++++++++++++++++
 .../ui/admin-web/app/views/users/list.html      |  5 ++-
 .../ui/admin-web/app/views/users/show.html      |  5 ++-
 7 files changed, 76 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/27cbe86a/ambari-admin/src/main/resources/ui/admin-web/app/index.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/index.html b/ambari-admin/src/main/resources/ui/admin-web/app/index.html
index fe049ac..44b957f 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/index.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/index.html
@@ -144,6 +144,7 @@
     <script src="scripts/directives/PasswordVerify.js"></script>
     <script src="scripts/directives/disabledTooltip.js"></script>
     <script src="scripts/directives/editableList.js"></script>
+    <script src="scripts/services/UserConstants.js"></script>
     <script src="scripts/services/User.js"></script>
     <script src="scripts/services/Group.js"></script>
     <script src="scripts/services/View.js"></script>

http://git-wip-us.apache.org/repos/asf/ambari/blob/27cbe86a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersListCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersListCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersListCtrl.js
index ff09832..de53265 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersListCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersListCtrl.js
@@ -18,7 +18,7 @@
 'use strict';
 
 angular.module('ambariAdminConsole')
-.controller('UsersListCtrl',['$scope', 'User', '$modal', '$rootScope', function($scope, User, $modal, $rootScope) {
+  .controller('UsersListCtrl',['$scope', 'User', '$modal', '$rootScope', 'UserConstants', function($scope, User, $modal, $rootScope, UserConstants) {
   $scope.users = [];
   $scope.usersPerPage = 10;
   $scope.currentPage = 1;
@@ -35,18 +35,15 @@ angular.module('ambariAdminConsole')
 
   $scope.loadUsers = function(){
     User.list({
-      currentPage: $scope.currentPage, 
-      usersPerPage: $scope.usersPerPage, 
+      currentPage: $scope.currentPage,
+      usersPerPage: $scope.usersPerPage,
       searchString: $scope.currentNameFilter,
-      ldap_user: $scope.currentTypeFilter.value,
+      user_type: $scope.currentTypeFilter.value,
       active: $scope.currentActiveFilter.value,
       admin: $scope.adminFilter
     }).then(function(data) {
       $scope.totalUsers = data.data.itemTotal;
-      $scope.users = data.data.items.map(function (user) {
-        user.Users.encoded_name = encodeURIComponent(user.Users.user_name);
-        return user;
-      });
+      $scope.users = data.data.items.map(User.makeUser);
     });
   };
 
@@ -61,13 +58,15 @@ angular.module('ambariAdminConsole')
     {label:'Inactive', value:false}
   ];
   $scope.currentActiveFilter = $scope.actvieFilterOptions[0];
-  
 
-  $scope.typeFilterOptions = [
-    {label:'All', value:'*'},
-    {label:'Local', value:false},
-    {label:'LDAP', value:true}
-  ];
+  $scope.typeFilterOptions = [{ label: 'All', value: '*'}]
+    .concat(Object.keys(UserConstants.TYPES).map(function(key) {
+      return {
+        label: UserConstants.TYPES[key].NAME,
+        value: UserConstants.TYPES[key].VALUE
+      };
+    }));
+
   $scope.currentTypeFilter = $scope.typeFilterOptions[0];
 
   $scope.adminFilter = false;

http://git-wip-us.apache.org/repos/asf/ambari/blob/27cbe86a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersShowCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersShowCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersShowCtrl.js
index db43f18..2496717 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersShowCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersShowCtrl.js
@@ -22,13 +22,13 @@ angular.module('ambariAdminConsole')
 
   function loadUserInfo(){
     User.get($routeParams.id).then(function(data) {
-      $scope.user = data.Users;
+      $scope.user = User.makeUser(data).Users;
       $scope.isCurrentUser = $scope.user.user_name === Auth.getCurrentUser();
       $scope.editingGroupsList = angular.copy($scope.user.groups);
     });
   }
 
-  loadUserInfo();  
+  loadUserInfo();
   $scope.user;
   $scope.isCurrentUser = true;
   $scope.dataLoaded = false;
@@ -46,7 +46,6 @@ angular.module('ambariAdminConsole')
       if( !angular.equals(newValue, $scope.user.groups) ){
         $scope.updateGroups();
       }
-        
     }
   }, true);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/27cbe86a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/User.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/User.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/User.js
index 9d20413..c87f9d2 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/User.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/User.js
@@ -18,7 +18,7 @@
 'use strict';
 
 angular.module('ambariAdminConsole')
-.factory('User', ['Restangular', '$http', 'Settings', function(Restangular, $http, Settings) {
+  .factory('User', ['Restangular', '$http', 'Settings', 'UserConstants', function(Restangular, $http, Settings, UserConstants) {
   Restangular.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
     var extractedData;
     if(operation === 'getList'){
@@ -36,12 +36,12 @@ angular.module('ambariAdminConsole')
   return {
     list: function(params) {
       return $http.get(
-        Settings.baseUrl + '/users/?' 
+        Settings.baseUrl + '/users/?'
         + 'Users/user_name.matches(.*'+params.searchString+'.*)'
         + '&fields=*'
         + '&from=' + (params.currentPage-1)*params.usersPerPage
         + '&page_size=' + params.usersPerPage
-        + (params.ldap_user === '*' ? '' : '&Users/ldap_user=' + params.ldap_user)
+        + (params.user_type === '*' ? '' : '&Users/user_type=' + params.user_type)
         + (params.active === '*' ? '' : '&Users/active=' + params.active)
         + (params.admin ? '&Users/admin=true' : '')
       );
@@ -86,6 +86,21 @@ angular.module('ambariAdminConsole')
           'fields': '*'
         }
       });
+    },
+    /**
+     * Generate user info to display by response data from API.
+     * Generally this is a single point to manage all required and useful data
+     * needed to use as context for views/controllers.
+     *
+     * @param {Object} user - object from API response
+     * @returns {Object}
+     */
+    makeUser: function(user) {
+      user.Users.encoded_name = encodeURIComponent(user.Users.user_name);
+      user.Users.userTypeName = UserConstants.TYPES[user.Users.user_type].NAME;
+      user.Users.ldap_user = user.Users.user_type === UserConstants.TYPES.LDAP.VALUE;
+
+      return user;
     }
   };
 }]);

http://git-wip-us.apache.org/repos/asf/ambari/blob/27cbe86a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/UserConstants.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/UserConstants.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/UserConstants.js
new file mode 100644
index 0000000..d7cd451
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/UserConstants.js
@@ -0,0 +1,38 @@
+/**
+ * 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.
+ */
+'use strict';
+
+angular.module('ambariAdminConsole').constant('UserConstants', {
+  /**
+   * Available user_types 'values' and 'labels' map.
+   */
+  TYPES: {
+    LOCAL: {
+      VALUE: 'LOCAL',
+      NAME: 'Local'
+    },
+    LDAP: {
+      VALUE: 'LDAP',
+      NAME: 'LDAP'
+    },
+    JWT: {
+      VALUE: 'JWT',
+      NAME: 'JWT'
+    }
+  }
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/27cbe86a/ambari-admin/src/main/resources/ui/admin-web/app/views/users/list.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/users/list.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/users/list.html
index 97ec9d1..f2da12a 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/users/list.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/users/list.html
@@ -15,7 +15,7 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 -->
-    
+
 <div class="users-pane">
   <div class="clearfix">
     <ol class="breadcrumb pull-left">
@@ -70,7 +70,7 @@
         <td>
            <a href="#/users/{{user.Users.encoded_name}}">{{user.Users.user_name}}</a>
         </td>
-        <td>{{user.Users.ldap_user ? 'LDAP' : 'Local'}}</td>
+        <td>{{user.Users.userTypeName}}</td>
         <td><span ng-class="user.Users.active ? 'text-success' : 'text-danger'">{{user.Users.active ? 'Active' : 'Inactive'}}</span></td>
       </tr>
     </tbody>
@@ -82,6 +82,5 @@
     <div class="pull-right">
       <select class="form-control" ng-model="usersPerPage" ng-change="usersPerPageChanges()" ng-options="currOption for currOption in [10, 25, 50, 100]"></select>
     </div>
-    
   </div>
 </div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/27cbe86a/ambari-admin/src/main/resources/ui/admin-web/app/views/users/show.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/users/show.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/users/show.html
index bff097f..36efe6f 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/users/show.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/users/show.html
@@ -34,7 +34,7 @@
     <div class="form-group">
       <label for="" class="col-sm-2 control-label">Type</label>
       <div class="col-sm-10">
-        <label for="" class="control-label">{{user.ldap_user ? 'LDAP' : 'Local'}}</label>
+        <label for="" class="control-label">{{user.userTypeName}}</label>
       </div>
     </div>
     <div class="form-group">
@@ -102,5 +102,4 @@
       </div>
     </div>
   </form>
-</div>
-  
\ No newline at end of file
+</div>
\ No newline at end of file