hive.ko.js 23 KB

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