hive.ko.js 21 KB

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