import rt 3.6.6
[freeside.git] / rt / lib / RT / Attachments_Overlay.pm
1 # BEGIN BPS TAGGED BLOCK {{{
2
3 # COPYRIGHT:
4 #  
5 # This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC 
6 #                                          <jesse@bestpractical.com>
7
8 # (Except where explicitly superseded by other copyright notices)
9
10
11 # LICENSE:
12
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
16 # from www.gnu.org.
17
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.
22
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.
28
29
30 # CONTRIBUTION SUBMISSION POLICY:
31
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.)
37
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.
46
47 # END BPS TAGGED BLOCK }}}
48 =head1 NAME
49
50   RT::Attachments - a collection of RT::Attachment objects
51
52 =head1 SYNOPSIS
53
54   use RT::Attachments;
55
56 =head1 DESCRIPTION
57
58 This module should never be called directly by client code. it's an internal module which
59 should only be accessed through exported APIs in Ticket, Queue and other similar objects.
60
61
62 =head1 METHODS
63
64
65 =begin testing
66
67 ok (require RT::Attachments);
68
69 =end testing
70
71 =cut
72
73
74 package RT::Attachments;
75
76 use strict;
77 no warnings qw(redefine);
78
79 # {{{ sub _Init  
80 sub _Init   {
81   my $self = shift;
82  
83   $self->{'table'} = "Attachments";
84   $self->{'primary_key'} = "id";
85   $self->OrderBy ( FIELD => 'id',
86                    ORDER => 'ASC');
87   return ( $self->SUPER::_Init(@_));
88 }
89 # }}}
90
91
92 # {{{ sub ContentType
93
94 =head2 ContentType (VALUE => 'text/plain', ENTRYAGGREGATOR => 'OR', OPERATOR => '=' ) 
95
96 Limit result set to attachments of ContentType 'TYPE'...
97
98 =cut
99
100
101 sub ContentType  {
102   my $self = shift;
103   my %args = ( VALUE => 'text/plain',
104                OPERATOR => '=',
105                ENTRYAGGREGATOR => 'OR',
106                @_);
107
108   $self->Limit ( FIELD => 'ContentType',
109                  VALUE => $args{'VALUE'},
110                  OPERATOR => $args{'OPERATOR'},
111                  ENTRYAGGREGATOR => $args{'ENTRYAGGREGATOR'});
112 }
113 # }}}
114
115 # {{{ sub ChildrenOf 
116
117 =head2 ChildrenOf ID
118
119 Limit result set to children of Attachment ID
120
121 =cut
122
123
124 sub ChildrenOf  {
125   my $self = shift;
126   my $attachment = shift;
127   $self->Limit ( FIELD => 'Parent',
128                  VALUE => $attachment);
129 }
130 # }}}
131
132 # {{{ sub NewItem 
133 sub NewItem  {
134   my $self = shift;
135
136   use RT::Attachment;
137   my $item = new RT::Attachment($self->CurrentUser);
138   return($item);
139 }
140 # }}}
141
142 # {{{ sub Next
143 sub Next {
144     my $self = shift;
145         
146     my $Attachment = $self->SUPER::Next();
147     if ((defined($Attachment)) and (ref($Attachment))) {
148         if ($Attachment->TransactionObj->__Value('Type') =~ /^Comment/ && 
149             $Attachment->TransactionObj->TicketObj->CurrentUserHasRight('ShowTicketComments')) {
150             return($Attachment);
151         } elsif ($Attachment->TransactionObj->__Value('Type') !~ /^Comment/ && 
152                  $Attachment->TransactionObj->TicketObj->CurrentUserHasRight('ShowTicket')) {
153             return($Attachment);
154         }
155
156         #If the user doesn't have the right to show this ticket
157         else {  
158             return($self->Next());
159         }
160     }
161
162     #if there never was any ticket
163     else {
164         return(undef);
165     }   
166 }
167 # }}}
168
169   1;
170
171
172
173