import of rt 3.0.4
[freeside.git] / rt / html / User / Delegation.html
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 <& /Elements/Header, Title => loc("Delegate rights") &>
25 <& /User/Elements/Tabs, 
26     current_tab => 'User/Delegation.html', 
27     Title => loc("Delegate rights") &>
28
29 <& /Elements/ListActions, actions => \@results &>
30
31 <form method="post">
32 <& Elements/DelegateRights, personalgroups => $personalgroups, objects => $objects, ObjectType => 'RT::System' &>
33 <& Elements/DelegateRights, personalgroups => $personalgroups, objects => $objects, ObjectType => 'RT::Queue' &>
34 <& Elements/DelegateRights, personalgroups => $personalgroups, objects => $objects, ObjectType => 'RT::Group' &>
35
36 <& /Elements/Submit &>
37 </form>
38 <%INIT>
39
40 my (@results, $arg);
41 foreach $arg (keys %ARGS) {
42     next unless ($arg =~ /^Delegate-Existing-ACE-(\d+)-to-(\d+)-as-(\d+)$/);
43        my $parent = $1;
44        my $principal = $2;
45        my $delegation = $3;
46        unless ($ARGS{"Delegate-ACE-$1-to-$2"}) {
47             my $ace_to_del = RT::ACE->new($session{'CurrentUser'});
48             $ace_to_del->Load($delegation);
49             my ($delval, $delmsg) = $ace_to_del->Delete();
50             push (@results, $delmsg);
51        }
52 }
53
54 foreach $arg (keys %ARGS) { 
55     next unless ($arg =~ /^Delegate-ACE-(\d+)-to-(\d+)$/);
56     my $parent = $1;
57     my $principal = $2;
58     # if we already delegate it, we just don't care
59     next if (grep /^Delegate-Existing-ACE-$parent-to-$principal-/, keys %ARGS);
60     my $ace = RT::ACE->new($session{'CurrentUser'});
61     $ace->Load($1);
62     unless ($ace->Id) {
63         push (@results, loc('Right not found'));
64         next;
65     }
66     my ($delid, $delmsg) = $ace->Delegate(PrincipalId => $principal);
67     push (@results, $delmsg);
68 }
69
70 my $personalgroups = RT::Groups->new($session{'CurrentUser'});
71 $personalgroups->LimitToPersonalGroupsFor($session{'CurrentUser'}->PrincipalId);
72
73 my $objects;
74 my $acl = RT::ACL->new ($session{'CurrentUser'});
75 $acl->ExcludeDelegatedRights();
76 $acl->LimitToPrincipal(Id => $session{'CurrentUser'}->PrincipalId, 
77                        IncludeGroupMembership => 1
78                        );
79
80 while(my $right = $acl->Next) {
81        push @{$objects->{$right->ObjectType}{$right->ObjectId}},$right;
82 }
83 </%INIT>