# AutoAssign.pm - Automatically assign a ticket to the current User if: # Ticket is owned by Nobody # User is privileged. # User can own tickets in this queue. # Bruce Campbell, RIPE NCC. package RT::Action::AutoAssign; require RT::Action::Generic; @ISA = qw(RT::Action::Generic); # We override the Prepare routine and return (0) if the condition is met. sub Prepare { my $self = shift; # We're only Prepare()d if we don't have a Name. my $retval = undef; if ( defined( $self->TicketObj->OwnerObj->id ) ){ if( $self->TicketObj->OwnerObj->Id == $RT::Nobody->Id ){ # Nobody $retval = 1; } }else{ # undefined - must be nobody. $retval = 1; } return( $retval ); } sub Commit { my $self = shift; my $retval = undef; # Are they one of the Privileged few? if ($self->TransactionObj->CreatorObj->Privileged && $self->TransactionObj->CreatorObj->Id != $RT::Nobody->Id ) { # Can they own a ticket in this queue? if( $self->TransactionObj->CreatorObj->HasQueueRight( QueueObj => $self->TicketObj->QueueObj, Right => 'OwnTicket' ) ){ # They can own the ticket. Make it so. $retval = $self->TicketObj->SetOwner( $self->TransactionObj->CreatorObj->Id ); } } return( $retval ); } 1;