1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2012 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 use Scalar::Util qw(blessed);
56 # Let callbacks get at principals and context before we do anything with them
57 $m->callback( Principals => $Principals, Context => $Context );
59 # Try to detect if we want to include an add user/group box
60 unless ( $AddPrincipal ) {
61 my $last = $Principals->[-1];
62 if ( $last->[0] =~ /Groups/i ) {
63 $AddPrincipal = 'group'; # loc
65 elsif ( $last->[0] =~ /Users/i ) {
66 $AddPrincipal = 'user'; # loc
70 %# Principals is an array of arrays, where the inner arrays are like:
71 %# [ 'Category name' => $CollectionObj => 'DisplayColumn' => 1 ]
72 %# The last value is a boolen determining if the value of DisplayColumn
73 %# should be loc()-ed before display.
75 <script type="text/javascript">
77 jQuery(".rights-editor").tabs({
78 select: function(ev, ui) {
79 window.location.hash = ui.tab.hash;
82 jQuery(".rights-editor .category-tabs").tabs();
86 <div class="rights-editor clearfix">
89 for my $category (@$Principals) {
90 my ($name, $collection, $col, $loc) = @$category;
92 <li class="category"><% loc($name) %></li>
94 while ( my $obj = $collection->Next ) {
95 my $display = ref $col eq 'CODE' ? $col->($obj) : $obj->$col;
96 my $id = "acl-$name-" . $obj->PrincipalId;
97 $id =~ s/[^a-zA-Z0-9\-]/_/g;
99 <li><a href="#<% $id %>"><% $loc ? loc($display) : $display %></a></li>
104 % if ( $AddPrincipal ) {
105 <li class="category"><&|/l, loc($AddPrincipal) &>Add [_1]</&></li>
106 <li class="addprincipal">
107 <a href="#acl-AddPrincipal">
108 <input type="text" value=""
109 name="AddPrincipalForRights-<% lc $AddPrincipal %>"
110 id="AddPrincipalForRights-<% lc $AddPrincipal %>" />
111 <script type="text/javascript">
113 jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>).keyup(function(){
114 toggle_addprincipal_validity(this, true);
117 % if (lc $AddPrincipal eq 'group') {
118 jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>).autocomplete({
119 source: <% RT->Config->Get('WebPath') |n,j%>+"/Helpers/Autocomplete/Groups",
120 select: addprincipal_onselect,
121 change: addprincipal_onchange
126 % my $type = lc $AddPrincipal eq 'user' ? loc('username') : loc($AddPrincipal);
127 <span class="warning"><&|/l, $type &>Invalid [_1]</&></span>
134 # Now generate our rights panels for each principal
135 for my $category (@$Principals) {
136 my ($name, $collection, $col, $loc) = @$category;
137 while ( my $obj = $collection->Next ) {
138 my $display = ref $col eq 'CODE' ? $col->($obj) : $obj->$col;
139 my $id = "acl-$name-" . $obj->PrincipalId;
140 $id =~ s/[^a-zA-Z0-9\-]/_/g;
145 <% $loc ? loc($display) : $display %>
147 if ($obj->isa('RT::Group') and $obj->Domain eq 'UserDefined') {
148 my $subgroups = $obj->GroupMembersObj( Recursively => 1 );
149 $subgroups->LimitToUserDefinedGroups;
150 $subgroups->Limit( FIELD => 'Name', OPERATOR => '!=', VALUE => $obj->Name );
152 if ( $subgroups->Count ) {
153 my $inc = join ", ", map $_->Name, @{$subgroups->ItemsArrayRef};
155 <span class="subgroups"><&|/l, $inc &>includes [_1]</&></span>\
161 <& EditRightsCategoryTabs, Context => $Context, Principal => $obj, id => $id &>
167 if ( $AddPrincipal ) {
169 <div id="acl-AddPrincipal">
170 <h3><&|/l, loc($AddPrincipal) &>Add rights for this [_1]</&></h3>
171 <& EditRightsCategoryTabs, Context => $Context, id => 'acl-AddPrincipal' &>