list_groups.mako 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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
  18. import urllib
  19. from django.utils.translation import ugettext as _
  20. from useradmin.models import group_permissions
  21. %>
  22. <%namespace name="actionbar" file="actionbar.mako" />
  23. <%namespace name="layout" file="layout.mako" />
  24. ${ commonheader(_('Hue Groups'), "useradmin", user) | n,unicode }
  25. ${layout.menubar(section='groups')}
  26. <div class="container-fluid">
  27. <div class="card card-small">
  28. <h1 class="card-heading simple">${_('Hue Groups')}</h1>
  29. <%actionbar:render>
  30. <%def name="search()">
  31. <input id="filterInput" type="text" class="input-xlarge search-query"
  32. placeholder="${_('Search for name, members, etc...')}">
  33. </%def>
  34. <%def name="actions()">
  35. %if user.is_superuser:
  36. <button id="deleteGroupBtn" class="btn confirmationModal" title="${_('Delete')}" disabled="disabled"><i
  37. class="icon-trash"></i> ${_('Delete')}</button>
  38. %endif
  39. </%def>
  40. <%def name="creation()">
  41. %if user.is_superuser:
  42. <a id="addGroupBtn" href="${url('useradmin.views.edit_group')}" class="btn"><i
  43. class="icon-plus-sign"></i> ${_('Add group')}</a>
  44. <a id="addLdapGroupBtn" href="${url('useradmin.views.add_ldap_groups')}" class="btn"><i
  45. class="icon-refresh"></i> ${_('Add/Sync LDAP group')}</a>
  46. %endif
  47. </%def>
  48. </%actionbar:render>
  49. <table class="table table-striped table-condensed datatables">
  50. <thead>
  51. <tr>
  52. %if user.is_superuser:
  53. <th width="1%">
  54. <div id="selectAll" class="hueCheckbox"></div>
  55. </th>
  56. %endif
  57. <th>${_('Group Name')}</th>
  58. <th>${_('Members')}</th>
  59. <th>${_('Permissions')}</th>
  60. </tr>
  61. </thead>
  62. <tbody>
  63. % for group in groups:
  64. <tr class="tableRow"
  65. data-search="${group.name}${', '.join([group_user.username for group_user in group.user_set.all()])}">
  66. %if user.is_superuser:
  67. <td data-row-selector-exclude="true">
  68. <div class="hueCheckbox groupCheck" data-group="${group.name}"
  69. data-confirmation-url="${ url('useradmin.views.delete_group', name=urllib.quote(group.name))}"
  70. data-row-selector-exclude="true"></div>
  71. </td>
  72. %endif
  73. <td>
  74. %if user.is_superuser:
  75. <strong><a title="${_('Edit %(groupname)s') % dict(groupname=group.name)}"
  76. href="${ url('useradmin.views.edit_group', name=urllib.quote(group.name)) }"
  77. data-row-selector="true">${group.name}</a></strong>
  78. %else:
  79. <strong>${group.name}</strong>
  80. %endif
  81. </td>
  82. <td>${', '.join([group_user.username for group_user in group.user_set.all()])}</td>
  83. <td>${', '.join([perm.app + "." + perm.action for perm in group_permissions(group)])}</td>
  84. </tr>
  85. % endfor
  86. </tbody>
  87. <tfoot class="hide">
  88. <tr>
  89. <td colspan="8">
  90. <div class="alert">
  91. ${_('There are no groups matching the search criteria.')}
  92. </div>
  93. </td>
  94. </tr>
  95. </tfoot>
  96. </table>
  97. </div>
  98. </div>
  99. <div id="deleteGroup" class="modal hide fade groupModal"></div>
  100. <script type="text/javascript" charset="utf-8">
  101. $(document).ready(function () {
  102. $(".datatables").dataTable({
  103. "bPaginate": false,
  104. "bLengthChange": false,
  105. "bInfo": false,
  106. "bFilter": false,
  107. "bAutoWidth": false,
  108. "aoColumns": [
  109. %if user.is_superuser:
  110. { "bSortable": false },
  111. %endif
  112. { "sWidth": "20%" },
  113. { "sWidth": "20%" },
  114. null
  115. ],
  116. "oLanguage": {
  117. "sEmptyTable": "${_('No data available')}",
  118. "sZeroRecords": "${_('No matching records')}",
  119. }
  120. });
  121. $(".dataTables_wrapper").css("min-height", "0");
  122. $(".dataTables_filter").hide();
  123. $(".confirmationModal").click(function () {
  124. var _this = $(this);
  125. $.ajax({
  126. url: _this.data("confirmation-url"),
  127. beforeSend: function (xhr) {
  128. xhr.setRequestHeader("X-Requested-With", "Hue");
  129. },
  130. dataType: "html",
  131. success: function (data) {
  132. $("#deleteGroup").html(data);
  133. $("#deleteGroup").modal("show");
  134. }
  135. });
  136. });
  137. $("#selectAll").click(function () {
  138. if ($(this).attr("checked")) {
  139. $(this).removeAttr("checked");
  140. $(".groupCheck").removeClass("icon-ok").removeAttr("checked");
  141. }
  142. else {
  143. $(this).attr("checked", "checked");
  144. $(".groupCheck").addClass("icon-ok").attr("checked", "checked");
  145. }
  146. toggleActions();
  147. });
  148. $(".groupCheck").click(function () {
  149. if ($(this).attr("checked")) {
  150. $(this).removeClass("icon-ok").removeAttr("checked");
  151. }
  152. else {
  153. $(this).addClass("icon-ok").attr("checked", "checked");
  154. }
  155. toggleActions();
  156. });
  157. function toggleActions() {
  158. if ($(".groupCheck[checked='checked']").length == 1) {
  159. $("#deleteGroupBtn").removeAttr("disabled").data("confirmation-url", $(".groupCheck[checked='checked']").data("confirmation-url"));
  160. }
  161. else {
  162. $("#deleteGroupBtn").attr("disabled", "disabled");
  163. }
  164. }
  165. $("a[data-row-selector='true']").jHueRowSelector();
  166. });
  167. </script>
  168. ${layout.commons()}
  169. ${ commonfooter(messages) | n,unicode }