[rt-users] RES: Is it possible to specify a different user with RT CLI ?

Jean-Christophe Boggio rt-users at thefreecat.org
Tue Jun 11 05:24:54 EDT 2013


Ok, I did it and it seems to work like I want it to. There are still 
things that I don't understand but they might be related to my lack of 
Perl knowledge, for example : why can't I find the declaration for 
RT::User->new or RT::Ticket->new ?


For the record I did this :

use lib qw(/usr/share/request-tracker4/lib);

use RT;
use RT::Ticket;
use RT::User;

RT->LoadConfig();
RT->Init();

# 140 is my test user (the one I'm impersonating)
my $User = RT::User->new();
$User->Load(140);
die "User 140 not found" unless $User->id;

# As I understand it, RT's $TicketObj->new expects a RT::User parameter
# which will be the "CurrentUser"
# This user must have rights to comment/correspond in the ticket's queue
# Our system does not use queues to determine who can write/comment/...
# It is rather based on (recursive) assets (organization/Administrative
# entity/Site) so I take care of the ACL by myself.
# I chose to give all permissions to all users in RT's queues.
# I probably could have rather used :
#   $RT::Handle->BeginTransaction();
#   $Ticket->_RecordNote(%args);
#   $RT::Handle->Commit();

# 3 is my test ticket

my $Ticket = RT::Ticket->new( $User );
$Ticket->Load(3);
die "Ticket 3 not found" unless $Ticket->id;

$Ticket->Comment(
	Content => "This is a test"
);



As a side note, the RT->Init() is very long, mainly because of 
RT::I18N->Init()

Since I don't need internationalization, I copied what RT::Init does and 
commented out the I18N part :

	RT::CheckPerlRequirements();
	RT::InitPluginPaths();
	RT::ConnectToDatabase();
	RT::InitSystemObjects();
	RT::InitClasses();
	RT::InitLogging();
	RT::InitPlugins();
#	RT::I18N->Init;
	RT->Config->PostLoadCheck;

Hope this helps. I'd be glad to create a wiki page describing this but 
I'm not too confident in my understanding of how RT core works. However, 
if someone validates it, I'll do it.

Thanks again to those who helped.




More information about the rt-users mailing list