Bläddra i källkod

[security] Add privileges to existing Hive role

Romain Rigaux 11 år sedan
förälder
incheckning
bb0f2e9

+ 4 - 5
apps/security/src/security/api.py

@@ -80,8 +80,8 @@ def list_sentry_privileges_by_role(request):
   return HttpResponse(json.dumps(result), mimetype="application/json")
 
 
-def _hive_add_privileges(role, privileges):  
-    api = get_api(request.user)
+def _hive_add_privileges(user, role, privileges):  
+    api = get_api(user)
   
     _priviledges = {}
   
@@ -95,7 +95,6 @@ def _hive_add_privileges(role, privileges):
           'action': priviledge['action']
       })
   
-    
     return _priviledges
 
 
@@ -108,7 +107,7 @@ def hive_create_role(request):
     api = get_api(request.user)
   
     api.create_sentry_role(role['name'])
-    result['privileges'] = _hive_add_privileges(role, role['privileges'])
+    result['privileges'] = _hive_add_privileges(request.user, role, role['privileges'])
     api.alter_sentry_role_add_groups(role['name'], role['groups'])
 
     result['role'] = {"name": role['name'], "groups": [], "grantorPrincipal": request.user.username}
@@ -127,7 +126,7 @@ def hive_add_privileges(request):
   try:
     role = json.loads(request.POST['role'])
 
-    result['privileges'] = _hive_add_privileges(role, role['newPrivileges'])
+    result['privileges'] = _hive_add_privileges(request.user, role, role['newPrivileges'])
 
     result['message'] = ''
     result['status'] = 0

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

@@ -64,6 +64,10 @@ ${ layout.menubar(section='hive') }
             <i class="fa fa-external-link"></i>                
           </a>
         </div>
+        <div>
+          <i class="fa fa-eye"></i>
+          <i class="fa fa-eye-slash"></i>
+        </div>
         <div>
           <div class="span8">
             <div data-bind="foreach: $root.assist.files">
@@ -129,11 +133,11 @@ ${ layout.menubar(section='hive') }
         <div>
         <table>
           <theader>
-            <th width="1%"><div class="hueCheckbox selectAll fa"></div></th>
-            <th width="3%"></th>
-            <th>${ _('Name') }</th>
-            <th>${ _('Groups') }</th>
-            <th>${ _('Grantor Principal') }</th>
+            <th style="width:1%"><div class="hueCheckbox selectAll fa"></div></th>
+            <th style="width:3%"></th>
+            <th style="width:20%">${ _('Name') }</th>
+            <th style="width:67%">${ _('Groups') }</th>
+            <th style="width:10%">${ _('Grantor Principal') }</th>
           </theader> 
           <tbody data-bind="foreach: $root.roles">          
             <tr>
@@ -144,7 +148,11 @@ ${ layout.menubar(section='hive') }
                 <a href="javascript:void(0);"><i class="fa fa-2x" data-bind="click: $root.list_sentry_privileges_by_role, css: {'fa-caret-right' : ! showPrivileges(), 'fa-caret-down': showPrivileges() }""></i></a>
               </td>
               <td data-bind="text: name"></td>
-              <td data-bind="text: groups"></td>
+              <td>
+                <span data-bind="foreach: groups">
+                  <a href="/useradmin/groups"><span data-bind="text: $data"></span></a>
+                </span>
+              </td>
               <td>
                 <a href=""><span data-bind="text: grantorPrincipal"></span></a>
               </td>
@@ -152,6 +160,15 @@ ${ layout.menubar(section='hive') }
             <tr data-bind="foreach: $data.privileges, visible: $data.showPrivileges">
               <td colspan="2"></td>
               <td colspan="3">
+                <span data-bind="text: name"></span>
+                <span data-bind="text: timestamp"></span>    
+                <a data-bind="attr: { href: '/metastore/' + database() }" target="_blank"><span data-bind="text: database"></span></a>
+                <span data-bind="text: action"></span>
+                <span data-bind="text: scope"></span>
+                <span data-bind="text: table"></span>
+                <span data-bind="text: URI"></span>
+                <span data-bind="text: grantor"></span>
+                <span data-bind="text: server"></span>
                 <span data-bind="text: ko.mapping.toJSON($data)"></span> <a href="javascript:void(0);"><i class="fa fa-minus"></i></a>
               </td>
             </tr>

+ 7 - 8
apps/security/static/js/hive.ko.js

@@ -44,7 +44,6 @@ var Role = function(vm, privilege) {
 	self.name('');
     self.groups.removeAll();
     self.privileges.removeAll();
-    self.newPrivileges.removeAll();
   }
   
   self.addGroup = function() {
@@ -63,6 +62,7 @@ var Role = function(vm, privilege) {
         if (data.status == 0) {
           $(document).trigger("info", data.message);
           data.role['privileges'] = ko.observableArray();
+          data.role['newPrivileges'] = ko.observableArray();
           data.role['showPrivileges'] = ko.observable(false);          
           vm.roles.unshift(data.role);
           self.reset();
@@ -100,15 +100,14 @@ var Role = function(vm, privilege) {
   self.saveNewPrivileges = function(role) {
 	$(".jHueNotify").hide();
     $.post("/security/api/hive/add_privileges", {
-        role: ko.mapping.toJSON(self)
+        role: ko.mapping.toJSON(role)
       }, function (data) {
         if (data.status == 0) {
-          $(document).trigger("info", data.message);
-          data.role['privileges'] = ko.observableArray();
-          data.role['showPrivileges'] = ko.observable(false);          
-          vm.roles.unshift(data.role);
-          self.reset();
-          vm.showCreateRole(false);
+          $.each(data.privileges, function(index, privileges) { // TODO: get back a set<TSentryPrivilege>
+            //role['privileges'] = ko.observableArray();
+            //vm.roles.unshift(data.role); privileges            
+          });
+          // self.reset();
         }
         else {
           $(document).trigger("error", data.message);