Browse Source

[security] Rename an HDFS acl

Romain Rigaux 11 years ago
parent
commit
2f3afc1
2 changed files with 17 additions and 5 deletions
  1. 8 0
      apps/security/src/security/api/hdfs.py
  2. 9 5
      apps/security/static/js/hdfs.ko.js

+ 8 - 0
apps/security/src/security/api/hdfs.py

@@ -38,8 +38,11 @@ def get_acls(request):
 def update_acls(request):
   path = request.POST.get('path')
   acls = json.loads(request.POST.get('acls'))
+  original_acls = json.loads(request.POST.get('originalAcls'))  
   
   try:
+    renamed_acls = set([_get_acl_name(acl) for acl in original_acls]) - set([_get_acl_name(acl) for acl in acls]) # We need to remove ACLs that have been renamed
+    _remove_acl_names(request.fs, path, list(renamed_acls))
     _remove_acl_entries(request.fs, path, [acl for acl in acls if acl['status'] == 'deleted'])
     _modify_acl_entries(request.fs, path, [acl for acl in acls if acl['status'] in ('new', 'modified')])
   except Exception, e:
@@ -57,3 +60,8 @@ def _modify_acl_entries(fs, path, acls):
 def _remove_acl_entries(fs, path, acls):
   aclspec = ','.join([_get_acl_name(acl) for acl in acls])
   return fs.remove_acl_entries(path, aclspec)
+
+
+def _remove_acl_names(fs, path, acl_names):
+  aclspec = ','.join(acl_names)
+  return fs.remove_acl_entries(path, aclspec)

+ 9 - 5
apps/security/static/js/hdfs.ko.js

@@ -21,16 +21,16 @@ function parseAcl(acl) {
 	'isDefault': m[1] != null,
     'type': m[2],
     'name': m[3],
-     'r': m[4] != '-',
-     'w': m[5] != '-',
-     'x': m[6] != '-',
-     'status': '',
+    'r': m[4] != '-',
+    'w': m[5] != '-',
+    'x': m[6] != '-',
+    'status': '',
   });
 
   acl.type.subscribe(function() {
     acl.status('modified');
   });
-  acl.name.subscribe(function() { // TODO duplicates
+  acl.name.subscribe(function() {
 	acl.status('modified');
   });
   acl.r.subscribe(function() {
@@ -60,6 +60,7 @@ var Assist = function(vm, assist) {
   self.files = ko.observableArray();
 
   self.acls = ko.observableArray();
+  self.originalAcls = ko.observableArray();
   self.regularAcls = ko.computed(function() {
 	return $.grep(self.acls(), function(acl){ return ! acl.isDefault(); });
   });
@@ -119,8 +120,10 @@ var Assist = function(vm, assist) {
     	'path': self.path()
       }, function (data) {
         self.acls.removeAll();
+        self.originalAcls.removeAll();
         $.each(data.entries, function(index, item) {
     	  self.acls.push(parseAcl(item));
+    	  self.originalAcls.push(parseAcl(item));
         });
         self.owner(data.owner);
         self.group(data.group);
@@ -138,6 +141,7 @@ var Assist = function(vm, assist) {
     $.post("/security/api/hdfs/update_acls", {
         'path': self.path(),
         'acls': ko.mapping.toJSON(self.acls()),
+        'originalAcls': ko.mapping.toJSON(self.originalAcls()),
       }, function (data) {
         var toDelete = []
     	$.each(self.acls(), function(index, item) {