[rt-users] Finding the current user for a reply (scrips)

Howard Jones howie at thingy.com
Thu Oct 8 12:12:13 EDT 2009


I'm trying to write a scrip to set a ticket's status based on who
replies to it - if it's staff, set it to stalled, if it's not, set to open.

I currently have an OnCorrespond condition, and a custom Action, but I'm
not seeing the user I expect from the Transaction object.

$RT::Logger->warning("Welcome to Scrip 13");

# get actor ID
my $trans = $self->TransactionObj;
my $Ticket = $trans->TicketObj;
my $Actor = $self->CurrentUser();

$RT::Logger->warning(ref($Ticket)." ".ref($Actor));

# if actor is RT_SystemUser then get out of here
return 1 if $Actor == $RT::SystemUser->id;

$RT::Logger->warning("Actor is ".$Actor->Name);

my $staff = 0;

my $GroupObj = RT::Group->new($Actor);
$GroupObj->LoadUserDefinedGroup( 'RTUsers' );

my $PrincipalObj = RT::Principal->new($Actor);
$PrincipalObj->Load($Actor->id);

$RT::Logger->warning("groupname: ".$GroupObj->Name); #Remove them from
production
$RT::Logger->warning("principaltype: ".$PrincipalObj->PrincipalType);

if ($GroupObj->HasMemberRecursively($PrincipalObj)) {
   $staff = 1;
   $self->TicketObj->SetStatus('stalled');
   $RT::Logger->warning("Staff");
}
else
{
   $RT::Logger->warning("Non-staff");
}

return 1;

and the log output is:
Oct  8 16:49:31 rt RT: Welcome to Scrip 13 ((eval 759):1)
Oct  8 16:49:31 rt RT: RT::Ticket RT::CurrentUser ((eval 759):9)
Oct  8 16:49:31 rt RT: Actor is RT_System ((eval 759):14)
Oct  8 16:49:31 rt RT: groupname: RTUsers ((eval 759):26)
Oct  8 16:49:31 rt RT: principaltype: User ((eval 759):27)
Oct  8 16:49:31 rt RT: Non-staff ((eval 759):36)

even though I am triggering this by replying to a ticket logged in as a
normal user (in the RTUsers group) from the web UI. Why is it 'RT_System'?

Can someone please point me in the right direction? I think I'm probably
missing something fundamental...

Thanks,

Howie



More information about the rt-users mailing list