hive.ko.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  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. isChecked: false,
  239. nodes: []
  240. };
  241. _tree.nodes.push(_item);
  242. }
  243. });
  244. if (typeof skipLoading == "undefined" || !skipLoading){
  245. self.loadData(self.growingTree());
  246. }
  247. }
  248. self.addTables = function (path, tables, skipLoading) {
  249. var _branch = self.growingTree();
  250. _branch.nodes.forEach(function (node) {
  251. if (node.path == path) {
  252. _branch = node;
  253. }
  254. });
  255. tables.forEach(function (table) {
  256. var _mainFound = false;
  257. var _path = path + "." + table;
  258. _branch.nodes.forEach(function (node) {
  259. if (node.path == _path) {
  260. _mainFound = true;
  261. }
  262. });
  263. if (!_mainFound) {
  264. var _item = {
  265. path: _path,
  266. name: table,
  267. isDb: false,
  268. isTable: true,
  269. isColumn: false,
  270. isExpanded: false,
  271. isChecked: false,
  272. nodes: []
  273. };
  274. _branch.nodes.push(_item);
  275. }
  276. });
  277. if (typeof skipLoading == "undefined" || !skipLoading){
  278. self.loadData(self.growingTree());
  279. }
  280. }
  281. self.addColumns = function (path, columns, skipLoading) {
  282. var _branch = self.growingTree();
  283. _branch.nodes.forEach(function (node) {
  284. if (node.path == path.split(".")[0]) {
  285. node.nodes.forEach(function (inode) {
  286. if (inode.path == path) {
  287. _branch = inode;
  288. }
  289. });
  290. }
  291. });
  292. columns.forEach(function (column) {
  293. var _mainFound = false;
  294. var _path = path + "." + column;
  295. _branch.nodes.forEach(function (node) {
  296. if (node.path == _path) {
  297. _mainFound = true;
  298. }
  299. });
  300. if (!_mainFound) {
  301. var _item = {
  302. path: _path,
  303. name: column,
  304. isDb: false,
  305. isTable: false,
  306. isColumn: true,
  307. isExpanded: false,
  308. isChecked: false,
  309. nodes: []
  310. };
  311. _branch.nodes.push(_item);
  312. }
  313. });
  314. if (typeof skipLoading == "undefined" || !skipLoading){
  315. self.loadData(self.growingTree());
  316. }
  317. }
  318. self.collapseTree = function () {
  319. self.updateTreeProperty(self.growingTree(), "isExpanded", false);
  320. self.updatePathProperty(self.growingTree(), "__HUEROOT__", "isExpanded", true);
  321. self.loadData(self.growingTree());
  322. }
  323. self.collapseOthers = function () {
  324. self.updateTreeProperty(self.growingTree(), "isExpanded", false);
  325. self.updatePathProperty(self.growingTree(), "__HUEROOT__", "isExpanded", true);
  326. var _path = self.path();
  327. var _crumb = "";
  328. for (var i = 0; i < _path.length; i++) {
  329. if ((_path[i] === "." && _crumb != "")) {
  330. self.updatePathProperty(self.growingTree(), _crumb, "isExpanded", true);
  331. }
  332. _crumb += _path[i];
  333. }
  334. self.updatePathProperty(self.growingTree(), _path, "isExpanded", true);
  335. self.loadData(self.growingTree());
  336. }
  337. self.expandTree = function () {
  338. self.updateTreeProperty(self.growingTree(), "isExpanded", true);
  339. self.loadData(self.growingTree());
  340. }
  341. self.refreshTree = function (force) {
  342. self.growingTree(jQuery.extend(true, {}, self.initialGrowingTree));
  343. // load root first
  344. self.fetchHivePath("", function(){
  345. Object.keys(self.treeAdditionalData).forEach(function (path) {
  346. if (path.indexOf(".") == -1 && path != "") {
  347. if (typeof force == "boolean" && force) {
  348. self.fetchHivePath(path);
  349. }
  350. else {
  351. if (self.treeAdditionalData[path].loaded) {
  352. self.fetchHivePath(path, function(){
  353. Object.keys(self.treeAdditionalData).forEach(function (ipath) {
  354. if (ipath.split(".").length == 2 && ipath.split(".")[0] == path){
  355. self.fetchHivePath(ipath, function() {
  356. self.updateTreeProperty(self.growingTree(), "isExpanded", true);
  357. });
  358. }
  359. });
  360. });
  361. }
  362. }
  363. }
  364. });
  365. });
  366. }
  367. self.setPath = function (obj, toggle) {
  368. if (self.getTreeAdditionalDataForPath(obj.path()).loaded || (!obj.isExpanded() && !self.getTreeAdditionalDataForPath(obj.path()).loaded)) {
  369. if (typeof toggle == "boolean" && toggle) {
  370. obj.isExpanded(!obj.isExpanded());
  371. }
  372. else {
  373. obj.isExpanded(true);
  374. }
  375. self.updatePathProperty(self.growingTree(), obj.path(), "isExpanded", obj.isExpanded());
  376. }
  377. self.path(obj.path());
  378. $(document).trigger("changed.path");
  379. self.fetchHivePath();
  380. }
  381. self.togglePath = function (obj) {
  382. self.setPath(obj, true);
  383. }
  384. self.checkPath = function (obj) {
  385. obj.isChecked(!obj.isChecked());
  386. self.updatePathProperty(self.growingTree(), obj.path(), "isChecked", obj.isChecked());
  387. }
  388. self.getTreeAdditionalDataForPath = function (path) {
  389. if (typeof self.treeAdditionalData[path] == "undefined") {
  390. var _add = {
  391. loaded: false
  392. }
  393. self.treeAdditionalData[path] = _add;
  394. }
  395. return self.treeAdditionalData[path];
  396. }
  397. self.updatePathProperty = function (leaf, path, property, value) {
  398. if (leaf.path == path) {
  399. leaf[property] = value;
  400. }
  401. if (leaf.nodes.length > 0) {
  402. leaf.nodes.forEach(function (node) {
  403. self.updatePathProperty(node, path, property, value);
  404. });
  405. }
  406. return leaf;
  407. }
  408. self.updateTreeProperty = function (leaf, property, value) {
  409. leaf[property] = value;
  410. if (leaf.nodes.length > 0) {
  411. leaf.nodes.forEach(function (node) {
  412. self.updateTreeProperty(node, property, value);
  413. });
  414. }
  415. return leaf;
  416. }
  417. self.loadParents = function (callback) {
  418. self.fetchHivePath("", function(){
  419. self.updatePathProperty(self.growingTree(), "", "isExpanded", true);
  420. var _crumbs = self.path().split(".");
  421. self.fetchHivePath(_crumbs[0], function() {
  422. self.updatePathProperty(self.growingTree(), _crumbs[0], "isExpanded", true);
  423. if (_crumbs.length > 1){
  424. self.fetchHivePath(_crumbs[0] + "." + _crumbs[1], function(){
  425. self.updatePathProperty(self.growingTree(), _crumbs[0] + "." + _crumbs[1], "isExpanded", true);
  426. self.loadData(self.growingTree());
  427. if (typeof callback != "undefined") {
  428. callback();
  429. }
  430. else {
  431. self.collapseOthers();
  432. vm.list_sentry_privileges_by_authorizable();
  433. }
  434. });
  435. }
  436. else {
  437. self.loadData(self.growingTree());
  438. if (typeof callback != "undefined") {
  439. callback();
  440. }
  441. else {
  442. self.collapseOthers();
  443. vm.list_sentry_privileges_by_authorizable();
  444. }
  445. }
  446. });
  447. });
  448. }
  449. self.fetchHivePath = function (optionalPath, loadCallback) {
  450. var _originalPath = typeof optionalPath != "undefined" ? optionalPath : self.path();
  451. if (_originalPath.split(".").length < 3) {
  452. var _path = _originalPath.replace('.', '/');
  453. var request = {
  454. url: '/beeswax/api/autocomplete/' + _path,
  455. dataType: 'json',
  456. type: 'GET',
  457. success: function (data) {
  458. var _hasCallback = typeof loadCallback != "undefined";
  459. self.getTreeAdditionalDataForPath(_originalPath).loaded = true;
  460. if (data.databases) {
  461. self.addDatabases(_originalPath, data.databases, _hasCallback);
  462. } else if (data.tables && data.tables.length > 0) {
  463. self.addTables(_originalPath, data.tables, _hasCallback);
  464. } else if (data.columns && data.columns.length > 0) {
  465. self.addColumns(_originalPath, data.columns, _hasCallback);
  466. }
  467. if (_hasCallback) {
  468. loadCallback(data);
  469. } else {
  470. vm.list_sentry_privileges_by_authorizable();
  471. }
  472. },
  473. cache: false
  474. };
  475. $.ajax(request).fail(function (xhr, textStatus, errorThrown) {
  476. $(document).trigger("error", xhr.responseText);
  477. });
  478. }
  479. else {
  480. vm.list_sentry_privileges_by_authorizable();
  481. }
  482. };
  483. self.afterRender = function () {
  484. $(document).trigger("rendered.tree");
  485. }
  486. }
  487. var HiveViewModel = function (initial) {
  488. var self = this;
  489. self.availablePrivileges = ko.observableArray(['SERVER', 'DATABASE', 'TABLE']);
  490. self.availableActions = ko.observableArray(['SELECT', 'INSERT', 'ALL', '']);
  491. // Models
  492. self.roles = ko.observableArray();
  493. self.availableHadoopGroups = ko.observableArray();
  494. self.assist = new Assist(self);
  495. // Editing
  496. self.showCreateRole = ko.observable(false);
  497. self.role = new Role(self, {});
  498. self.privilege = new Privilege(self, {});
  499. self.doAs = ko.observable(initial.user);
  500. self.doAs.subscribe(function () {
  501. self.assist.fetchHivePath();
  502. });
  503. self.availableHadoopUsers = ko.observableArray();
  504. self.selectableHadoopUsers = ko.computed(function () {
  505. var _users = ko.utils.arrayMap(self.availableHadoopUsers(), function (user) {
  506. return user.username;
  507. });
  508. return _users.sort();
  509. }, self);
  510. self.selectableHadoopGroups = ko.computed(function () {
  511. var _groups = ko.utils.arrayMap(self.availableHadoopGroups(), function (group) {
  512. return group.name;
  513. });
  514. _groups.push("");
  515. return _groups.sort();
  516. }, self);
  517. self.selectAllRoles = function () {
  518. self.allRolesSelected(!self.allRolesSelected());
  519. ko.utils.arrayForEach(self.roles(), function (role) {
  520. role.selected(self.allRolesSelected());
  521. });
  522. return true;
  523. };
  524. self.allRolesSelected = ko.observable(false);
  525. self.selectedRoles = ko.computed(function () {
  526. return ko.utils.arrayFilter(self.roles(), function (role) {
  527. return role.selected();
  528. });
  529. }, self);
  530. self.selectedRole = ko.computed(function () {
  531. return self.selectedRoles()[0];
  532. }, self);
  533. self.deleteSelectedRoles = function () {
  534. ko.utils.arrayForEach(self.selectedRoles(), function (role) {
  535. role.remove(role);
  536. });
  537. };
  538. self.expandSelectedRoles = function () {
  539. ko.utils.arrayForEach(self.selectedRoles(), function (role) {
  540. if (! role.showPrivileges()) {
  541. self.list_sentry_privileges_by_role(role);
  542. }
  543. });
  544. };
  545. self.init = function (path) {
  546. self.fetchUsers();
  547. self.assist.path(path);
  548. self.list_sentry_roles_by_group();
  549. if (path != "") {
  550. self.assist.loadParents();
  551. } else {
  552. self.assist.fetchHivePath();
  553. }
  554. };
  555. self.removeRole = function (roleName) {
  556. $.each(self.roles(), function (index, role) {
  557. if (role.name == roleName) {
  558. self.roles.remove(role);
  559. return false;
  560. }
  561. });
  562. };
  563. self.list_sentry_roles_by_group = function () {
  564. $.ajax({
  565. type: "POST",
  566. url: "/security/api/hive/list_sentry_roles_by_group",
  567. data: {
  568. 'groupName': $('#selectedGroup').val()
  569. },
  570. success: function (data) {
  571. if (typeof data.status !== "undefined" && data.status == -1) {
  572. $(document).trigger("error", data.message);
  573. }
  574. else {
  575. self.roles.removeAll();
  576. $.each(data.roles, function (index, item) {
  577. self.roles.push(new Role(self, item));
  578. });
  579. }
  580. }
  581. }).fail(function (xhr, textStatus, errorThrown) {
  582. $(document).trigger("error", xhr.responseText);
  583. });
  584. };
  585. self.list_sentry_privileges_by_role = function (role) {
  586. $.ajax({
  587. type: "POST",
  588. url: "/security/api/hive/list_sentry_privileges_by_role",
  589. data: {
  590. 'roleName': role.name
  591. },
  592. success: function (data) {
  593. if (typeof data.status !== "undefined" && data.status == -1) {
  594. $(document).trigger("error", data.message);
  595. }
  596. else {
  597. role.privileges.removeAll();
  598. role.originalPrivileges.removeAll();
  599. $.each(data.sentry_privileges, function (index, item) {
  600. var privilege = _create_ko_privilege(item);
  601. role.privileges.push(privilege);
  602. role.originalPrivileges.push(privilege);
  603. });
  604. role.showPrivileges(true);
  605. }
  606. }
  607. }).fail(function (xhr, textStatus, errorThrown) {
  608. $(document).trigger("error", xhr.responseText);
  609. });
  610. };
  611. function _create_ko_privilege(privilege) {
  612. var _privilege = new Privilege(self, {
  613. 'privilegeScope': privilege.scope,
  614. 'serverName': privilege.server,
  615. 'dbName': privilege.database,
  616. 'tableName': privilege.table,
  617. 'URI': privilege.URI,
  618. 'action': privilege.action,
  619. 'timestamp': privilege.timestamp
  620. });
  621. return _privilege;
  622. }
  623. self.list_sentry_privileges_by_authorizable = function () {
  624. if (self.assist.path() != "") {
  625. $.ajax({
  626. type: "POST",
  627. url: "/security/api/hive/list_sentry_privileges_by_authorizable",
  628. data: {
  629. groups: ko.mapping.toJSON(['sambashare', 'hadoop']),
  630. roleSet: ko.mapping.toJSON({all: true, roles: []}),
  631. authorizableHierarchy: ko.mapping.toJSON({
  632. 'server': self.assist.server(),
  633. 'db': self.assist.db(),
  634. 'table': self.assist.table()
  635. })
  636. },
  637. success: function (data) {
  638. self.assist.privileges.removeAll();
  639. $.each(data.privileges, function (index, item) {
  640. self.assist.privileges.push(_create_ko_privilege(item));
  641. });
  642. }
  643. }).fail(function (xhr, textStatus, errorThrown) {
  644. $(document).trigger("error", xhr.responseText);
  645. });
  646. }
  647. };
  648. self.fetchUsers = function () {
  649. $.getJSON('/desktop/api/users/autocomplete', {
  650. 'include_myself': true,
  651. 'extend_user': true
  652. }, function (data) {
  653. self.availableHadoopUsers(data.users);
  654. self.availableHadoopGroups(data.groups);
  655. $(document).trigger("loaded.users");
  656. });
  657. }
  658. self.updatePathHash = function (path) {
  659. var _hash = window.location.hash;
  660. if (_hash.indexOf("@") == -1){
  661. window.location.hash = path;
  662. }
  663. else {
  664. window.location.hash = path + "@" + _hash.split("@")[1];
  665. }
  666. }
  667. self.updateSectionHash = function (section) {
  668. var _hash = window.location.hash;
  669. if (_hash == ""){
  670. window.location.hash = "@" + section;
  671. }
  672. if (_hash.indexOf("@") == -1){
  673. window.location.hash = _hash + "@" + section;
  674. }
  675. else {
  676. window.location.hash = _hash.split("@")[0] + "@" + section;
  677. }
  678. }
  679. self.getPathHash = function () {
  680. if (window.location.hash != "") {
  681. var _hash = window.location.hash.substr(1);
  682. if (_hash.indexOf("@") > -1){
  683. return _hash.split("@")[0];
  684. }
  685. else {
  686. return _hash;
  687. }
  688. }
  689. return "";
  690. }
  691. self.getSectionHash = function () {
  692. if (window.location.hash != "") {
  693. var _hash = window.location.hash.substr(1);
  694. if (_hash.indexOf("@") > -1){
  695. return _hash.split("@")[1];
  696. }
  697. }
  698. return "edit";
  699. }
  700. };
  701. function logGA(page) {
  702. if (typeof trackOnGA == 'function') {
  703. trackOnGA('security/' + page);
  704. }
  705. }