sentry.mako 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  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. <%!
  17. from desktop.views import commonheader, commonfooter, _ko
  18. from django.utils.translation import ugettext as _
  19. %>
  20. <%namespace name="actionbar" file="actionbar.mako" />
  21. <%namespace name="layout" file="layout.mako" />
  22. <%namespace name="tree" file="common_tree.mako" />
  23. ${ commonheader(_('Hadoop Security'), "security", user, request) | n,unicode }
  24. ${ layout.menubar(section=component) }
  25. <script type="text/html" id="role">
  26. <div class="acl-block-title">
  27. <i class="fa fa-cube muted"></i> <a class="pointer" data-bind="click: function(){ $root.showRole($data); }"><span data-bind="text: name"></span></a>
  28. </div>
  29. <div data-bind="template: { name: 'privilege', foreach: privilegesForView }"></div>
  30. <!-- ko ifnot: $root.isApplyingBulk() -->
  31. <div class="acl-block acl-actions">
  32. <span class="pointer" data-bind="visible: privilegesForViewTo() < privileges().length, click: function(){ privilegesForViewTo(privilegesForViewTo() + 50) }" title="${ _('Show 50 more...') }"><i class="fa fa-ellipsis-h"></i></span>
  33. <span class="pointer" data-bind="click: addPrivilege, visible: $root.is_sentry_admin" title="${ _('Add privilege') }"><i class="fa fa-plus"></i></span>
  34. <span class="pointer" data-bind="click: function() { $root.list_sentry_privileges_by_authorizable() }, visible: privilegesChanged().length > 0" title="${ _('Undo') }"> &nbsp; <i class="fa fa-undo"></i></span>
  35. <span class="pointer" data-bind="click: function() { deletePrivilegeModal($data) }, visible: privilegesChanged().length > 0" title="${ _('Save') }"> &nbsp; <i class="fa fa-save"></i></span>
  36. </div>
  37. <!-- /ko -->
  38. </script>
  39. <script type="text/html" id="privilege">
  40. <div data-bind="visible: status() != 'deleted' && status() != 'alreadydeleted'" class="acl-block acl-block-airy">
  41. <!-- ko if: editing() -->
  42. <div class="pull-right privilege-actions" data-bind="visible: grantOption() || $root.is_sentry_admin">
  43. <!-- ko if: $root.component() != 'solr' -->
  44. <a title="${ _('Grant this privilege') }" class="pointer" style="margin-right: 4px" data-bind="click: function(){ $root.grantToPrivilege($data); $('#grantPrivilegeModal').modal('show'); }"><i class="fa fa-send"></i></a>
  45. <!-- /ko -->
  46. <a class="pointer" style="margin-right: 4px" data-bind="click: function() { if (editing()) { editing(false); }}"><i class="fa fa-eye"></i></a>
  47. <a class="pointer" style="margin-right: 4px" data-bind="click: remove"><i class="fa fa-times"></i></a>
  48. </div>
  49. <!-- ko if: $root.component() == 'hive' -->
  50. <div class="inline-block" style="vertical-align: middle">
  51. <a class="pointer" style="padding-top: 4px" data-bind="click: function(){ privilegeType('DATABASE'); action($root.availableActions()[0]) }">
  52. <i class="fa fa-fw fa-1halfx muted" data-bind="css: {'fa-circle-o': privilegeType() != 'DATABASE', 'fa-check-circle-o': privilegeType() == 'DATABASE'}"></i>
  53. </a>
  54. </div>
  55. <input type="text" data-bind="hivechooser: $data.path, enable: privilegeType() == 'DATABASE'" placeholder="dbName.tableName <CTRL+SPACE>">
  56. <div class="inline-block" style="vertical-align: middle">
  57. <a class="pointer" style="padding-top: 4px" data-bind="click: function(){ privilegeType('URI'); action('ALL'); }">
  58. <i class="fa fa-fw fa-1halfx muted" data-bind="css: {'fa-circle-o': privilegeType() != 'URI', 'fa-check-circle-o': privilegeType() == 'URI'}"></i>
  59. </a>
  60. </div>
  61. <input type="text" data-bind="filechooser: 'URI TODO', enable: privilegeType() == 'URI'" placeholder="URI">
  62. <select data-bind="options: $root.availableActions, value: $data.action, enable: (privilegeType() == 'DATABASE')" style="width: 100px; margin-bottom: 0"></select>
  63. <!-- /ko -->
  64. <!-- ko if: $root.component() == 'solr' -->
  65. <input type="text" class="input-xxlarge" data-bind="solrchooser: $data.path" placeholder="collection or config name <CTRL+SPACE>">
  66. <select data-bind="options: privilegeType() == 'CONFIG' ? $root.availableSolrConfigActions : $root.availableActions, value: $data.action, enable: (privilegeType() == 'COLLECTION')" style="width: 100px; margin-bottom: 0"></select>
  67. <!-- /ko -->
  68. <div class="new-line-if-small">
  69. <!-- ko if: $root.component() != 'solr' -->
  70. <label class="checkbox"><input type="checkbox" data-bind="checked: grantOption"> ${ _('With grant') }</label>
  71. <!-- /ko -->
  72. <a class="pointer showAdvanced" data-bind="click: function(){ showAdvanced(true); }, visible: ! showAdvanced()"><i class="fa fa-cog"></i> ${ _('Show advanced') }</a>
  73. <a class="pointer showAdvanced" data-bind="click: function(){ showAdvanced(false); }, visible: showAdvanced()"><i class="fa fa-cog"></i> ${ _('Hide advanced') }</a>
  74. <div class="clearfix"></div>
  75. </div>
  76. <div class="acl-block-section" data-bind="visible: showAdvanced" style="margin-top: 0">
  77. ${ _('Server') } <input type="text" data-bind="value: serverName" placeholder="serverName" style="margin-left: 6px">
  78. </div>
  79. <!-- /ko -->
  80. <!-- ko ifnot: editing() -->
  81. <!-- ko ifnot: $root.isApplyingBulk() -->
  82. <div class="pull-right privilege-actions" data-bind="visible: grantOption() || $root.is_sentry_admin">
  83. <!-- ko if: $root.component() != 'solr' -->
  84. <a title="${ _('Grant this privilege') }" class="pointer" style="margin-right: 4px" data-bind="click: function(){ $root.grantToPrivilege($data); $('#grantPrivilegeModal').modal('show'); }"><i class="fa fa-send"></i></a>
  85. <!-- /ko -->
  86. <a title="${ _('Edit this privilege') }" class="pointer" style="margin-right: 4px" data-bind="visible: $root.is_sentry_admin, click: function() { if (! editing()) { editing(true); }}"><i class="fa fa-pencil"></i></a>
  87. <a title="${ _('Delete this privilege') }" class="pointer" style="margin-right: 4px" data-bind="visible: $root.is_sentry_admin, click: remove"><i class="fa fa-times"></i></a>
  88. </div>
  89. <!-- /ko -->
  90. <span class="muted" data-bind="text: privilegeType, attr: {title: moment(timestamp()).fromNow()}"></span>
  91. <!-- ko if: $root.component() == 'solr' && authorizables().length > 0 && authorizables()[0].type() == 'COLLECTION' && authorizables()[0].name_() != '*' -->
  92. <a data-bind="attr: { href: indexerPath() }" target="_blank" title="${ _('Open in Indexer') }" class="muted">
  93. <i class="fa fa-external-link"></i>
  94. </a>
  95. <!-- /ko -->
  96. <!-- ko if: grantOption -->
  97. <i class="fa fa-unlock muted" title="${ _('With grant option') }"></i>
  98. <!-- /ko -->
  99. <!-- ko if: $root.component() == 'hive' -->
  100. <span data-bind="visible: metastorePath() != '' && privilegeType() == 'DATABASE'">
  101. <a data-bind="attr: { href: metastorePath() }" class="muted" target="_blank" style="margin-left: 4px" title="${ _('Open in Metastore') }"><i class="fa fa-external-link"></i></a>
  102. </span>
  103. <br/>
  104. server=<span data-bind="text: serverName"></span>
  105. <!-- ko if: privilegeType() == 'DATABASE' -->
  106. // TODO
  107. <span data-bind="visible: dbName">
  108. <i class="fa fa-long-arrow-right"></i> db=<a class="pointer" data-bind="click: function(){ $root.linkToBrowse(dbName()) }" title="${ _('Browse db privileges') }"><span data-bind="text: dbName"></span></a>
  109. </span>
  110. <span data-bind="visible: tableName">
  111. <i class="fa fa-long-arrow-right"></i> table=<a class="pointer" data-bind="click: function(){ $root.linkToBrowse(dbName() + '.' + tableName()) }" title="${ _('Browse table privileges') }"><span data-bind="text: tableName"></span></a>
  112. </span>
  113. <span data-bind="visible: columnName">
  114. <i class="fa fa-long-arrow-right"></i> column=<a class="pointer" data-bind="click: function(){ $root.linkToBrowse(dbName() + '.' + tableName() + '.' + columnName()) }" title="${ _('Browse column privileges') }"><span data-bind="text: columnName"></span></a>
  115. </span>
  116. <!-- /ko -->
  117. <!-- ko if: privilegeType() == 'URI' -->
  118. <i class="fa fa-long-arrow-right"></i> <i class="fa fa-file-o"></i> <i class="fa fa-long-arrow-right"></i> <a data-bind="attr: { href: '/filebrowser/view=/' + URI().split('/')[3] }" target="_blank"><span data-bind="text: URI"></span></a>
  119. <!-- /ko -->
  120. <!-- /ko -->
  121. <!-- ko if: $root.component() == 'solr' -->
  122. <br/>
  123. <!-- ko foreach: authorizables -->
  124. <!-- ko if: name_() != '' -->
  125. <!-- ko if: $index() > 0 -->
  126. <i class="fa fa-long-arrow-right"></i>
  127. <!-- /ko -->
  128. <!-- ko if: type() == 'COLLECTION' && name_() != '*' -->
  129. <span data-bind="text: type"></span>=<a class="pointer" data-bind="click: function(){ $root.linkToBrowse('collections.' + name_()) }" title="${ _('Browse privileges') }"><span data-bind="text: name_"></span></a></span>
  130. <!-- /ko -->
  131. <!-- ko ifnot: type() == 'COLLECTION' && name_() != '*' -->
  132. <span data-bind="text: type"></span>=<span data-bind="text: name_"></span></span>
  133. <!-- /ko -->
  134. <!-- /ko -->
  135. <!-- /ko -->
  136. <!-- /ko -->
  137. <i class="fa fa-long-arrow-right"></i> action=<span data-bind="text: action"></span>
  138. <!-- /ko -->
  139. </div>
  140. </script>
  141. <div class="container-fluid">
  142. <div class="row-fluid">
  143. <div class="span2">
  144. <div class="sidebar-nav">
  145. <ul class="nav nav-list">
  146. <li class="nav-header">${ _('Privileges') }</li>
  147. <li class="active"><a href="javascript:void(0)" data-toggleSection="edit"><i class="fa fa-sitemap fa-rotate-270"></i> ${ _('Browse') }</a></li>
  148. <li><a href="javascript:void(0)" data-toggleSection="roles"><i class="fa fa-cubes"></i> ${ _('Roles') }</a></li>
  149. <li class="nav-header"><i class="fa fa-group"></i> ${ _('Groups') }
  150. <div>
  151. <br/>
  152. <select id="selectedGroup" data-bind="options: $root.selectableHadoopGroups, select2: { dropdownAutoWidth: true, update: $data.action, type: 'action', allowClear: true }" style="width: 100%"></select>
  153. </div>
  154. </li>
  155. </ul>
  156. </div>
  157. </div>
  158. <div class="span10">
  159. <div id="edit" class="mainSection card card-small">
  160. <h1 class="card-heading simple">
  161. <!-- ko if: component() == 'hive' -->
  162. ${ _('Database and Table privileges') }
  163. <!-- /ko -->
  164. <!-- ko if: component() == 'solr' -->
  165. ${ _('Collections privileges') }
  166. <!-- /ko -->
  167. <div id="help-content" class="hide">
  168. ${ _('Check the') } <a href="http://gethue.com/apache-sentry-made-easy-with-the-new-hue-security-app/#howto" target="_blank">${ _('documentation!') }</a>
  169. </div>
  170. <div data-bind="visible: ! $root.is_sentry_admin" class="pull-right" rel="tooltip" data-original-title="${ _('Click to see some Help') }" data-placement="top">
  171. <i class="fa fa-question-circle help" style="cursor: pointer"></i>
  172. </div>
  173. </h1>
  174. <div class="card-body">
  175. <div class="row-fluid" data-bind="visible: $root.doAs() != '${ user.username }' && ! $root.assist.isDiffMode()">
  176. <div class="span12">
  177. <div class="alert"><i class="fa fa-warning"></i> ${ _('You are currently impersonating the user') } <strong data-bind="text: $root.doAs"></strong></div>
  178. </div>
  179. </div>
  180. <div class="row-fluid">
  181. <div class="span6">
  182. <div class="path-container">
  183. <div class="input-append span12">
  184. <input id="path" class="path" type="text" autocomplete="off" />
  185. <!-- ko if: $root.component() == 'solr' -->
  186. <a data-bind="attr: { href: $root.assist.indexerPath() }" target="_blank" title="${ _('Open in Indexer') }" class="btn btn-inverse">
  187. <i class="fa fa-external-link"></i>
  188. </a>
  189. <!-- /ko -->
  190. <!-- ko ifnot: $root.component() == 'solr' -->
  191. <a data-bind="attr: { href: $root.assist.metastorePath() }" target="_blank" title="${ _('Open in Metastore Browser') }" class="btn btn-inverse">
  192. <i class="fa fa-external-link"></i>
  193. </a>
  194. <!-- /ko -->
  195. </div>
  196. <div class="clearfix"></div>
  197. <div class="tree-toolbar">
  198. <div class="pull-right">
  199. % if has_impersonation_perm:
  200. <div class="dropdown inline-block" style="margin-right: 6px">
  201. <a class="dropdown-toggle" data-toggle="dropdown" href="#">
  202. <i class="fa fa-eye-slash" data-bind="visible: $root.assist.isDiffMode"></i>
  203. <i class="fa fa-eye" data-bind="visible: ! $root.assist.isDiffMode()"></i>
  204. <span data-bind="visible: $root.assist.isDiffMode">${ _('Show non accessible paths for') }</span>
  205. <span data-bind="visible: ! $root.assist.isDiffMode()">${ _('Impersonate the user') }</span>
  206. </a>
  207. <ul class="dropdown-menu">
  208. <li data-bind="visible: ! $root.assist.isDiffMode(), click: function() { $root.assist.isDiffMode(true); }">
  209. <a tabindex="-1" href="#">${ _('Show non accessible paths for') }</a>
  210. </li>
  211. <li data-bind="visible: $root.assist.isDiffMode(), click: function() { $root.assist.isDiffMode(false); }">
  212. <a tabindex="-1" href="#">${ _('Impersonate the user') }</a>
  213. </li>
  214. </ul>
  215. </div>
  216. <select class="user-list" data-bind="options: $root.selectableHadoopUsers, select2: { dropdownAutoWidth: true, placeholder: '${ _ko("Select a user") }', update: $root.doAs, type: 'user'}" style="width: 120px"></select>
  217. % endif
  218. </div>
  219. <div>
  220. <a class="pointer" data-bind="click: $root.assist.collapseOthers" rel="tooltip" data-placement="right" title="${_('Close other nodes')}">
  221. <i class="fa fa-compress"></i>
  222. </a>
  223. &nbsp;
  224. <a class="pointer" data-bind="click: $root.assist.refreshTree" rel="tooltip" data-placement="right" title="${_('Refresh the tree')}">
  225. <i class="fa fa-refresh"></i>
  226. </a>
  227. &nbsp;
  228. <a class="pointer" data-bind="visible: $root.assist.checkedItems().length > 0, click: function(){ $root.isApplyingBulk(true); $('#bulkActionsModal').modal('show'); }" rel="tooltip" data-placement="right" title="${ _('Add, replace or remove ACLs for the checked paths') }">
  229. <i class="fa fa-copy"></i>
  230. </a>
  231. &nbsp;
  232. <i class="fa fa-spinner fa-spin" data-bind="visible: $root.assist.isLoadingTree()"></i>
  233. </div>
  234. </div>
  235. </div>
  236. ${ tree.render(id='expandableTree', data='$root.assist.treeData', afterRender='$root.assist.afterRender') }
  237. </div>
  238. <div class="span6 acl-panel">
  239. <div class="acl-panel-content">
  240. <div class="pull-right">
  241. <input class="input-medium no-margin" type="text" placeholder="${ _('Search privileges...') }" data-bind="value: privilegeFilter, valueUpdate: 'afterkeydown', visible: $root.assist.privileges().length > 1"> &nbsp;
  242. <a data-bind="visible: $root.assist.privileges().length > 0 && $root.is_sentry_admin, click: function(){ $root.showCreateRole(true); $('#createRoleModal').modal('show'); }" class="btn pointer">
  243. <i class="fa fa-plus-circle"></i> ${ _('Add role') }
  244. </a>
  245. </div>
  246. <div data-bind="visible: $root.assist.privileges().length == 0 && $root.isLoadingPrivileges()"><i class="fa fa-spinner fa-spin" data-bind="visible: $root.isLoadingPrivileges()"></i> <em class="muted">${ _('Loading privileges...')}</em></div>
  247. <h4 style="margin-top: 4px" data-bind="visible: $root.assist.privileges().length > 0 && ! $root.isLoadingPrivileges()">${ _('Privileges') } &nbsp;</h4>
  248. <div data-bind="visible: $root.assist.privileges().length == 0 && ! $root.isLoadingPrivileges()">
  249. <div class="span10 offset1 center" style="cursor: pointer" data-bind="click: function(){ if ($root.is_sentry_admin) { $root.showCreateRole(true); $('#createRoleModal').modal('show'); } }">
  250. <i data-bind="visible: $root.is_sentry_admin" class="fa fa-plus-circle waiting"></i>
  251. <h1 class="emptyMessage">
  252. ${ _('No privileges found for the selected item') }<br/>
  253. <a class="pointer" data-bind="visible: $root.is_sentry_admin">${ _('Click here to add some') }</a>
  254. </h1>
  255. </div>
  256. </div>
  257. <div data-bind="template: { name: 'role', foreach: $root.assist.roles }"></div>
  258. </div>
  259. </div>
  260. </div>
  261. </div>
  262. </div>
  263. <div id="roles" class="mainSection hide card card-small">
  264. <h1 class="card-heading simple">
  265. ${ _('Roles') }
  266. <div data-bind="visible: ! $root.is_sentry_admin" class="pull-right" rel="tooltip" data-original-title="${ _('Click to see some Help') }" data-placement="top">
  267. <i class="fa fa-question-circle help" style="cursor: pointer"></i>
  268. </div>
  269. </h1>
  270. <div class="card-body">
  271. <h1 class="muted" data-bind="visible: $root.isLoadingRoles()"><i class="fa fa-spinner fa-spin"></i></h1>
  272. <div class="span10 offset1 center" style="cursor: pointer" data-bind="visible: $root.roles().length == 0 && ! $root.isLoadingRoles(), click: function(){ if ($root.is_sentry_admin) { $root.showCreateRole(true); $('#createRoleModal').modal('show'); } }">
  273. <i data-bind="visible: $root.is_sentry_admin" class="fa fa-plus-circle waiting"></i>
  274. <h1 class="emptyMessage">
  275. ${ _('There are currently no roles defined') }<br/>
  276. <a class="pointer" data-bind="visible: $root.is_sentry_admin">${ _('Click here to add one') }</a>
  277. <br/>
  278. </h1>
  279. </div>
  280. <div class="clearfix" data-bind="visible: $root.roles().length == 0 && ! $root.isLoadingRoles()"></div>
  281. <div data-bind="visible: $root.roles().length > 0 && ! $root.isLoadingRoles()">
  282. <%actionbar:render>
  283. <%def name="search()">
  284. <input id="filterInput" type="text" class="input-xlarge search-query" placeholder="${_('Search roles by name, groups, etc...')}" data-bind="clearable: $root.roleFilter, valueUpdate: 'afterkeydown'">
  285. </%def>
  286. <%def name="actions()">
  287. <button class="btn toolbarBtn" data-bind="click: $root.expandSelectedRoles, enable: $root.selectedRoles().length > 0"><i class="fa fa-expand"></i> ${ _('Expand') }</button>
  288. <button class="btn toolbarBtn" data-bind="visible: $root.is_sentry_admin, click: function(){ $('#deleteRoleModal').modal('show'); }, enable: $root.selectedRoles().length > 0">
  289. <i class="fa fa-times"></i> ${ _('Delete') }
  290. </button>
  291. </%def>
  292. <%def name="creation()">
  293. <a data-bind="visible: $root.is_sentry_admin, click: function(){ $root.showCreateRole(true); $('#createRoleModal').modal('show'); }" class="btn pointer">
  294. <i class="fa fa-plus-circle"></i> ${ _('Add') }
  295. </a>
  296. </%def>
  297. </%actionbar:render>
  298. </div>
  299. <table class="card-marginbottom" data-bind="visible: $root.roles().length > 0 && ! $root.isLoadingRoles()">
  300. <thead>
  301. <th width="1%"><div data-bind="click: $root.selectAllRoles, css: { hueCheckbox: true, 'fa': true, 'fa-check': allRolesSelected }"></div></th>
  302. <th width="2%"></th>
  303. <th width="20%" style="text-align:left">${ _('Name') }</th>
  304. <th width="74%" style="text-align:left">${ _('Groups') }</th>
  305. <th width="3%"></th>
  306. </thead>
  307. <tbody data-bind="foreach: $root.filteredRoles">
  308. <tr>
  309. <td class="center" data-bind="click: handleSelect" style="cursor: default">
  310. <div data-bind="css: { hueCheckbox: true, 'fa': true, 'fa-check': selected }"></div>
  311. </td>
  312. <td class="center">
  313. <a href="javascript:void(0);" title="${ _('Show privileges') }">
  314. <i class="fa fa-2x fa-caret" data-bind="click: function() { if (showPrivileges()) { showPrivileges(false); } else { $root.list_sentry_privileges_by_role($data);} }, css: {'fa-caret-right' : ! showPrivileges(), 'fa-caret-down': showPrivileges() }"></i>
  315. </a>
  316. </td>
  317. <td data-bind="click: function() { if (showPrivileges()) { showPrivileges(false); } else { $root.list_sentry_privileges_by_role($data);} }" class="pointer">
  318. <a data-bind="attr: {'href': name}"></a>
  319. <i class="fa fa-cube muted"></i>
  320. <span data-bind="text: name"/>
  321. </td>
  322. <td>
  323. <!-- ko if: $root.is_sentry_admin -->
  324. <!-- ko if: !showEditGroups() && !groupsChanged() -->
  325. <a class="pointer" data-bind="click: function() { if ($root.is_sentry_admin) { showEditGroups(true); } }">
  326. <!-- ko if: groups().length > 0 -->
  327. <span data-bind="foreach: groups">
  328. <span data-bind="text: $data"></span>
  329. </span>
  330. <!-- /ko -->
  331. <!-- ko if: groups().length == 0 -->
  332. <span>
  333. <i class="fa fa-plus"></i> ${ _('Add a group') }
  334. </span>
  335. <!-- /ko -->
  336. </a>
  337. <!-- /ko -->
  338. <!-- ko if: showEditGroups() || (groupsChanged() && ! $root.isLoadingRoles()) -->
  339. <select data-bind="options: $root.selectableHadoopGroups, selectedOptions: groups, select2: { dropdownAutoWidth: true, update: groups, type: 'group' }" size="5" multiple="true" style="width: 400px"></select>
  340. <span data-bind="visible: groupsChanged() && !$root.isLoadingRoles()">
  341. &nbsp;
  342. <a class="pointer" data-bind="click: resetGroups"><i class="fa fa-undo"></i></a>
  343. &nbsp;
  344. <a class="pointer" data-bind="click: saveGroups"><i class="fa fa-save"></i></a>
  345. </span>
  346. <span data-bind="visible: !groupsChanged() && !$root.isLoadingRoles()">
  347. &nbsp;
  348. <a class="pointer" data-bind="click: function(){ showEditGroups(false); }"><i class="fa fa-times"></i></a>
  349. </span>
  350. <!-- /ko -->
  351. <!-- /ko -->
  352. <!-- ko ifnot: $root.is_sentry_admin -->
  353. <span data-bind="foreach: groups">
  354. <span data-bind="text: $data"></span>
  355. </span>
  356. <!-- /ko -->
  357. </td>
  358. <td>
  359. </td>
  360. </tr>
  361. <tr>
  362. <td colspan="2"></td>
  363. <td colspan="4">
  364. <div data-bind="template: { name: 'privilege', foreach: $data.privileges }, visible: $data.showPrivileges">
  365. </div>
  366. </td>
  367. </tr>
  368. <tr data-bind="visible: $data.showPrivileges">
  369. <td colspan="2"></td>
  370. <td colspan="4">
  371. <div class="acl-block acl-actions" data-bind="click: privilegesChanged().length == 0 ? addPrivilege : void(0), visible: $root.is_sentry_admin">
  372. <span class="pointer" data-bind="click: addPrivilege, visible: $data.showPrivileges" title="${ _('Add privilege') }"><i class="fa fa-plus"></i></span>
  373. <span class="pointer" data-bind="click: $root.list_sentry_privileges_by_role, visible: privilegesChanged().length > 0" title="${ _('Undo') }"> &nbsp; <i class="fa fa-undo"></i></span>
  374. <span class="pointer" data-bind="click: function() { deletePrivilegeModal($data) }, visible: privilegesChanged().length > 0 && isValid()" title="${ _('Save') }"> &nbsp; <i class="fa fa-save"></i></span>
  375. </div>
  376. </td>
  377. </tr>
  378. </tbody>
  379. </table>
  380. </div>
  381. </div>
  382. </div> <!-- /span10 -->
  383. </div>
  384. </div>
  385. <div id="createRoleModal" class="modal hide fade in" role="dialog">
  386. <div class="modal-header">
  387. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  388. <h3 data-bind="visible: ! $root.role().isEditing()">${ _('Add or select a role') }</h3>
  389. <h3 data-bind="visible: $root.role().isEditing()">${ _('Edit role') }</h3>
  390. </div>
  391. <div class="modal-body" data-bind="with: $root.role, visible: showCreateRole">
  392. <div class="row-fluid">
  393. <div class="span6">
  394. <h4>${ _('Name') }</h4>
  395. <input id="createRoleName" type="text" class="input-xlarge" data-bind="value: $data.name, visible: ! $data.isEditing()" placeholder="${ _('New or existing role name') }" style="width: 360px" />
  396. <strong data-bind="text: $data.name, visible: $data.isEditing()"></strong>
  397. </div>
  398. <div class="span6">
  399. <h4>${ _('Groups') }</h4>
  400. <select data-bind="options: $root.selectableHadoopGroups, selectedOptions: groups, select2: { dropdownAutoWidth: true, update: groups, type: 'group', placeholder: '${ _ko("Optional") }' }" size="5" multiple="true" style="width: 360px"></select>
  401. </div>
  402. </div>
  403. <h4>${ _('Privileges') }</h4>
  404. <div data-bind="template: { name: 'privilege', foreach: privileges }"></div>
  405. <div class="acl-block acl-actions pointer" data-bind="click: addPrivilege">
  406. <span class="pointer" title="${ _('Add privilege') }"><i class="fa fa-plus"></i></span>
  407. </div>
  408. </div>
  409. <div class="modal-footer">
  410. <button class="btn" data-dismiss="modal" aria-hidden="true">${ _('Cancel') }</button>
  411. <button data-loading-text="${ _('Saving...') }" class="btn btn-primary disable-enter" data-bind="click: $root.role().create, visible: ! $root.role().isEditing(), css: {'disabled': !$root.role().isValid()}">${ _('Save') }</button>
  412. <button data-loading-text="${ _('Saving...') }" class="btn btn-primary disable-enter" data-bind="click: $root.role().update, visible: $root.role().isEditing(), css: {'disabled': !$root.role().isValid()}">${ _('Update') }</button>
  413. </div>
  414. </div>
  415. <div id="grantPrivilegeModal" class="modal hide fade in" role="dialog">
  416. <div class="modal-header">
  417. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  418. <h3>${ _('Grant privilege') }</h3>
  419. </div>
  420. <div class="modal-body">
  421. <!-- ko if: $root.grantToPrivilege() -->
  422. <div data-bind="template: { name: 'privilege', data: $root.grantToPrivilege() }"></div>
  423. <!-- /ko -->
  424. <br/>
  425. <span>${ _('To role') }&nbsp;&nbsp;</span>
  426. <select data-bind="options: $root.selectableRoles(), value: $root.grantToPrivilegeRole, select2: { dropdownAutoWidth: true, update: $root.grantToPrivilegeRole, placeholder: '${ _ko("Select a role") }', type: 'role' }" style="width: 360px"></select>
  427. <br/>
  428. </div>
  429. <div class="modal-footer">
  430. <button class="btn" data-dismiss="modal" aria-hidden="true">${ _('Cancel') }</button>
  431. <button data-loading-text="${ _('Saving...') }" class="btn btn-primary disable-enter" data-bind="click: $root.grant_privilege">${ _('Grant') }</button>
  432. </div>
  433. </div>
  434. <div id="deleteRoleModal" class="modal hide fade in" role="dialog">
  435. <div class="modal-header">
  436. <a href="#" class="close" data-dismiss="modal">&times;</a>
  437. <h3>${ _('Do you really want to delete the selected role(s)?') }</h3>
  438. </div>
  439. <div class="modal-footer">
  440. <button class="btn" data-dismiss="modal" aria-hidden="true">${ _('Cancel') }</button>
  441. <button data-loading-text="${ _('Deleting...') }" class="btn btn-danger" data-bind="click: $root.deleteSelectedRoles">${ _('Yes') }</button>
  442. </div>
  443. </div>
  444. <div id="deletePrivilegeModal" class="modal hide fade in" role="dialog">
  445. <div class="modal-header">
  446. <a href="#" class="close" data-dismiss="modal">&times;</a>
  447. <h3>${ _('Confirm the deletion?') }</h3>
  448. </div>
  449. <div class="modal-body">
  450. ${ _('Sentry will recursively delete the SERVER or DATABASE privileges you marked for deletion.') }
  451. </div>
  452. <div class="modal-footer">
  453. <button class="btn" data-dismiss="modal" aria-hidden="true">${ _('Cancel') }</button>
  454. <button data-loading-text="${ _('Deleting...') }" class="btn btn-danger" data-bind="click: function() { $root.role().savePrivileges($root.roleToUpdate()); }">${ _('Yes, delete') }</button>
  455. </div>
  456. </div>
  457. <div id="bulkActionsModal" class="modal hide fade in" role="dialog">
  458. <div class="modal-header">
  459. <a href="#" class="close" data-dismiss="modal">&times;</a>
  460. <h3>${ _('Select one operation') }</h3>
  461. </div>
  462. <div class="modal-body" style="overflow-x: hidden">
  463. <div class="row-fluid">
  464. <div class="span8">
  465. <div class="row-fluid">
  466. <div class="span4 center">
  467. <div class="big-btn" data-bind="css: {'selected': $root.bulkAction() == 'add'}, click: function(){$root.bulkAction('add')}">
  468. <i class="fa fa-plus"></i><br/><br/>
  469. <span>${ _('Add current privileges to selection') }</span>
  470. </div>
  471. </div>
  472. <div class="span4 center">
  473. <div class="big-btn" data-bind="css: {'selected': $root.bulkAction() == 'sync'}, click: function(){$root.bulkAction('sync')}">
  474. <i class="fa fa-random"></i><br/><br/>
  475. <span>${ _('Replace selection with current privileges') }</span>
  476. </div>
  477. </div>
  478. <div class="span4 center">
  479. <div class="big-btn" data-bind="css: {'selected': $root.bulkAction() == 'delete'}, click: function(){$root.bulkAction('delete')}">
  480. <i class="fa fa-eraser"></i><br/><br/>
  481. <span>${ _('Delete all privileges of selection') }</span>
  482. </div>
  483. </div>
  484. </div>
  485. </div>
  486. <div class="span4">
  487. <h4>${ _('to apply to the selection') }</h4>
  488. <ul class="unstyled modal-panel" data-bind="foreach: $root.assist.checkedItems">
  489. <li data-bind="visible: path.indexOf('.') > -1" class="force-word-break">
  490. <i class="fa fa-database muted"></i>
  491. <span data-bind="text: path.split('.')[0]"></span>
  492. <i class="fa fa-long-arrow-right muted"></i>
  493. <i class="fa fa-table muted"></i>
  494. <span data-bind="text: path.split('.')[1]"></span>
  495. <span data-bind="visible: path.split('.')[2]">
  496. <i class="fa fa-long-arrow-right muted"></i>
  497. <i class="fa fa-columns muted"></i>
  498. <span data-bind="text: path.split('.')[2]"></span>
  499. </span>
  500. </li>
  501. <li data-bind="visible: path.indexOf('.') == -1" class="force-word-break">
  502. <i class="fa fa-database muted"></i> <span data-bind="text: path.split('.')[0]"></span>
  503. </li>
  504. </ul>
  505. </div>
  506. </div>
  507. <br/>
  508. <div class="row-fluid" data-bind="visible: $root.bulkAction() != '' && $root.bulkAction() != 'delete'">
  509. <div class="span12">
  510. <h4>${ _('Privileges to apply') }</h4>
  511. <div data-bind="visible: $root.assist.privileges().length == 0"><em class="muted">${ _('No privileges found for the selected item.')}</em></div>
  512. <div data-bind="template: { name: 'role', foreach: $root.assist.roles }" class="modal-panel"></div>
  513. </div>
  514. </div>
  515. </div>
  516. <div class="modal-footer">
  517. <button class="btn" data-dismiss="modal" aria-hidden="true">${ _('Cancel') }</button>
  518. <button class="btn" data-bind="enable: $root.bulkAction(), css: {'btn-primary': $root.bulkAction() != 'delete', 'btn-danger': $root.bulkAction() == 'delete'}, click: $root.bulkPerfomAction">${ _('Confirm') }</button>
  519. </div>
  520. </div>
  521. <div id="chooseFile" class="modal hide fade">
  522. <div class="modal-header">
  523. <a href="#" class="close" data-dismiss="modal">&times;</a>
  524. <h3>${_('Choose a file')}</h3>
  525. </div>
  526. <div class="modal-body">
  527. <div id="filechooser">
  528. </div>
  529. </div>
  530. <div class="modal-footer">
  531. </div>
  532. </div>
  533. <%def name="treeIcons()">
  534. 'fa-hdd-o': isServer(),
  535. 'fa-database-open': isDb() && (nodes().length > 0 || isLoaded()),
  536. 'fa-database': isDb() && nodes().length == 0,
  537. 'fa-table': isTable(),
  538. 'fa-columns': isColumn()
  539. </%def>
  540. <%def name="withPrivilegesPullRight()">
  541. <div class="pull-right">
  542. <i class="fa fa-shield" data-bind="visible: withPrivileges()" style="color: #338bb8" title="${ _('Has some privileges') }"></i>&nbsp;
  543. <i class="fa fa-file-o muted" data-bind="click: $root.assist.showAuthorizable ,visible: isTable()"></i>
  544. </div>
  545. </%def>
  546. ${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assist.togglePath', itemSelected='$root.assist.path() == path()', styleModifier='withPrivileges', iconModifier=treeIcons, anchorProperty='path', itemChecked='isChecked', styleModifierPullRight=withPrivilegesPullRight) }
  547. <script src="${ static('desktop/ext/js/routie-0.3.0.min.js') }" type="text/javascript" charset="utf-8"></script>
  548. <script src="${ static('security/js/sentry.ko.js') }" type="text/javascript" charset="utf-8"></script>
  549. <script src="${ static('desktop/js/jquery.hiveautocomplete.js') }" type="text/javascript" charset="utf-8"></script>
  550. <script src="${ static('desktop/js/jquery.filechooser.js') }" type="text/javascript" charset="utf-8"></script>
  551. <script type="text/javascript" charset="utf-8">
  552. function deletePrivilegeModal(role) {
  553. var cascadeDeletes = $.grep(role.privilegesChanged(), function(privilege) {
  554. return privilege.status() == 'deleted' && (privilege.privilegeType() == 'SERVER' || privilege.privilegeType() == 'DATABASE'); }
  555. );
  556. if (cascadeDeletes.length > 0 ) {
  557. viewModel.roleToUpdate(role);
  558. $('#deletePrivilegeModal').modal('show');
  559. } else {
  560. viewModel.role().savePrivileges(role);
  561. }
  562. }
  563. var viewModel = new SentryViewModel(${ initial | n,unicode });
  564. ko.applyBindings(viewModel);
  565. $(document).ready(function () {
  566. var _initialPath = viewModel.getPathHash();
  567. viewModel.init(_initialPath);
  568. $("#path").val(_initialPath);
  569. $(".help").popover({
  570. 'title': "${ _('Looking for edit permissions?') }",
  571. 'content': $("#help-content").html(),
  572. 'trigger': 'click',
  573. 'placement': 'left',
  574. 'html': true
  575. });
  576. function setPathFromAutocomplete(path){
  577. if (path.lastIndexOf(".") == path.length -1){
  578. path = path.substring(0, path.length - 1);
  579. }
  580. viewModel.assist.path(path);
  581. viewModel.assist.updatePathProperty(viewModel.assist.growingTree(), path, "isExpanded", true);
  582. viewModel.assist.fetchAuthorizablesPath();
  583. }
  584. $("#path").jHueGenericAutocomplete({
  585. skipColumns: true,
  586. serverType: viewModel.component().toUpperCase(),
  587. home: viewModel.assist.path(),
  588. onPathChange: function (path) {
  589. setPathFromAutocomplete(path);
  590. },
  591. onEnter: function (el) {
  592. setPathFromAutocomplete(el.val());
  593. },
  594. smartTooltip: "${_('Did you know? You can use the tab key or CTRL + Space to autocomplete file and folder names')}"
  595. });
  596. function resizeComponents() {
  597. $("#path").width($(".tree-toolbar").width() - 64);
  598. $("#expandableTree").height($(window).height() - 260);
  599. $(".acl-panel-content").height($(window).height() - 240);
  600. }
  601. resizeComponents();
  602. $(document).on("rendered.tree", function() {
  603. var _path = viewModel.assist.path();
  604. if (_path[_path.length-1] == "/"){
  605. _path = _path.substr(0, _path.length - 1);
  606. }
  607. if ($("a.anchor[href^='"+_path+"']").length > 0){
  608. $("#expandableTree").animate({
  609. scrollTop: ($("a.anchor[href^='"+_path+"']:first").position().top + $("#expandableTree").scrollTop() - $("#expandableTree").position().top - 4) + "px"
  610. });
  611. }
  612. });
  613. $(document).on("created.role", function(){
  614. $("#createRoleModal").modal("hide");
  615. $("#grantPrivilegeModal").modal("hide");
  616. $("#deletePrivilegeModal").modal("hide");
  617. viewModel.clearTempRoles();
  618. window.setTimeout(function(){
  619. viewModel.refreshExpandedRoles();
  620. }, 500);
  621. });
  622. $(document).on("deleted.role", function(){
  623. $("#deleteRoleModal").modal("hide");
  624. });
  625. $(document).on("changed.path", function(){
  626. if ($("#path").val() != viewModel.assist.path()){
  627. $("#path").val(viewModel.assist.path());
  628. }
  629. });
  630. function showMainSection(mainSection) {
  631. if ($("#" + mainSection).is(":hidden")) {
  632. $(".mainSection").hide();
  633. $("#" + mainSection).show();
  634. highlightMainMenu(mainSection);
  635. viewModel.updateSectionHash(mainSection);
  636. }
  637. logGA(mainSection);
  638. }
  639. function highlightMainMenu(mainSection) {
  640. $(".nav.nav-list li").removeClass("active");
  641. $("a[data-toggleSection='" + mainSection + "']").parent().addClass("active");
  642. }
  643. $("[data-toggleSection]").on("click", function(){
  644. showMainSection($(this).attr("data-toggleSection"));
  645. });
  646. showMainSection(viewModel.getSectionHash());
  647. $(document).on("show.mainSection", function(){
  648. showMainSection(viewModel.getSectionHash());
  649. });
  650. $(document).on("show.role", function(e, role) {
  651. if (typeof role != "undefined" && role.name != null){
  652. $("#bulkActionsModal").modal("hide");
  653. showMainSection("roles");
  654. $("html, body").animate({
  655. scrollTop: ($("a[href='" + role.name() + "']").position().top - 90) + "px"
  656. });
  657. }
  658. });
  659. var _resizeTimeout = -1;
  660. $(window).resize(function(){
  661. window.clearTimeout(_resizeTimeout);
  662. _resizeTimeout = window.setTimeout(resizeComponents, 100);
  663. });
  664. window.onpopstate = function() {
  665. viewModel.assist.path(viewModel.getPathHash());
  666. };
  667. $("#createRoleModal").modal({
  668. show: false
  669. });
  670. $("#grantPrivilegeModal").modal({
  671. show: false
  672. });
  673. $("#createRoleModal").on("show", function () {
  674. $(document).trigger("create.typeahead");
  675. });
  676. $("#createRoleModal").on("hide", function () {
  677. $('#jHueGenericAutocomplete').hide();
  678. viewModel.resetCreateRole();
  679. });
  680. $("#grantPrivilegeModal").on("hide", function () {
  681. viewModel.clearTempRoles();
  682. });
  683. $("#deleteRoleModal").modal({
  684. show: false
  685. });
  686. $("#selectedGroup").select2("val", "");
  687. $("#selectedGroup").change(function() {
  688. viewModel.list_sentry_privileges_by_authorizable();
  689. viewModel.list_sentry_roles_by_group();
  690. });
  691. $(document).on("added.bulk.privileges", function() {
  692. $(document).trigger("info", "${ _('The current privileges have been successfully added to the checked items.') }");
  693. $("#bulkActionsModal").modal("hide");
  694. });
  695. $(document).on("deleted.bulk.privileges", function() {
  696. $(document).trigger("info", "${ _('All the privileges have been successfully removed from the checked items.') }");
  697. $("#bulkActionsModal").modal("hide");
  698. });
  699. $(document).on("syncd.bulk.privileges", function() {
  700. $(document).trigger("info", "${ _('All the privileges for the checked items have been replaced with the current selection.') }");
  701. $("#bulkActionsModal").modal("hide");
  702. });
  703. $("#bulkActionsModal").modal({
  704. show: false
  705. });
  706. $("#bulkActionsModal").on("hidden", function(){
  707. viewModel.isApplyingBulk(false);
  708. });
  709. $(document).on("create.typeahead", function () {
  710. $("#createRoleName").typeahead({
  711. source: function (query) {
  712. var _options = [];
  713. viewModel.selectableRoles().forEach(function (item) {
  714. if (item.toLowerCase().indexOf(query.toLowerCase()) > -1) {
  715. _options.push(item);
  716. }
  717. });
  718. return _options;
  719. },
  720. minLength: 0,
  721. 'updater': function (item) {
  722. return item;
  723. }
  724. });
  725. });
  726. $(document).on('focus', '#createRoleName', function () {
  727. if ($("#createRoleName").data('typeahead')){
  728. $("#createRoleName").data('typeahead').lookup();
  729. }
  730. });
  731. $(document).on("destroy.typeahead", function(){
  732. $('.typeahead').unbind();
  733. $("ul.typeahead").hide();
  734. });
  735. $(document).trigger("create.typeahead");
  736. $("#deletePrivilegeModal").modal({
  737. show: false
  738. });
  739. });
  740. </script>
  741. ${ commonfooter(request, messages) | n,unicode }