[rt-devel] Contrib: OnOwnerChangeGroup (RT 2.0.x)

Bruce Campbell bruce_campbell at ripe.net
Sun May 26 15:33:44 EDT 2002

The attached RT::Condition and _example_ insert script will fire under the
following conditions:

	If the Owner is being changed
	The new Owner is a member of the group mentioned in the Argument.

This is used in conjunction with the previous SetKeyword RT::ScripAction,
in the following manner:

	OnOwnerChangeToGroupName SetKeyword with template Keyword_Group

It is assumed that one has already set up various groups of people (for
instance, in a tiered helpdesk system, the different levels ).  The
Argument for the ScripCondition is simply the name of one of these groups,
and is passed to RT::Group->Load() .

Refer to my previous mail for SetKeyword template specifics.

                             Bruce Campbell                            RIPE
                   Systems/Network Engineer                             NCC
                 www.ripe.net - PGP562C8B1B                      Operations

-------------- next part --------------
#!/usr/bin/perl -w
# $Header: /raid/cvsroot/rt-addons/ScripConditions/OnOwnerChange/insert_condition.pl,v 1.1 2001/06/17 19:18:36 jesse Exp $
# RT is (c) 1996-2000 Jesse Vincent (jesse at fsck.com);
# OnOwnerChange Condition by Bas Toonk (B.Toonk at zx.nl);
# This a a copy form the OnQueueChange script!

package RT;
use strict;
use vars qw($VERSION $Handle $Nobody $SystemUser $item);

use lib "/home/rt2/lib";
use lib "/home/rt2/etc";

#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);

#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

#Load etc/config.pm and drop privs

#Connect to the database and get RT::SystemUser and RT::Nobody loaded


# {{{ ScripConditions

my @ScripConditions = (
			Name => 'OnOwnerChangeToCHANGEME',
			Description =>  'When a ticket is moved to a group named CHANGEME',
			ApplicableTransTypes =>  'Any',
			ExecModule => 'OwnerChangeGroup',
			Argument => 'CHANGEME',

# }}}
print "Creating ScripConditions...";

use RT::ScripCondition;
for $item (@ScripConditions) {
    my $new_entry = new RT::ScripCondition($CurrentUser);
    my $return = $new_entry->Create(%$item);
    print $return.".";

print "done.\n";



-------------- next part --------------
# $Header: /home/rt2/etc/site_scrips/Condition/RCS/OwnerChangeGroup.pm,v 1.2 2002/05/26 19:22:03 bc Exp $
# OnOwnerChangeGroup - fires if we're changing the Owner, and the new Owner
# is a member of a particular group given in the Argument.

package RT::Condition::OwnerChangeGroup;
require RT::Condition::Generic;

use RT::Groups;

@ISA = qw(RT::Condition::Generic);

=head2 IsApplicable

If the queue is being changed, and the new owner is a member of the group
mentioned in the Argument, return true.


sub IsApplicable {
    my $self = shift;
    my $retval = undef;

    # Is this an OwnerChange, and do we have an Argument?
    if ($self->TransactionObj->Field eq 'Owner' && defined( $self->Argument ) )  {

	# Now to see if the new owner is a member of the group mentioned
	# in the Argument.  
	# my $self->TicketObj->Owner
	my $Group = RT::Group->new( $RT::SystemUser );
	$Group->Load( $self->Argument );

	if( $Group->Name eq $self->Argument ){

		# Right, is the current Owner a member of this group?
		while( my $groupmember = $Group->MembersObj->Next ){
			# Do the ids match?
			if( $groupmember->UserObj->id == $self->TicketObj->OwnerObj->id ){
				$RT::Logger->debug("$self: New owner is within indicated group " . $self->Argument . "\n");
    return( $retval );


More information about the Rt-devel mailing list