浏览代码

HUE-7521 [security] Prevent JS error on printAcl not defined

Enrico Berti 8 年之前
父节点
当前提交
49d7c4f
共有 2 个文件被更改,包括 41 次插入41 次删除
  1. 40 40
      apps/security/src/security/static/security/js/hdfs.ko.js
  2. 1 1
      apps/security/src/security/templates/hdfs.mako

+ 40 - 40
apps/security/src/security/static/security/js/hdfs.ko.js

@@ -16,42 +16,6 @@
 
 var HdfsViewModel = (function () {
 
-  function parseAcl(acl) {
-    // (default:)?(user|group|mask|other):[[A-Za-z_][A-Za-z0-9._-]]*:([rwx-]{3})?
-    m = acl.match(/(default:)?(user|group|mask|other):(.*?):(.)(.)(.)/);
-    var acl = ko.mapping.fromJS({
-      'isDefault': m[1] != null,
-      'type': m[2],
-      'name': m[3],
-      'r': m[4] != '-',
-      'w': m[5] != '-',
-      'x': m[6] != '-',
-      'status': ''
-    });
-
-    acl.type.subscribe(function () {
-      acl.status('modified');
-    });
-    acl.name.subscribe(function () {
-      acl.status('modified');
-    });
-    acl.r.subscribe(function () {
-      acl.status('modified');
-    });
-    acl.w.subscribe(function () {
-      acl.status('modified');
-    });
-    acl.x.subscribe(function () {
-      acl.status('modified');
-    });
-
-    return acl;
-  }
-
-  function printAcl(acl) {
-    return (acl.isDefault() ? 'default:' : '') + acl.type() + ':' + acl.name() + ':' + (acl.r() ? 'r' : '-') + (acl.w() ? 'w' : '-') + (acl.x() ? 'x' : '-');
-  }
-
   var Assist = function (vm, assist) {
     var self = this;
 
@@ -163,13 +127,13 @@ var HdfsViewModel = (function () {
 
 
     self.addAcl = function () {
-      var newAcl = parseAcl('group::---');
+      var newAcl = vm.parseAcl('group::---');
       newAcl.status('new');
       self.acls.push(newAcl);
     };
 
     self.addDefaultAcl = function () {
-      var newAcl = parseAcl('default:group::---');
+      var newAcl = vm.parseAcl('default:group::---');
       newAcl.status('new');
       self.acls.push(newAcl);
     };
@@ -481,8 +445,8 @@ var HdfsViewModel = (function () {
           self.acls.removeAll();
           self.originalAcls.removeAll();
           $.each(data.entries, function (index, item) {
-            self.acls.push(parseAcl(item));
-            self.originalAcls.push(parseAcl(item));
+            self.acls.push(vm.parseAcl(item));
+            self.originalAcls.push(vm.parseAcl(item));
           });
           self.owner(data.owner);
           self.group(data.group);
@@ -665,6 +629,42 @@ var HdfsViewModel = (function () {
         $(document).trigger("loadedUsers");
       });
     }
+
+    self.parseAcl = function (acl) {
+    // (default:)?(user|group|mask|other):[[A-Za-z_][A-Za-z0-9._-]]*:([rwx-]{3})?
+    m = acl.match(/(default:)?(user|group|mask|other):(.*?):(.)(.)(.)/);
+    var acl = ko.mapping.fromJS({
+      'isDefault': m[1] != null,
+      'type': m[2],
+      'name': m[3],
+      'r': m[4] != '-',
+      'w': m[5] != '-',
+      'x': m[6] != '-',
+      'status': ''
+    });
+
+    acl.type.subscribe(function () {
+      acl.status('modified');
+    });
+    acl.name.subscribe(function () {
+      acl.status('modified');
+    });
+    acl.r.subscribe(function () {
+      acl.status('modified');
+    });
+    acl.w.subscribe(function () {
+      acl.status('modified');
+    });
+    acl.x.subscribe(function () {
+      acl.status('modified');
+    });
+
+    return acl;
+  }
+
+    self.printAcl = function (acl) {
+      return (acl.isDefault() ? 'default:' : '') + acl.type() + ':' + acl.name() + ':' + (acl.r() ? 'r' : '-') + (acl.w() ? 'w' : '-') + (acl.x() ? 'x' : '-');
+    }
   };
 
   return HdfsViewModel;

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

@@ -33,7 +33,7 @@ ${ layout.menubar(section='hdfs', is_embeddable=is_embeddable) }
 
 <script type="text/html" id="aclDisplay">
   <div data-bind="visible: status() != 'deleted'">
-    <span data-bind="text: printAcl($data)"></span>
+    <span data-bind="text: $root.printAcl($data)"></span>
   </div>
 </script>