hive.ko.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. var Privilege = function (vm, privilege) {
  17. var self = this;
  18. self.status = ko.observable(typeof privilege.status != "undefined" && privilege.status != null ? privilege.status : "");
  19. self.editing = ko.observable(typeof privilege.editing != "undefined" && privilege.editing != null ? privilege.editing : false);
  20. //self.privilegeScope = ko.observable(typeof privilege.privilegeScope != "undefined" && privilege.privilegeScope != null ? privilege.privilegeScope : "");
  21. self.serverName = ko.observable(typeof privilege.serverName != "undefined" && privilege.serverName != null ? privilege.serverName : "");
  22. self.serverName.subscribe(function () {
  23. if (self.status() == '') {
  24. self.status('modified');
  25. }
  26. });
  27. self.dbName = ko.observable(typeof privilege.dbName != "undefined" && privilege.dbName != null ? privilege.dbName : "");
  28. self.dbName.subscribe(function () {
  29. if (self.status() == '') {
  30. self.status('modified');
  31. }
  32. });
  33. self.tableName = ko.observable(typeof privilege.tableName != "undefined" && privilege.tableName != null ? privilege.tableName : "");
  34. self.tableName.subscribe(function () {
  35. if (self.status() == '') {
  36. self.status('modified');
  37. }
  38. });
  39. self.URI = ko.observable(typeof privilege.URI != "undefined" && privilege.URI != null ? privilege.URI : "");
  40. self.URI.subscribe(function () {
  41. if (self.status() == '') {
  42. self.status('modified');
  43. }
  44. });
  45. self.action = ko.observable(typeof privilege.action != "undefined" && privilege.action != null ? privilege.action : "");
  46. self.action.subscribe(function () {
  47. if (self.status() == '') {
  48. self.status('modified');
  49. }
  50. });
  51. // UI
  52. self.showAdvanced = ko.observable(false);
  53. self.path = ko.computed({
  54. read: function () {
  55. if (self.tableName().length > 0) {
  56. return self.dbName() + "." + self.tableName();
  57. } else {
  58. return self.dbName();
  59. }
  60. },
  61. write: function (value) {
  62. var lastSpacePos = value.lastIndexOf(".");
  63. if (lastSpacePos > 0) {
  64. this.dbName(value.substring(0, lastSpacePos));
  65. this.tableName(value.substring(lastSpacePos + 1));
  66. } else {
  67. this.dbName(value);
  68. this.tableName('');
  69. }
  70. },
  71. owner: self
  72. });
  73. self.privilegeScope = ko.computed(function() {
  74. if (self.tableName().length > 0) {
  75. return 'TABLE';
  76. } else if (self.dbName().length > 0) {
  77. return 'DATABASE';
  78. } else {
  79. return 'SERVER';
  80. }
  81. });
  82. self.remove = function (privilege) {
  83. if (privilege.status() == 'new') {
  84. privilege.status('alreadydeleted');
  85. } else {
  86. privilege.status('deleted');
  87. }
  88. }
  89. }
  90. var Role = function (vm, role) {
  91. var self = this;
  92. self.name = ko.observable(typeof role.name != "undefined" && role.name != null ? role.name : "");
  93. self.selected = ko.observable(false);
  94. self.handleSelect = function (row, e) {
  95. self.selected(!self.selected());
  96. }
  97. self.grantorPrincipal = ko.observable(typeof role.grantorPrincipal != "undefined" && role.grantorPrincipal != null ? role.grantorPrincipal : "");
  98. self.groups = ko.observableArray();
  99. $.each(typeof role.groups != "undefined" && role.groups != null ? role.groups : [], function (index, group) {
  100. self.groups.push(group);
  101. });
  102. self.privileges = ko.observableArray(); // Not included in the API
  103. self.originalPrivileges = ko.observableArray();
  104. self.showPrivileges = ko.observable(false);
  105. self.privilegesChanged = ko.computed(function () {
  106. return $.grep(self.privileges(), function (privilege) {
  107. return ['new', 'deleted', 'modified'].indexOf(privilege.status()) != -1;
  108. });
  109. });
  110. self.reset = function () {
  111. self.name('');
  112. self.groups.removeAll();
  113. self.privileges.removeAll();
  114. self.originalPrivileges.removeAll();
  115. }
  116. self.addGroup = function () {
  117. self.groups.push('');
  118. }
  119. self.addPrivilege = function () {
  120. self.privileges.push(new Privilege(vm, {'serverName': vm.assist.server(), 'status': 'new', 'editing': true}));
  121. }
  122. self.create = function () {
  123. $(".jHueNotify").hide();
  124. $.post("/security/api/hive/create_role", {
  125. role: ko.mapping.toJSON(self)
  126. }, function (data) {
  127. if (data.status == 0) {
  128. $(document).trigger("info", data.message);
  129. var role = new Role(vm, data.role);
  130. role.showPrivileges(true);
  131. vm.roles.unshift(role);
  132. self.reset();
  133. $(document).trigger("created.role");
  134. vm.showCreateRole(false);
  135. } else {
  136. $(document).trigger("error", data.message);
  137. }
  138. }).fail(function (xhr, textStatus, errorThrown) {
  139. $(document).trigger("error", xhr.responseText);
  140. });
  141. }
  142. self.remove = function (role) {
  143. $(".jHueNotify").hide();
  144. $.post("/security/api/hive/drop_sentry_role", {
  145. roleName: role.name
  146. }, function (data) {
  147. if (data.status == 0) {
  148. $(document).trigger("info", data.message);
  149. vm.removeRole(role.name);
  150. }
  151. else {
  152. $(document).trigger("error", data.message);
  153. }
  154. }).fail(function (xhr, textStatus, errorThrown) {
  155. $(document).trigger("error", xhr.responseText);
  156. });
  157. }
  158. self.savePrivileges = function (role) {
  159. $(".jHueNotify").hide();
  160. $.post("/security/api/hive/save_privileges", {
  161. role: ko.mapping.toJSON(role)
  162. }, function (data) {
  163. if (data.status == 0) {
  164. vm.list_sentry_privileges_by_role(role); // Refresh all role privileges
  165. } else {
  166. $(document).trigger("error", data.message);
  167. }
  168. }).fail(function (xhr, textStatus, errorThrown) {
  169. $(document).trigger("error", xhr.responseText);
  170. });
  171. }
  172. }
  173. var Assist = function (vm) {
  174. var self = this;
  175. self.compareNames = function (a, b) {
  176. if (a.name.toLowerCase() < b.name.toLowerCase())
  177. return -1;
  178. if (a.name.toLowerCase() > b.name.toLowerCase())
  179. return 1;
  180. return 0;
  181. }
  182. self.path = ko.observable("");
  183. self.path.subscribe(function (path) {
  184. window.location.hash = path;
  185. });
  186. self.server = ko.observable('');
  187. self.db = ko.computed(function () {
  188. return self.path().split(/[.]/)[0];
  189. });
  190. self.table = ko.computed(function () {
  191. return self.path().split(/[.]/)[1];
  192. });
  193. self.privileges = ko.observableArray();
  194. self.isDiffMode = ko.observable(false);
  195. self.isDiffMode = ko.observable(false);
  196. self.isDiffMode.subscribe(function () {
  197. //self.refreshTree();
  198. });
  199. self.isLoadingTree = ko.observable(false);
  200. self.treeAdditionalData = {};
  201. self.treeData = ko.observable({nodes: []});
  202. self.loadData = function (data) {
  203. self.treeData(new TreeNodeModel(data));
  204. };
  205. self.initialGrowingTree = {
  206. path: "__HUEROOT__",
  207. name: "__HUEROOT__",
  208. selected: false,
  209. nodes: []
  210. };
  211. self.growingTree = ko.observable(jQuery.extend(true, {}, self.initialGrowingTree));
  212. self.addDatabases = function (path, databases, skipLoading) {
  213. var _tree = self.growingTree();
  214. databases.forEach(function (db) {
  215. var _mainFound = false;
  216. _tree.nodes.forEach(function (node) {
  217. if (node.path == db) {
  218. _mainFound = true;
  219. }
  220. });
  221. if (!_mainFound) {
  222. var _item = {
  223. path: db,
  224. name: db,
  225. isDb: true,
  226. isTable: false,
  227. isColumn: false,
  228. isExpanded: false,
  229. nodes: []
  230. };
  231. _tree.nodes.push(_item);
  232. }
  233. });
  234. if (typeof skipLoading == "undefined" || !skipLoading){
  235. self.loadData(self.growingTree());
  236. }
  237. }
  238. self.addTables = function (path, tables, skipLoading) {
  239. var _branch = self.growingTree();
  240. _branch.nodes.forEach(function (node) {
  241. if (node.path == path) {
  242. _branch = node;
  243. }
  244. });
  245. tables.forEach(function (table) {
  246. var _mainFound = false;
  247. var _path = path + "." + table;
  248. _branch.nodes.forEach(function (node) {
  249. if (node.path == _path) {
  250. _mainFound = true;
  251. }
  252. });
  253. if (!_mainFound) {
  254. var _item = {
  255. path: _path,
  256. name: table,
  257. isDb: false,
  258. isTable: true,
  259. isColumn: false,
  260. isExpanded: false,
  261. nodes: []
  262. };
  263. _branch.nodes.push(_item);
  264. }
  265. });
  266. if (typeof skipLoading == "undefined" || !skipLoading){
  267. self.loadData(self.growingTree());
  268. }
  269. }
  270. self.addColumns = function (path, columns, skipLoading) {
  271. var _branch = self.growingTree();
  272. _branch.nodes.forEach(function (node) {
  273. if (node.path == path.split(".")[0]) {
  274. node.nodes.forEach(function (inode) {
  275. if (inode.path == path) {
  276. _branch = inode;
  277. }
  278. });
  279. }
  280. });
  281. columns.forEach(function (column) {
  282. var _mainFound = false;
  283. var _path = path + "." + column;
  284. _branch.nodes.forEach(function (node) {
  285. if (node.path == _path) {
  286. _mainFound = true;
  287. }
  288. });
  289. if (!_mainFound) {
  290. var _item = {
  291. path: _path,
  292. name: column,
  293. isDb: false,
  294. isTable: false,
  295. isColumn: true,
  296. isExpanded: false,
  297. nodes: []
  298. };
  299. _branch.nodes.push(_item);
  300. }
  301. });
  302. if (typeof skipLoading == "undefined" || !skipLoading){
  303. self.loadData(self.growingTree());
  304. }
  305. }
  306. self.collapseTree = function () {
  307. self.updateTreeProperty(self.growingTree(), "isExpanded", false);
  308. self.updatePathProperty(self.growingTree(), "__HUEROOT__", "isExpanded", true);
  309. self.loadData(self.growingTree());
  310. }
  311. self.collapseOthers = function () {
  312. self.updateTreeProperty(self.growingTree(), "isExpanded", false);
  313. self.updatePathProperty(self.growingTree(), "__HUEROOT__", "isExpanded", true);
  314. var _path = self.path();
  315. var _crumb = "";
  316. for (var i = 0; i < _path.length; i++) {
  317. if ((_path[i] === "." && _crumb != "")) {
  318. self.updatePathProperty(self.growingTree(), _crumb, "isExpanded", true);
  319. }
  320. _crumb += _path[i];
  321. }
  322. self.updatePathProperty(self.growingTree(), _path, "isExpanded", true);
  323. self.loadData(self.growingTree());
  324. }
  325. self.expandTree = function () {
  326. self.updateTreeProperty(self.growingTree(), "isExpanded", true);
  327. self.loadData(self.growingTree());
  328. }
  329. self.refreshTree = function (force) {
  330. self.growingTree(jQuery.extend(true, {}, self.initialGrowingTree));
  331. // load root first
  332. self.fetchHivePath("", function(){
  333. Object.keys(self.treeAdditionalData).forEach(function (path) {
  334. if (path.indexOf(".") == -1 && path != ""){
  335. if (typeof force == "boolean" && force) {
  336. self.fetchHivePath(path);
  337. }
  338. else {
  339. if (self.treeAdditionalData[path].loaded) {
  340. self.fetchHivePath(path, function(){
  341. Object.keys(self.treeAdditionalData).forEach(function (ipath) {
  342. if (ipath.split(".").length == 2 && ipath.split(".")[0] == path){
  343. self.fetchHivePath(ipath, function(){
  344. self.updateTreeProperty(self.growingTree(), "isExpanded", true);
  345. });
  346. }
  347. });
  348. });
  349. }
  350. }
  351. }
  352. });
  353. });
  354. }
  355. self.setPath = function (obj, toggle) {
  356. if (self.getTreeAdditionalDataForPath(obj.path()).loaded || (!obj.isExpanded() && !self.getTreeAdditionalDataForPath(obj.path()).loaded)) {
  357. if (typeof toggle == "boolean" && toggle) {
  358. obj.isExpanded(!obj.isExpanded());
  359. }
  360. else {
  361. obj.isExpanded(true);
  362. }
  363. self.updatePathProperty(self.growingTree(), obj.path(), "isExpanded", obj.isExpanded());
  364. }
  365. self.path(obj.path());
  366. $(document).trigger("changed.path");
  367. self.fetchHivePath();
  368. }
  369. self.togglePath = function (obj) {
  370. self.setPath(obj, true);
  371. }
  372. self.getTreeAdditionalDataForPath = function (path) {
  373. if (typeof self.treeAdditionalData[path] == "undefined") {
  374. var _add = {
  375. loaded: false
  376. }
  377. self.treeAdditionalData[path] = _add;
  378. }
  379. return self.treeAdditionalData[path];
  380. }
  381. self.updatePathProperty = function (leaf, path, property, value) {
  382. if (leaf.path == path) {
  383. leaf[property] = value;
  384. }
  385. if (leaf.nodes.length > 0) {
  386. leaf.nodes.forEach(function (node) {
  387. self.updatePathProperty(node, path, property, value);
  388. });
  389. }
  390. return leaf;
  391. }
  392. self.updateTreeProperty = function (leaf, property, value) {
  393. leaf[property] = value;
  394. if (leaf.nodes.length > 0) {
  395. leaf.nodes.forEach(function (node) {
  396. self.updateTreeProperty(node, property, value);
  397. });
  398. }
  399. return leaf;
  400. }
  401. self.loadParents = function (callback) {
  402. self.fetchHivePath("", function(){
  403. self.updatePathProperty(self.growingTree(), "", "isExpanded", true);
  404. var _crumbs = self.path().split(".");
  405. self.fetchHivePath(_crumbs[0], function(){
  406. self.updatePathProperty(self.growingTree(), _crumbs[0], "isExpanded", true);
  407. if (_crumbs.length > 1){
  408. self.fetchHivePath(_crumbs[0] + "." + _crumbs[1], function(){
  409. self.updatePathProperty(self.growingTree(), _crumbs[0] + "." + _crumbs[1], "isExpanded", true);
  410. self.loadData(self.growingTree());
  411. if (typeof callback != "undefined"){
  412. callback();
  413. }
  414. else {
  415. self.collapseOthers();
  416. vm.list_sentry_privileges_by_authorizable();
  417. }
  418. });
  419. }
  420. else {
  421. self.loadData(self.growingTree());
  422. if (typeof callback != "undefined"){
  423. callback();
  424. }
  425. else {
  426. self.collapseOthers();
  427. vm.list_sentry_privileges_by_authorizable();
  428. }
  429. }
  430. });
  431. });
  432. }
  433. self.fetchHivePath = function (optionalPath, loadCallback) {
  434. var _originalPath = typeof optionalPath != "undefined" ? optionalPath : self.path();
  435. if (_originalPath.split(".").length < 3) {
  436. var _path = _originalPath.replace('.', '/');
  437. var request = {
  438. url: '/beeswax/api/autocomplete/' + _path,
  439. dataType: 'json',
  440. type: 'GET',
  441. success: function (data) {
  442. var _hasCallback = typeof loadCallback != "undefined";
  443. //self.getTreeAdditionalDataForPath(self.path()).loaded = true;
  444. self.getTreeAdditionalDataForPath(_originalPath).loaded = true;
  445. if (data.databases) {
  446. self.addDatabases(_originalPath, data.databases, _hasCallback);
  447. }
  448. else if (data.tables && data.tables.length > 0) {
  449. self.addTables(_originalPath, data.tables, _hasCallback);
  450. }
  451. else if (data.columns && data.columns.length > 0) {
  452. self.addColumns(_originalPath, data.columns, _hasCallback);
  453. }
  454. if (_hasCallback){
  455. loadCallback(data);
  456. }
  457. else {
  458. vm.list_sentry_privileges_by_authorizable();
  459. }
  460. },
  461. cache: false
  462. };
  463. $.ajax(request).fail(function (xhr, textStatus, errorThrown) {
  464. $(document).trigger("error", xhr.responseText);
  465. });
  466. }
  467. else {
  468. vm.list_sentry_privileges_by_authorizable();
  469. }
  470. };
  471. self.afterRender = function () {
  472. $(document).trigger("rendered.tree");
  473. }
  474. }
  475. var HiveViewModel = function (initial) {
  476. var self = this;
  477. self.availablePrivileges = ko.observableArray(['SERVER', 'DATABASE', 'TABLE']);
  478. self.availableActions = ko.observableArray(['SELECT', 'INSERT', 'ALL', '']);
  479. // Models
  480. self.roles = ko.observableArray();
  481. self.availableHadoopGroups = ko.mapping.fromJS(initial.hadoop_groups);
  482. self.assist = new Assist(self);
  483. // Editing
  484. self.showCreateRole = ko.observable(false);
  485. self.role = new Role(self, {});
  486. self.privilege = new Privilege(self, {});
  487. self.doAs = ko.observable(initial.user);
  488. self.doAs.subscribe(function () {
  489. self.assist.fetchHivePath();
  490. });
  491. self.availableHadoopUsers = ko.observableArray();
  492. self.selectableHadoopUsers = ko.computed(function () {
  493. var _users = ko.utils.arrayMap(self.availableHadoopUsers(), function (user) {
  494. return user.username;
  495. });
  496. return _users.sort();
  497. }, self);
  498. self.selectableHadoopGroups = ko.computed(function () {
  499. var _users = ko.utils.arrayMap(self.availableHadoopGroups(), function (group) {
  500. return group.name;
  501. });
  502. return _users.sort();
  503. }, self);
  504. self.selectAllRoles = function () {
  505. self.allRolesSelected(!self.allRolesSelected());
  506. ko.utils.arrayForEach(self.roles(), function (role) {
  507. role.selected(self.allRolesSelected());
  508. });
  509. return true;
  510. };
  511. self.allRolesSelected = ko.observable(false);
  512. self.selectedRoles = ko.computed(function () {
  513. return ko.utils.arrayFilter(self.roles(), function (role) {
  514. return role.selected();
  515. });
  516. }, self);
  517. self.selectedRole = ko.computed(function () {
  518. return self.selectedRoles()[0];
  519. }, self);
  520. self.deleteSelectedRoles = function () {
  521. ko.utils.arrayForEach(self.selectedRoles(), function (role) {
  522. role.remove(role);
  523. });
  524. };
  525. self.expandSelectedRoles = function () {
  526. if (self.selectedRoles().length == 0){
  527. self.selectAllRoles();
  528. }
  529. ko.utils.arrayForEach(self.selectedRoles(), function (role) {
  530. self.list_sentry_privileges_by_role(role)
  531. });
  532. };
  533. self.init = function (path) {
  534. self.fetchUsers();
  535. self.assist.path(path);
  536. self.list_sentry_roles_by_group();
  537. if (path != ""){
  538. self.assist.loadParents();
  539. }
  540. else {
  541. self.assist.fetchHivePath();
  542. }
  543. };
  544. self.removeRole = function (roleName) {
  545. $.each(self.roles(), function (index, role) {
  546. if (role.name == roleName) {
  547. self.roles.remove(role);
  548. return false;
  549. }
  550. });
  551. };
  552. self.list_sentry_roles_by_group = function () {
  553. $.getJSON('/security/api/hive/list_sentry_roles_by_group', function (data) {
  554. if (typeof data.status !== "undefined" && data.status == -1) {
  555. $(document).trigger("error", data.message);
  556. }
  557. else {
  558. $.each(data.roles, function (index, item) {
  559. self.roles.push(new Role(self, item));
  560. });
  561. }
  562. }).fail(function (xhr, textStatus, errorThrown) {
  563. $(document).trigger("error", xhr.responseText);
  564. });
  565. };
  566. self.list_sentry_privileges_by_role = function (role) {
  567. $.ajax({
  568. type: "POST",
  569. url: "/security/api/hive/list_sentry_privileges_by_role",
  570. data: {
  571. 'roleName': role.name
  572. },
  573. success: function (data) {
  574. if (typeof data.status !== "undefined" && data.status == -1) {
  575. $(document).trigger("error", data.message);
  576. }
  577. else {
  578. role.privileges.removeAll();
  579. role.originalPrivileges.removeAll();
  580. $.each(data.sentry_privileges, function (index, item) {
  581. var privilege = _create_ko_privilege(item);
  582. role.privileges.push(privilege);
  583. role.originalPrivileges.push(privilege);
  584. });
  585. role.showPrivileges(true);
  586. }
  587. }
  588. }).fail(function (xhr, textStatus, errorThrown) {
  589. $(document).trigger("error", xhr.responseText);
  590. });
  591. };
  592. function _create_ko_privilege(privilege) {
  593. var _privilege = new Privilege(self, {
  594. 'privilegeScope': privilege.scope,
  595. 'serverName': privilege.server,
  596. 'dbName': privilege.database,
  597. 'tableName': privilege.table,
  598. 'URI': privilege.URI,
  599. 'action': privilege.action
  600. });
  601. _privilege.properties = ko.mapping.fromJS(privilege);
  602. return _privilege;
  603. }
  604. self.list_sentry_privileges_by_authorizable = function () {
  605. if (self.assist.path() != ""){
  606. $.ajax({
  607. type: "POST",
  608. url: "/security/api/hive/list_sentry_privileges_by_authorizable",
  609. data: {
  610. groups: ko.mapping.toJSON(['sambashare', 'hadoop']),
  611. roleSet: ko.mapping.toJSON({all: true, roles: []}),
  612. authorizableHierarchy: ko.mapping.toJSON({
  613. 'server': self.assist.server(),
  614. 'db': self.assist.db(),
  615. 'table': self.assist.table()
  616. })
  617. },
  618. success: function (data) {
  619. self.assist.privileges.removeAll();
  620. $.each(data.privileges, function (index, item) {
  621. self.assist.privileges.push(_create_ko_privilege(item));
  622. });
  623. }
  624. }).fail(function (xhr, textStatus, errorThrown) {
  625. $(document).trigger("error", xhr.responseText);
  626. });
  627. }
  628. };
  629. self.fetchUsers = function () {
  630. $.getJSON('/desktop/api/users/autocomplete', {
  631. 'include_myself': true,
  632. 'extend_user': true
  633. }, function (data) {
  634. self.availableHadoopUsers(data.users);
  635. self.availableHadoopGroups(data.groups);
  636. $(document).trigger("loaded.users");
  637. });
  638. }
  639. };
  640. function logGA(page) {
  641. if (typeof trackOnGA == 'function') {
  642. trackOnGA('security/' + page);
  643. }
  644. }