[rt-devel] Contrib: AutoAssign (RT2.0.x)
Bruce Campbell
bruce_campbell at ripe.net
Mon Apr 15 10:03:43 EDT 2002
The attached RT::Action and insert script will automatically change the
ownership of a ticket if the following conditions are met:
Ticket is Owned by Nobody
User is Privileged
User can Own Tickets in the current Queue.
Effectively, the first User that can own a ticket who replies to the
Ticket, ends up Owning the ticket. (ie, if they have a public opinion on
a Problem, they then Own the Problem)
Recommended Scrip to apply would be:
OnCorrespondence AutoAssign with template Blank
Caveats - the WebUI puts in a SetOwner, meaning that you will see a quick
series of 'RT_System gives ticket to Joe', then 'Joe gives ticket to
Nobody', with the final Owner undefined, but predominately Nobody. The
current way of fixing this would be to patch
WebRT/html/Ticket/Elements/EditPeople to default to the current user if it
is currently Nobody. Ughity.
Regards,
--
Bruce Campbell RIPE
Systems/Network Engineer NCC
www.ripe.net - PGP562C8B1B Operations
-------------- next part --------------
# 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;
-------------- next part --------------
#!/usr/bin/perl -w
#
package RT;
use strict;
use vars qw($VERSION $Handle $Nobody $SystemUser $item);
use lib "!!CHANGE ME TO YOUR RT LIB DIRECTORY!!";
use lib "!!CHANGE ME TO YOUR RT ETC DIRECTORY!!";
#This drags in RT's config.pm
use config;
use Carp;
use RT::Handle;
use RT::User;
use RT::CurrentUser;
#connect to the db
$RT::Handle = new RT::Handle($RT::DatabaseType);
$RT::Handle->Connect();
#Put together a current user object so we can create a User object
my $CurrentUser = new RT::CurrentUser();
#now that we bootstrapped that little bit, we can use the standard RT cli
# helpers to do what we need
use RT::Interface::CLI qw(CleanEnv LoadConfig DBConnect
GetCurrentUser GetMessageContent);
#Clean out all the nasties from the environment
CleanEnv();
#Load etc/config.pm and drop privs
LoadConfig();
#Connect to the database and get RT::SystemUser and RT::Nobody loaded
DBConnect();
$CurrentUser->LoadByName('RT_System');
# {{{ ScripActions
my @ScripActions = (
{
Name => 'AutoAssign',
Description => 'Automatically assigns a ticket to a permitted user if they are the first reply',
ExecModule => 'AutoAssign',
Argument => '',
},
);
# }}}
print "Creating ScripActions...";
use RT::ScripAction;
for $item (@ScripActions) {
my $new_entry = new RT::ScripAction($CurrentUser);
my $return = $new_entry->Create(%$item);
print $return.".";
}
print "done.\n";
$RT::Handle->Disconnect();
1;
More information about the Rt-devel
mailing list