1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
6 # <jesse@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/copyleft/gpl.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 }}}
50 RT::ACL - collection of RT ACE objects
55 my $ACL = new RT::ACL($CurrentUser);
74 no warnings qw(redefine);
79 Hand out the next ACE that was found
86 =head2 LimitToObject $object
88 Limit the ACL to rights for the object $object. It needs to be an RT::Record class.
95 unless ( defined($obj)
97 && UNIVERSAL::can( $obj, 'id' )
103 FIELD => 'ObjectType',
106 ENTRYAGGREGATOR => 'OR'
112 ENTRYAGGREGATOR => 'OR',
122 =head2 LimitNotObject $object
124 Limit the ACL to rights NOT on the object $object. $object needs to be
132 unless ( defined($obj)
134 && UNIVERSAL::can( $obj, 'id' )
139 $self->Limit( FIELD => 'ObjectType',
142 ENTRYAGGREGATOR => 'OR',
143 SUBCLAUSE => $obj->id
145 $self->Limit( FIELD => 'ObjectId',
148 ENTRYAGGREGATOR => 'OR',
150 SUBCLAUSE => $obj->id
156 # {{{ LimitToPrincipal
158 =head2 LimitToPrincipal { Type => undef, Id => undef, IncludeGroupMembership => undef }
160 Limit the ACL to the principal with PrincipalId Id and PrincipalType Type
165 if IncludeGroupMembership => 1 is specified, ACEs which apply to the principal due to group membership will be included in the resultset.
170 sub LimitToPrincipal {
172 my %args = ( Type => undef,
174 IncludeGroupMembership => undef,
176 if ( $args{'IncludeGroupMembership'} ) {
177 my $cgm = $self->NewAlias('CachedGroupMembers');
178 $self->Join( ALIAS1 => 'main',
179 FIELD1 => 'PrincipalId',
181 FIELD2 => 'GroupId' );
182 $self->Limit( ALIAS => $cgm,
185 VALUE => $args{'Id'},
186 ENTRYAGGREGATOR => 'OR' );
189 if ( defined $args{'Type'} ) {
190 $self->Limit( FIELD => 'PrincipalType',
192 VALUE => $args{'Type'},
193 ENTRYAGGREGATOR => 'OR' );
195 # if the principal id points to a user, we really want to point
196 # to their ACL equivalence group. The machinations we're going through
197 # lead me to start to suspect that we really want users and groups
198 # to just be the same table. or _maybe_ that we want an object db.
199 my $princ = RT::Principal->new($RT::SystemUser);
200 $princ->Load($args{'Id'});
201 if ($princ->PrincipalType eq 'User') {
202 my $group = RT::Group->new($RT::SystemUser);
203 $group->LoadACLEquivalenceGroup($princ);
204 $args{'Id'} = $group->PrincipalId;
206 $self->Limit( FIELD => 'PrincipalId',
208 VALUE => $args{'Id'},
209 ENTRYAGGREGATOR => 'OR' );
217 # {{{ ExcludeDelegatedRights
219 =head2 ExcludeDelegatedRights
221 Don't list rights which have been delegated.
225 sub ExcludeDelegatedRights {
227 $self->DelegatedBy(Id => 0);
228 $self->DelegatedFrom(Id => 0);
234 =head2 DelegatedBy { Id => undef }
236 Limit the ACL to rights delegated by the principal whose Principal Id is
250 FIELD => 'DelegatedBy',
252 VALUE => $args{'Id'},
253 ENTRYAGGREGATOR => 'OR'
262 =head2 DelegatedFrom { Id => undef }
264 Limit the ACL to rights delegate from the ACE which has the Id specified
276 $self->Limit(FIELD => 'DelegatedFrom', OPERATOR=> '=', VALUE => $args{'Id'}, ENTRYAGGREGATOR => 'OR');
287 my $ACE = $self->SUPER::Next();
288 if ( ( defined($ACE) ) and ( ref($ACE) ) ) {
290 if ( $self->CurrentUser->HasRight( Right => 'ShowACL',
291 Object => $ACE->Object )
292 or $self->CurrentUser->HasRight( Right => 'ModifyACL',
293 Object => $ACE->Object )
298 #If the user doesn't have the right to show this ACE
300 return ( $self->Next() );
304 #if there never was any ACE
315 #wrap around _DoSearch so that we can build the hash of returned
319 # $RT::Logger->debug("Now in ".$self."->_DoSearch");
320 my $return = $self->SUPER::_DoSearch(@_);
321 # $RT::Logger->debug("In $self ->_DoSearch. return from SUPER::_DoSearch was $return\n");
327 #Build a hash of this ACL's entries.
331 while (my $entry = $self->Next) {
332 my $hashkey = $entry->ObjectType . "-" . $entry->ObjectId . "-" . $entry->RightName . "-" . $entry->PrincipalId . "-" . $entry->PrincipalType;
334 $self->{'as_hash'}->{"$hashkey"} =1;
349 my %args = ( RightScope => undef,
350 RightAppliesTo => undef,
352 PrincipalId => undef,
353 PrincipalType => undef,
356 #if we haven't done the search yet, do it now.
359 if ($self->{'as_hash'}->{ $args{'RightScope'} . "-" .
360 $args{'RightAppliesTo'} . "-" .
361 $args{'RightName'} . "-" .
362 $args{'PrincipalId'} . "-" .
363 $args{'PrincipalType'}