import of rt 3.0.9
[freeside.git] / rt / html / Admin / Elements / SelectRights
1 %# BEGIN LICENSE BLOCK
2 %# 
3 %# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
4 %# 
5 %# (Except where explictly superceded by other copyright notices)
6 %# 
7 %# This work is made available to you under the terms of Version 2 of
8 %# the GNU General Public License. A copy of that license should have
9 %# been provided with this software, but in any event can be snarfed
10 %# from www.gnu.org.
11 %# 
12 %# This work is distributed in the hope that it will be useful, but
13 %# WITHOUT ANY WARRANTY; without even the implied warranty of
14 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 %# General Public License for more details.
16 %# 
17 %# Unless otherwise specified, all modifications, corrections or
18 %# extensions to this work which alter its source code become the
19 %# property of Best Practical Solutions, LLC when submitted for
20 %# inclusion in the work.
21 %# 
22 %# 
23 %# END LICENSE BLOCK
24 <INPUT TYPE=HIDDEN NAME="CheckACL"  VALUE="<%$ACLDesc%>">
25      <TABLE BORDER=0>
26 <TR>
27 <TD valign=top width="180" align="left"> 
28 <h3><&|/l&>Current rights</&></h3>
29 % if ($ACLObj->Count() > 0) {
30 <i>(<&|/l&>Check box to revoke right</&>)</i> <BR>
31 % } else {
32 <i><&|/l&>No rights granted.</&></i> <BR>    
33 % }
34 % while (my $right = $ACLObj->Next()) {
35 % if ($right->RightName) {
36 <input type=checkbox value="<%$right->Id%>" name="RevokeRight-<%$ACLDesc%>-<%$right->RightName%>"> <% loc($right->RightName) %><br>
37 % }
38 %  }
39 </TD>
40 <TD valign=top>
41 <h3><&|/l&>New rights</&></h3> 
42 <SELECT SIZE=5  MULTIPLE  NAME="GrantRight-<%$ACLDesc%>">
43 % foreach $right (sort keys %Rights) {
44       <OPTION VALUE="<%$right%>"  
45         ><% loc($right) %></OPTION>
46 % }
47 <OPTION VALUE="" SELECTED><&|/l&>(no value)</&></OPTION>
48 </SELECT>
49 </TD>
50 </TR>
51 </TABLE>
52 <%INIT>
53     my ($right, $ACLDesc, $AppliesTo, %Rights);
54
55     # if the principal id points to a user, we really want to point
56     # to their ACL equivalence group. The machinations we're going through
57     # lead me to start to suspect that we really want users and groups
58     # to just be the same table. or _maybe_ that we want an object db.
59     my $princ = RT::Principal->new($RT::SystemUser);
60     $princ->Load($PrincipalId);
61     if ($princ->PrincipalType eq 'User') {
62     my $group = RT::Group->new($RT::SystemUser);
63         $group->LoadACLEquivalenceGroup($princ);
64         $PrincipalId = $group->PrincipalId;
65     }
66
67
68     my $ACLObj = new RT::ACL($session{'CurrentUser'});
69     my $ACE = new RT::ACE($session{'CurrentUser'});
70
71
72     $ACLObj->LimitToObject( $Object);
73     $ACLObj->LimitToPrincipal( Id => $PrincipalId);
74     $ACLObj->OrderBy(FIELD=>'RightName'); 
75
76     if (ref($Object) && UNIVERSAL::can($Object, 'AvailableRights')) { 
77         %Rights = %{$Object->AvailableRights};
78     } 
79
80         else {
81                 %Rights = { loc('System Error') => loc("No rights found")};
82         }
83         
84     $ACLDesc = "$PrincipalId-".ref($Object)."-".$Object->Id;
85 </%INIT>
86     
87 <%ARGS>
88 $PrincipalType => undef
89 $PrincipalId => undef
90 $Object =>undef
91 </%ARGS>