ソースを参照

HUE-2361 [sentry] Temporary roles should not show up in the list of roles

Enrico Berti 11 年 前
コミット
a5ebc25e2d

+ 7 - 0
apps/security/src/security/templates/hive.mako

@@ -243,6 +243,7 @@ ${ layout.menubar(section='hive') }
             <h1 class="emptyMessage">
               ${ _('There are currently no roles defined') }<br/>
               <a class="pointer" data-bind="visible: $root.is_sentry_admin">${ _('Click here to add one') }</a>
+              <br/>
             </h1>
           </div>
           <div class="clearfix" data-bind="visible: $root.roles().length == 0 && ! $root.isLoadingRoles()"></div>
@@ -602,6 +603,7 @@ ${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assi
         $("#createRoleModal").modal("hide");
         $("#grantPrivilegeModal").modal("hide");
         $("#deletePrivilegeModal").modal("hide");
+        viewModel.clear_temp_roles();
         window.setTimeout(function(){
           viewModel.refreshExpandedRoles();
         }, 500);
@@ -671,6 +673,11 @@ ${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assi
         viewModel.resetCreateRole();
       });
 
+      $("#grantPrivilegeModal").on("hidden", function () {
+        viewModel.clearTempRoles();
+      });
+
+
       $("#deleteRoleModal").modal({
         show: false
       });

+ 3 - 1
apps/security/static/js/common.ko.js

@@ -78,7 +78,9 @@ ko.bindingHandlers.select2 = {
                   viewModel.availablePrivileges.push(_newVal);
                 }
                 if (_type == "role") {
-                  viewModel.roles.push(new Role(viewModel, { name: _newVal }));
+                  var _r = new Role(viewModel, { name: _newVal });
+                  viewModel.tempRoles.push(_r);
+                  viewModel.roles.push(_r);
                 }
                 if (_isArray){
                   var _vals = $(element).select2("val");

+ 19 - 0
apps/security/static/js/hive.ko.js

@@ -747,6 +747,7 @@ var HiveViewModel = function (initial) {
 
   // Models
   self.roles = ko.observableArray();
+  self.tempRoles = ko.observableArray();
   self.originalRoles = ko.observableArray();
   self.roleFilter = ko.observable("");
   self.filteredRoles = ko.computed(function () {
@@ -1010,6 +1011,7 @@ var HiveViewModel = function (initial) {
         if (data.status == 0) {
           $(document).trigger("info", data.message);
           self.assist.refreshTree();
+          self.clearTempRoles();
           $(document).trigger("created.role");
         } else {
           $(document).trigger("error", data.message);
@@ -1020,6 +1022,23 @@ var HiveViewModel = function (initial) {
     });
   }
 
+  self.clearTempRoles = function () {
+    var _roles = [];
+    self.roles().forEach(function(role){
+      var _found = false;
+      self.tempRoles().forEach(function(tempRole){
+        if (role.name() == tempRole.name()){
+          _found = true;
+        }
+      });
+      if (! _found){
+        _roles.push(role);
+      }
+    });
+    self.roles(_roles);
+    self.tempRoles([]);
+  }
+
   self.list_sentry_privileges_by_authorizable = function (optionalPath, skipList) {
     var _path = self.assist.path();
     if (optionalPath != null){