[rt-devel] New Contrib Action for the Steal

Jan Okrouhly okrouhly at civ.zcu.cz
Mon Dec 3 14:36:00 EST 2001


I utilized existing contrib condition OwnerChange (I suggest to move
it into rt-addons/Conditions) not for only notifing on 'Give', but also
on 'Steal'. There wasn't any action for old owner notifycation so
I've done the one (see the attachment).

Example scrips:
          OnOwnerChange NotifyOwnerAsComment with template Give
          OnOwnerChange NotifyOldOwner with template Steal

Example Templates:
Request #{$Ticket->id} has been given to you on
{$Transaction->CreatedAsString} by {$Transaction->CreatorObj->RealName}.

Ticket <URL: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id} >
Request #{$Ticket->id} has been stollen from you on
{$Transaction->CreatedAsString} by {$Transaction->CreatorObj->RealName}.

Ticket <URL: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id} >

I am sure it is not briliant code but I could be a good kick-off for other
contrib rt-users.


Jan Okrouhly
---------------------------------------\-\-\+\-\-\---okrouhly at civ.zcu.cz---
Laboratory for Computer Science             |    phone: (420 19) 7491588
University of West Bohemia                  | location: Univerzitni 22
Americka 42, 306 14 Pilsen, Czech Republic  |     room: UI404
------------------------------------------73!-de-OK1INC at OK0PPL.#BOH.CZE.EU-
-------------- next part --------------

package RT::Action::NotifyOldOwner;
require RT::Action::Notify;
@ISA = qw(RT::Action::Notify);

sub SetRecipients {
    my $self=shift;


    $arg =~ s/\bAll\b/OldOwner/;

    my (@To);

    if ($arg =~ /\bOldOwner\b/) {
        if ($self->TransactionObj->OldValue != $RT::Nobody->Id) {
        my $OldOwner=new RT::User($RT::SystemUser);

        push(@To, $OldOwner->EmailAddress);

        $self->SUPER::SetRecipients ();

        my $creator = $self->TransactionObj->CreatorObj->EmailAddress();
        # override possible 'To'
        @{$self->{'To'}} = grep (!/^$creator$/, @To);

return (1);

sub SetReturnAddress {
	my $self = shift;
	# Tell RT::Action::SendEmail that this should come 
	# from the relevant comment email address.
	$self->{'comment'} = 1;
	return($self->SUPER::SetReturnAddress(is_comment => 1));

# {{{ sub IsApplicable
sub IsApplicable  {
  my $self = shift;

  return (1) if ($self->TransactionObj->Field eq 'Owner');
  return (undef);
# }}}


-------------- next part --------------
#!/usr/bin/perl -w

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

use lib "/opt/rt/lib";
use lib "/opt/rt/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


# {{{ ScripActions

my @ScripActions = (
			Name => 'NotifyOldOwner',
			Description =>  'Sends a message to the old owner of stollen ticket',
			ExecModule => 'NotifyOldOwner',
			Argument =>  'OldOwner',

# }}}
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";



More information about the Rt-devel mailing list