Просмотр исходного кода

[security] Make Sentry action and server mandatory

Romain Rigaux 11 лет назад
Родитель
Сommit
c310f3067c

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

@@ -209,6 +209,7 @@ def list_sentry_privileges_by_authorizable(request):
     for role in roles:
       for privilege in get_api(request.user).list_sentry_privileges_by_role(role['name']): # authorizableHierarchy not working here?
         if privilege['database'] == authorizableHierarchy['db'] and ('table' not in authorizableHierarchy or privilege['table'] == authorizableHierarchy['table']):
+          privilege['roleName'] = role['name']
           privileges.append(privilege)
 
     result['privileges'] = privileges

+ 4 - 5
apps/security/src/security/templates/hive.mako

@@ -33,7 +33,6 @@ ${ layout.menubar(section='hive') }
     <a href="javascript: void(0)" class="pull-right" style="margin-right: 4px">
       <i class="fa fa-times" data-bind="click: remove"></i>
     </a>
-    ## 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">
 
@@ -42,10 +41,10 @@ ${ layout.menubar(section='hive') }
 
     <select data-bind="options: $root.availableActions, select2: { update: $data.action, type: 'action'}" style="width: 100px"></select>
 
-    &nbsp;&nbsp;<a class="pointer" data-bind="click: function(){ showAdvanced(true);}, visible: ! showAdvanced()"><i class="fa fa-cog"></i> ${ _('Show advanced options') }</a>
+    &nbsp;&nbsp;<a class="pointer" data-bind="click: function(){ showAdvanced(true); }, visible: ! showAdvanced()"><i class="fa fa-cog"></i> ${ _('Show advanced options') }</a>
 
     <div class="acl-block-section" data-bind="visible: showAdvanced">
-      <input type="text" data-bind="value: $data.server" placeholder="serverName">
+      <input type="text" data-bind="value: serverName" placeholder="serverName">
       <select data-bind="options: $root.availablePrivileges, select2: { update: $data.privilegeScope, type: 'scope'}" style="width: 100px"></select>
     </div>
 
@@ -56,9 +55,9 @@ ${ layout.menubar(section='hive') }
       <i class="fa fa-times" data-bind="click: remove"></i>
     </a>
 
-    <em class="muted" data-bind="text: moment(timestamp()).fromNow()"></em><br/>
+    <em class="muted" data-bind="text: moment(timestamp()).fromNow()"></em> <span data-bind="visible: roleName"> ${ _('for role') }<span data-bind="text: roleName"></span></span><br/>
     ${_('Database')}: <a data-bind="attr: { href: '/metastore/' + dbName() }" target="_blank"><span data-bind="text: dbName"></span></a><br/>
-    <span data-bind="text: action"></span>
+    ${_('Action')}: <span data-bind="text: action"></span>
     <span data-bind="text: privilegeScope"></span>
     <span data-bind="text: tableName"></span>
     <span data-bind="text: URI"></span>

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

@@ -29,6 +29,7 @@ function UUID() {
 var Privilege = function (vm, privilege) {
   var self = this;
 
+  self.roleName = ko.observable(typeof privilege.roleName != "undefined" && privilege.roleName != null ? privilege.roleName : "");
   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.serverName = ko.observable(typeof privilege.serverName != "undefined" && privilege.serverName != null ? privilege.serverName : "");
@@ -55,7 +56,7 @@ var Privilege = function (vm, privilege) {
       self.status('modified');
     }
   });
-  self.action = ko.observable(typeof privilege.action != "undefined" && privilege.action != null ? privilege.action : "");
+  self.action = ko.observable(typeof privilege.action != "undefined" && privilege.action != null ? privilege.action : 'SELECT');
   self.action.subscribe(function () {
     if (self.status() == '') {
       self.status('modified');
@@ -244,7 +245,7 @@ var Assist = function (vm) {
   self.path.subscribe(function (path) {
     vm.updatePathHash(path);
   });
-  self.server = ko.observable('');
+  self.server = ko.observable('server1');
   self.db = ko.computed(function () {
     return self.path().split(/[.]/)[0];
   });
@@ -584,7 +585,7 @@ var HiveViewModel = function (initial) {
   var self = this;
 
   self.availablePrivileges = ko.observableArray(['SERVER', 'DATABASE', 'TABLE']);
-  self.availableActions = ko.observableArray(['SELECT', 'INSERT', 'ALL', '']);
+  self.availableActions = ko.observableArray(['SELECT', 'INSERT', 'ALL']);
 
   // Models
   self.roles = ko.observableArray();
@@ -755,7 +756,8 @@ var HiveViewModel = function (initial) {
       'tableName': privilege.table,
       'URI': privilege.URI,
       'action': privilege.action,
-      'timestamp': privilege.timestamp
+      'timestamp': privilege.timestamp,
+      'roleName': privilege.roleName,
     });
     return _privilege;
   }