%# Senate, n.: %# A body of elderly gentlemen charged with high duties and misdemeanors. %# -- Ambrose Bierce
<%INIT> if ($ApprovalId) { my $Approval = LoadTicket($ApprovalId); my $Ticket = $Approval->OriginObj; foreach my $key (keys %ARGS) { $key =~ /^AddMoreEntry-(.*)$/ or next; $ARGS{'AddMoreEntry'} = [ split(/-/, $1) ]; } my $Entries = $m->comp('/Work/Tickets/Elements/ProcessEntryUpdates', TicketObj => $Ticket, %ARGS); $ARGS{"Ticket-".$Ticket->Id."-CustomField-$_-Values"} = $Entries->{$_} foreach keys %{$Entries}; ProcessTicketCustomFieldUpdates( ARGSRef => \%ARGS ); if ($ARGS{'AddMoreEntry'}) { return $m->comp('Display.html', %ARGS); } } foreach my $key (reverse sort keys %ARGS) { $key =~ /^Approval-(\d+)-(Action|Content)$/ or next; my ($id, $mode) = ($1, $2); my $Approval = LoadTicket($id); if ( $mode eq 'Content' ) { $ARGS{$key} =~ /\S/ or next; my $method = ($ARGS{"Approval-$id-Action"} eq 'None') ? 'Correspond' : 'Comment'; my $notes = MIME::Entity->build( Data => [ $ARGS{$key} ] ); RT::I18N::SetMIMEEntityToUTF8($notes); # convert text parts into utf-8 $Approval->$method( MIMEObj => $notes, _reopen => 0, _open => 0 ); if ($RT::OIN104 and $method eq 'Correspond') { # XXX - for some reason jimmy wants to attach it to the parent my $Ticket = $Approval->OriginObj; local *RT::Scrips::Apply = sub { return 1 }; my $notes = MIME::Entity->build( Data => [ loc("Approver's notes: [_1]", $ARGS{$key}) ] ); $Ticket->Correspond( MIMEObj => $notes, _reopen => 0, _open => 0 ); } next; } # Okay, here is the Action part. my $Action = $ARGS{$key}; if ( $Action eq 'Deny' ) { $Approval->SetStatus('rejected'); } elsif ( $Action eq 'Approve' ) { if ( my $owner = $ARGS{"Approval-$id-Owner"} ) { my $Transfer = RT::Ticket->new($RT::SystemUser); $Transfer->Create( Type => 'approval', Owner => $owner, Subject => loc("Transferred Approval"), Queue => $Approval->Queue, ); $Transfer->SetOriginObj( $Approval->OriginObj ); my $links = $Approval->DependedOnBy->ItemsArrayRef; foreach my $link (@$links) { my $child = $link->BaseObj or next; $Transfer->AddLink( Type => 'DependsOn', Base => $child->Id, Silent => 1, ); $link->Delete; } $Approval->AddLink( Type => 'DependsOn', Base => $Transfer->Id, Silent => 1, ); $Approval->SetStatus('resolved'); delete $session{"Approval-$id-Owner"}; next; } # XXX - eventually factor this out to RT::Ticket. my @proc = $Approval; while (my $TicketObj = shift(@proc)) { $TicketObj->SetStatus('resolved'); my $deps = RT::Tickets->new($session{'CurrentUser'}); $deps->LimitStatus(VALUE => 'open'); $deps->LimitStatus(VALUE => 'stalled'); $deps->LimitType(VALUE => 'approval'); $deps->LimitDependsOn($TicketObj->Id); $deps->LimitOwner(VALUE => $session{'CurrentUser'}->UserObj->Id); push @proc, @{ $deps->ItemsArrayRef || [] }; } } } <%ARGS> $ApprovalId => undef