import rt 3.0.12
[freeside.git] / rt / html / Ticket / Elements / LoadTextAttachments
1 <%INIT>
2
3 my $attachments = RT::Attachments->new( $session{'CurrentUser'} );
4
5 $attachments->Columns( qw(id Content ContentType TransactionId ContentEncoding));
6
7 if ( $Ticket->CurrentUserHasRight('ShowTicket') ) {
8     my $transactions = $attachments->NewAlias('Transactions');
9     $attachments->Join( ALIAS1 => 'main',
10                                            FIELD1 => 'TransactionId',
11                                            ALIAS2 => $transactions,
12                                            FIELD2 => 'id' );
13     
14     my $tickets = $attachments->NewAlias('Tickets');
15
16     $attachments->Join( ALIAS1 => $transactions,
17                         FIELD1 => 'Ticket',
18                         ALIAS2 => $tickets,
19                         FIELD2 => 'id' );
20
21     $attachments->Limit( ALIAS => $tickets,
22                          FIELD => 'EffectiveId',
23                          VALUE => $Ticket->id() );
24     # if the user may not see comments do not return them
25     unless ( $Ticket->CurrentUserHasRight('ShowTicketComments') ) {
26         $attachments->Limit( ALIAS    => $transactions, FIELD    => 'Type', OPERATOR => '!=', VALUE    => "Comment" );
27     }
28
29     $attachments->Limit ( FIELD => 'ContentType', OPERATOR => '=', VALUE => 'text/plain');
30     $attachments->Limit ( FIELD => 'ContentType', OPERATOR => 'STARTSWITH', VALUE => 'message/');
31     $attachments->Limit ( FIELD => 'ContentType', OPERATOR => '=', VALUE => 'text');
32
33 }
34 return ($attachments);
35 </%INIT>
36 <%ARGS>
37 $Ticket => undef
38 </%ARGS>
39