%args> $id => undef %args> <%init> my $Ticket; my @Actions; unless ($id) { Abort('No ticket specified'); } if ($ARGS{'id'} eq 'new') { # {{{ Create a new ticket my $Queue = new RT::Queue( $session{'CurrentUser'} ); $Queue->Load($ARGS{'Queue'}); unless ( $Queue->id ) { Abort('Queue not found'); } unless ( $Queue->CurrentUserHasRight('CreateTicket') ) { Abort('You have no permission to create tickets in that queue.'); } ($Ticket, @Actions) = CreateTicket( Attachments => delete $session{'Attachments'}, %ARGS, ); unless ( $Ticket->CurrentUserHasRight('ShowTicket') ) { Abort("No permission to view newly created ticket #".$Ticket->id."."); } # }}} } else { $Ticket ||= LoadTicket($ARGS{'id'}); $m->callback( CallbackName => 'BeforeProcessArguments', TicketObj => $Ticket, ActionsRef => \@Actions, ARGSRef => \%ARGS ); if ( defined $ARGS{'Action'} ) { if ($ARGS{'Action'} =~ /^(Steal|Kill|Take|SetTold)$/) { my $action = $1; my ($res, $msg) = $Ticket->$action(); push(@Actions, $msg); } } $m->callback(CallbackName => 'ProcessArguments', Ticket => $Ticket, ARGSRef => \%ARGS, Actions => \@Actions); $ARGS{UpdateAttachments} = $session{'Attachments'}; push @Actions, ProcessUpdateMessage( ARGSRef => \%ARGS, Actions => \@Actions, TicketObj => $Ticket, ); delete $session{'Attachments'}; #Process status updates push @Actions, ProcessTicketWatchers(ARGSRef => \%ARGS, TicketObj => $Ticket ); push @Actions, ProcessTicketBasics( ARGSRef => \%ARGS, TicketObj => $Ticket ); push @Actions, ProcessTicketLinks( ARGSRef => \%ARGS, TicketObj => $Ticket ); push @Actions, ProcessTicketDates( ARGSRef => \%ARGS, TicketObj => $Ticket ); push @Actions, ProcessObjectCustomFieldUpdates(ARGSRef => \%ARGS, TicketObj => $Ticket ); # XXX: we shouldn't block actions here if user has no right to see the ticket, # but we should allow him to see actions he has done unless ($Ticket->CurrentUserHasRight('ShowTicket')) { Abort("No permission to view ticket"); } if ( $ARGS{'MarkAsSeen'} ) { $Ticket->SetAttribute( Name => 'User-'. $Ticket->CurrentUser->id .'-SeenUpTo', Content => $Ticket->LastUpdated, ); push @Actions, loc('Marked all messages as seen'); } } $m->callback( CallbackName => 'BeforeDisplay', TicketObj => \$Ticket, Actions => \@Actions, ARGSRef => \%ARGS, ); # This code does automatic redirection if any updates happen. if (@Actions) { # We've done something, so we need to clear the decks to avoid # resubmission on refresh. # But we need to store Actions somewhere too, so we don't lose them. my $key = Digest::MD5::md5_hex( rand(1024) ); push @{ $session{"Actions"}->{$key} ||= [] }, @Actions; $session{'i'}++; my $url = RT->Config->Get('WebURL') . "m/ticket/show?id=" . $Ticket->id . "&results=" . $key; $url .= '#' . $ARGS{Anchor} if $ARGS{Anchor}; RT::Interface::Web::Redirect($url); } # If we haven't been passed in an Attachments object (through the precaching mechanism) # then we need to find one my $Attachments = $m->comp('/Ticket/Elements/FindAttachments', Ticket => $Ticket); my %documents; while ( my $attach = $Attachments->Next() ) { next unless ($attach->Filename()); unshift( @{ $documents{ $attach->Filename } }, $attach ); } my $Customers = $Ticket->Customers; my @customers; while ( my $customer = $Customers->Next() ) { push @customers, $customer; } my $CustomFields = $Ticket->CustomFields; $m->callback( CallbackName => 'MassageCustomFields', Object => $Ticket, CustomFields => $CustomFields, ); my $print_value = sub { my ($cf, $value) = @_; my $linked = $value->LinkValueTo; if ( defined $linked && length $linked ) { my $linked = $m->interp->apply_escapes( $linked, 'h' ); $m->out(''); } my $comp = "ShowCustomField". $cf->Type; $m->callback( CallbackName => 'ShowComponentName', Name => \$comp, CustomField => $cf, Object => $Ticket, ); if ( $m->comp_exists( $comp ) ) { $m->comp( $comp, Object => $value ); } else { $m->out( $m->interp->apply_escapes( $value->Content, 'h' ) ); } $m->out('') if defined $linked && length $linked; # This section automatically populates a