summaryrefslogtreecommitdiff
path: root/rt/html/Ticket/Elements/LoadTextAttachments
blob: 084502e4cbe0e699361fdad81c4e176a2d86db29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<%INIT>

my $attachments = RT::Attachments->new( $session{'CurrentUser'} );

$attachments->Columns( qw(id Content ContentType TransactionId ContentEncoding));

if ( $Ticket->CurrentUserHasRight('ShowTicket') ) {
    my $transactions = $attachments->NewAlias('Transactions');
    $attachments->Join( ALIAS1 => 'main',
                                           FIELD1 => 'TransactionId',
                                           ALIAS2 => $transactions,
                                           FIELD2 => 'id' );
    
    my $tickets = $attachments->NewAlias('Tickets');

    $attachments->Join( ALIAS1 => $transactions,
                        FIELD1 => 'Ticket',
                        ALIAS2 => $tickets,
                        FIELD2 => 'id' );

    $attachments->Limit( ALIAS => $tickets,
                         FIELD => 'EffectiveId',
                         VALUE => $Ticket->id() );
    # if the user may not see comments do not return them
    unless ( $Ticket->CurrentUserHasRight('ShowTicketComments') ) {
        $attachments->Limit( ALIAS    => $transactions, FIELD    => 'Type', OPERATOR => '!=', VALUE    => "Comment" );
    }

    $attachments->Limit ( FIELD => 'ContentType', OPERATOR => '=', VALUE => 'text/plain');
    $attachments->Limit ( FIELD => 'ContentType', OPERATOR => 'STARTSWITH', VALUE => 'message/');
    $attachments->Limit ( FIELD => 'ContentType', OPERATOR => '=', VALUE => 'text');

}
return ($attachments);
</%INIT>
<%ARGS>
$Ticket => undef
</%ARGS>