1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2005 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., 675 Mass Ave, Cambridge, MA 02139, USA.
28 # CONTRIBUTION SUBMISSION POLICY:
30 # (The following paragraph is not intended to limit the rights granted
31 # to you to modify and distribute this software under the terms of
32 # the GNU General Public License and is only of importance to you if
33 # you choose to contribute your changes and enhancements to the
34 # community by submitting them to Best Practical Solutions, LLC.)
36 # By intentionally submitting any modifications, corrections or
37 # derivatives to this work, or any other work intended for use with
38 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 # you are the copyright holder for those contributions and you grant
40 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
41 # royalty-free, perpetual, license to use, copy, create derivative
42 # works based on those contributions, and sublicense and distribute
43 # those contributions and any derivatives thereof.
45 # END BPS TAGGED BLOCK }}}
49 RT::SavedSearches - a pseudo-collection for SavedSearch objects.
57 SavedSearches is an object consisting of a number of SavedSearch objects.
58 It works more or less like a DBIx::SearchBuilder collection, although it
65 use_ok(RT::SavedSearches);
67 # The real tests are in lib/t/20savedsearch.t
73 package RT::SavedSearches;
84 my $class = ref($proto) || $proto;
86 bless ($self, $class);
87 $self->CurrentUser(@_);
89 $self->{'objects'} = [];
95 Takes two argumets: a privacy string, of the format "<class>-<id>", as
96 produced by RT::SavedSearch::Privacy(); and a type string, as produced
97 by RT::SavedSearch::Type(). The SavedSearches object will load the
98 searches belonging to that user or group that are of the type
99 specified. If no type is specified, all the searches belonging to the
100 user/group will be loaded. Repeated calls to the same object should DTRT.
109 my $object = $self->_GetObject($privacy);
112 $self->{'objects'} = [];
113 my @search_atts = $object->Attributes->Named('SavedSearch');
114 foreach my $att (@search_atts) {
115 my $search = RT::SavedSearch->new($self->CurrentUser);
116 $search->Load($privacy, $att->Id);
117 next if $type && $search->Type ne $type;
118 push(@{$self->{'objects'}}, $search);
121 $RT::Logger->error("Could not load object $privacy");
129 Returns the next object in the collection.
135 my $search = $self->{'objects'}->[$self->{'idx'}];
139 # We have run out of objects; reset the counter.
147 Returns the number of search objects found.
153 return scalar @{$self->{'objects'}};
158 # _GetObject: helper routine to load the correct object whose parameters
165 my ($obj_type, $obj_id) = split(/\-/, $privacy);
166 unless ($obj_type eq 'RT::User' || $obj_type eq 'RT::Group') {
167 $RT::Logger->error("Tried to load a search belonging to an $obj_type, which is neither a user nor a group");
174 \$object = $obj_type->new(\$self->CurrentUser);
175 \$object->Load($obj_id);
177 unless (ref($object) eq $obj_type) {
178 $RT::Logger->error("Could not load object of type $obj_type with ID $obj_id");
182 # Do not allow the loading of a user object other than the current
183 # user, or of a group object of which the current user is not a member.
185 if ($obj_type eq 'RT::User'
186 && $object->Id != $self->CurrentUser->UserObj->Id()) {
187 $RT::Logger->error('Requested user ' . $object->Id
188 . 'is not current user');
191 if ($obj_type eq 'RT::Group'
192 && !$object->HasMemberRecursively($self->CurrentUser->PrincipalObj)) {
193 $RT::Logger->error('Current user does not belong to requested group '
201 eval "require RT::SavedSearches_Vendor";
202 die $@ if ($@ && $@ !~ qr{^Can't locate RT/SavedSearches_Vendor.pm});
203 eval "require RT::SavedSearches_Local";
204 die $@ if ($@ && $@ !~ qr{^Can't locate RT/SavedSearches_Local.pm});