[rt-users] Finding the current user for a reply (scrips)
Kevin Falcone
falcone at bestpractical.com
Thu Oct 8 12:24:08 EDT 2009
On Thu, Oct 08, 2009 at 05:12:13PM +0100, Howard Jones wrote:
> 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();
Try using $trans->Creator or $trans->CreatorObj
Scrips run in a system context, but the creator of the transaction
will be the user who triggered it.
-kevin
> $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
> _______________________________________________
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>
> Community help: http://wiki.bestpractical.com
> Commercial support: sales at bestpractical.com
>
>
> Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
> Buy a copy at http://rtbook.bestpractical.com
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20091008/69c3ae37/attachment.sig>
More information about the rt-users
mailing list