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

[security] Simplify Sentry privilege form

Romain Rigaux пре 11 година
родитељ
комит
24dab6561f

+ 1 - 1
apps/security/src/security/api/hive.py

@@ -101,7 +101,7 @@ def create_role(request):
 
     result['role'] = {"name": role['name'], "groups": role['groups'], "grantorPrincipal": request.user.username}
 
-    result['message'] = ''
+    result['message'] = _('Role created!')
     result['status'] = 0
   except Exception, e:
     result['message'] = unicode(str(e), "utf8")

+ 1 - 1
apps/security/src/security/templates/hdfs.mako

@@ -60,7 +60,7 @@ ${ layout.menubar(section='hdfs') }
         <select class="group-list-acl" data-bind="options: $root.selectableHadoopGroups, select2: { placeholder: '${ _("Select a group") }', update: name, type: 'group'}" style="width: 200px"></select>
       </div>
 
-      <input type="text" data-bind="value: name, valueUpdate: 'afterkeydown', visible: type() == 'mask' || type() == 'other'" placeholder="${ _('name ad...') }" style="width: 180px; margin-bottom: 0px; height: 26px; min-height: 26px"/>
+      <input type="text" data-bind="value: name, valueUpdate: 'afterkeydown', visible: type() == 'mask' || type() == 'other'" placeholder="${ _('name ...') }" style="width: 180px; margin-bottom: 0px; height: 26px; min-height: 26px"/>
     </div>
 
     <br/>

+ 22 - 6
apps/security/src/security/templates/hive.mako

@@ -31,15 +31,27 @@ ${ layout.menubar(section='hive') }
 <div data-bind="visible: status() != 'deleted', click: function() { if (! editing()) { editing(true); } }">
 
   <!-- ko if: editing() -->
-    <input type="text" data-bind="value: $data.dbName" placeholder="dbName">
-    <input type="text" data-bind="value: $data.tableName" placeholder="tableName">
+    ## todo, role name
+    <input name="db" data-bind="attr: { name: 'privilege-' + $index() }" type="radio" checked/> 
+    <input type="text" data-bind="value: $data.path, valueUpdate: 'afterkeydown'" placeholder="dbName.tableName">
 
+    <input name="uri" data-bind="attr: { name: 'privilege-' + $index() }" type="radio"/>
     <input type="text" data-bind="value: $data.URI" placeholder="URI">
 
-    <input type="text" data-bind="value: $data.action" placeholder="action">
+    ## <input type="text" class="input-small" data-bind="value: $data.action" placeholder="action">
+    <select data-bind="options: $data.availableActions, select2: { update: $data.action, type: 'user'}" style="width: 100px"></select>
     
-    <input type="text" data-bind="value: $data.serverName" placeholder="serverName">
-    <select data-bind="options: availablePrivileges, value: privilegeScope"></select>
+    <div>
+      <label class="checkbox inline-block">
+        <i class="fa fa-cog"></i>
+        <input type="checkbox" data-bind="checked: showAdvanced"/>
+      </label>    
+    </div>
+
+    <span data-bind="visible: showAdvanced">
+      <input type="text" data-bind="value: $data.server" placeholder="serverName">
+      <select data-bind="options: availablePrivileges, value: privilegeScope"></select>
+    </span>
     
     <a href="javascript:void(0)"><i class="fa fa-minus" data-bind="click: remove"></i></a>
   <!-- /ko -->
@@ -189,7 +201,10 @@ ${ layout.menubar(section='hive') }
               <i class="fa fa-save"></i>
             </button>
           </div>
-
+          <br/>
+          <br/>
+          <br/>
+      <div>
         <table>
           <theader>
             <th style="width:1%"><div class="hueCheckbox selectAll fa"></div></th>
@@ -243,6 +258,7 @@ ${ layout.menubar(section='hive') }
             </tr>
         </tbody>
         </table>
+      </div>        
         </div>
       </div>
 

+ 36 - 6
apps/security/static/js/hive.ko.js

@@ -18,7 +18,9 @@
 var Privilege = function (vm, privilege) {
   var self = this;
 
-  self.privilegeScope = ko.observable(typeof privilege.privilegeScope != "undefined" && privilege.privilegeScope != null ? privilege.privilegeScope : "");
+  self.status = ko.observable(typeof privilege.status != "undefined" && privilege.status != null ? privilege.status : "");
+  self.editing = ko.observable(typeof privilege.editing != "undefined" && privilege.editing != null ? privilege.editing : false);
+  //self.privilegeScope = ko.observable(typeof privilege.privilegeScope != "undefined" && privilege.privilegeScope != null ? privilege.privilegeScope : "");
   self.serverName = ko.observable(typeof privilege.serverName != "undefined" && privilege.serverName != null ? privilege.serverName : "");
   self.serverName.subscribe(function () {
     if (self.status() == '') {
@@ -50,9 +52,38 @@ var Privilege = function (vm, privilege) {
     }
   });
 
-  self.status = ko.observable(typeof privilege.status != "undefined" && privilege.status != null ? privilege.status : "");
-  self.editing = ko.observable(typeof privilege.editing != "undefined" && privilege.editing != null ? privilege.editing : false);
-
+  // UI
+  self.showAdvanced = ko.observable(false);
+  self.path = ko.computed({
+	read: function () {
+	  if (self.tableName().length > 0) {
+	    return self.dbName() + "." + self.tableName();
+	  } else {
+        return self.dbName();
+	  }
+	},
+	write: function (value) {
+	  var lastSpacePos = value.lastIndexOf(".");
+	    if (lastSpacePos > 0) {
+	      this.dbName(value.substring(0, lastSpacePos));
+	      this.tableName(value.substring(lastSpacePos + 1));
+	    } else {
+	      this.dbName(value);
+	      this.tableName('');
+	    }
+	  },
+	owner: self
+  });
+  self.privilegeScope = ko.computed(function() {
+      if (self.tableName().length > 0) {
+        return 'TABLE';	
+      } else if (self.dbName().length > 0) {
+    	return 'DATABASE';
+      } else {
+    	return 'SERVER';
+      }
+  });  
+  
   self.availablePrivileges = ko.observableArray(['SERVER', 'DATABASE', 'TABLE']);
   self.availableActions = ko.observableArray(['SELECT', 'INSERT', 'ALL', '']);
 
@@ -105,8 +136,7 @@ var Role = function (vm, role) {
         vm.roles.unshift(new Role(vm, data.role));
         self.reset();
         vm.showCreateRole(false);
-      }
-      else {
+      } else {
         $(document).trigger("error", data.message);
       }
     }).fail(function (xhr, textStatus, errorThrown) {