1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
6 %# <sales@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 %# General Public License for more details.
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 %# CONTRIBUTION SUBMISSION POLICY:
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
47 %# END BPS TAGGED BLOCK }}}
51 $AddPrincipal => undef
54 # Let callbacks get at principals and context before we do anything with them
55 $m->callback( Principals => $Principals, Context => $Context );
57 # Try to detect if we want to include an add user/group box
58 unless ( $AddPrincipal ) {
59 my $last = $Principals->[-1];
60 if ( $last->[0] =~ /Groups/i ) {
61 $AddPrincipal = 'group'; # loc
63 elsif ( $last->[0] =~ /Users/i ) {
64 $AddPrincipal = 'user'; # loc
68 my $anchor = $DECODED_ARGS->{Anchor} || '';
69 if ($anchor =~ /AddPrincipal/) {
70 for my $type ("group", "user") {
71 my $record = _ParseACLNewPrincipal($DECODED_ARGS, $type)
73 if ($record->PrincipalId) {
74 $anchor = "#acl-" . $record->PrincipalId;
80 %# Principals is an array of arrays, where the inner arrays are like:
81 %# [ 'Category name' => $CollectionObj => 'DisplayColumn' => 1 ]
82 %# The last value is a boolen determining if the value of DisplayColumn
83 %# should be loc()-ed before display.
85 <script type="text/javascript">
87 function sync_anchor(hash) {
88 if (!hash.length) return;
89 window.location.hash = hash;
90 jQuery(".rights-editor input[name=Anchor]").val(hash);
92 sync_anchor(<% $anchor |n,j %>);
94 jQuery(".rights-editor").tabs({
95 beforeActivate: function(ev, ui) {
96 sync_anchor(ui.newPanel.selector);
97 if ( ui.newTab.find('input[type=text]').size() > 0 ) {
98 ui.newTab.find('input[type=text]:first').focus();
103 jQuery(".rights-editor .category-tabs").tabs({
104 active: jQuery.cookie('rights-category-tab') || 0,
105 activate: function(ev, ui) {
106 jQuery.cookie('rights-category-tab', ui.newTab.index());
107 jQuery(".rights-editor .category-tabs").not(this).each(function() {
108 var item = jQuery(this);
109 var selected = item.tabs("option", "active") || 0;
110 if (selected != ui.newTab.index())
111 item.tabs("option", "active", ui.newTab.index());
118 <div class="rights-editor clearfix">
119 <input type="hidden" value="" name="Anchor" />
123 for my $category (@$Principals) {
124 my ($name, $collection, $col, $loc) = @$category;
126 <li class="category"><% loc($name) %></li>
128 while ( my $obj = $collection->Next ) {
129 my $display = ref $col eq 'CODE' ? $col->($obj) : $obj->$col;
130 my $id = "acl-" . $obj->PrincipalId;
132 <li><a href="#<% $id %>"><% $loc ? loc($display) : $display %></a></li>
137 % if ( $AddPrincipal ) {
138 <li class="category"><&|/l, loc($AddPrincipal) &>Add [_1]</&></li>
139 <li class="addprincipal">
140 <a href="#acl-AddPrincipal">
141 <input type="text" value=""
142 data-autocomplete="<% lc $AddPrincipal eq 'user' ? 'Users' : 'Groups' %>"
143 % if ( lc $AddPrincipal eq 'user' ) {
144 data-autocomplete-return="Name"
145 data-autocomplete-privileged="1"
147 name="AddPrincipalForRights-<% lc $AddPrincipal %>"
148 id="AddPrincipalForRights-<% lc $AddPrincipal %>" />
149 <script type="text/javascript">
151 jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>).keyup(function(){
152 toggle_addprincipal_validity(this, true);
153 }).keydown(function(event){
154 event.stopPropagation() // Disable tabs keyboard nav
157 jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>).on("autocompleteselect", addprincipal_onselect);
158 jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>).on("autocompletechange", addprincipal_onchange);
161 % my $type = lc $AddPrincipal eq 'user' ? loc('username') : loc($AddPrincipal);
162 <span class="warning"><&|/l, $type &>Invalid [_1]</&></span>
169 # Now generate our rights panels for each principal
170 for my $category (@$Principals) {
171 my ($name, $collection, $col, $loc) = @$category;
172 while ( my $obj = $collection->Next ) {
173 my $display = ref $col eq 'CODE' ? $col->($obj) : $obj->$col;
174 my $id = "acl-" . $obj->PrincipalId;
179 <% $loc ? loc($display) : $display %>
181 if ($obj->isa('RT::Group') and $obj->Domain eq 'UserDefined') {
182 my $subgroups = $obj->GroupMembersObj( Recursively => 1 );
183 $subgroups->LimitToUserDefinedGroups;
184 $subgroups->Limit( FIELD => 'Name', OPERATOR => '!=', VALUE => $obj->Name, CASESENSITIVE => 0 );
186 if ( $subgroups->Count ) {
187 my $inc = join ", ", map $_->Name, @{$subgroups->ItemsArrayRef};
189 <span class="subgroups"><&|/l, $inc &>includes [_1]</&></span>\
195 <& EditRightsCategoryTabs, Context => $Context, Principal => $obj, id => $id &>
201 if ( $AddPrincipal ) {
203 <div id="acl-AddPrincipal">
204 <h3><&|/l, loc($AddPrincipal) &>Add rights for this [_1]</&></h3>
205 <& EditRightsCategoryTabs, Context => $Context, id => 'acl-AddPrincipal' &>