Batch user add to group

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi there,
I was wondering if there’s any command line utility or API call that I
can use to add users to a group in bulk, in RT4.

I have something like
user1@domain
user2@domain
user3@domain
user4@domain

they are already on the system, but unprivileged.

I want to make them privileged and add to a group.

Has anyone done this before?

Thanks,
G


Giuseppe Sollazzo
Senior Systems Analyst
Computing Services
Information Services
St. George’s, University Of London
Cranmer Terrace
London SW17 0RE

Email: gsollazz@sgul.ac.uk
Direct Dial: +44 20 8725 5160
Fax: +44 20 8725 3583

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJQK4QVAAoJEAqigArPBfJX1T4H/2pJliIKQqrTFaIQHNBPCyuF
oPTTbLAtv3l2xur0/f7/ev8SQmwDgvjfzZ1K+Tqm3uEzR/s7U8M6luik+2UTZ3EE
QB9RHJ0KnObqUr80LVsvesuDkCXNTcSPZ5pcjs/PqSk9QPiGqo2p/NR2iM1tutq7
BaWrUPowWzD+RmXL+4tR3OFLJunM+jSgXia9XdcKd1KpuKP0hoqlVPWg1X5E/Jnv
EGvCfF5uIP4mzFstWGaaKrI9et5aLDUmBC+21VNjJbMbGbNnf0daxwT3KWq/aJUF
HZcnX3mvagAKoaZ3Ia6RALXL7u9hNkA/sCLI8d0yvojylecKUVZt5lyWo6kJ2Bg=
=I5rd
-----END PGP SIGNATURE-----

Hi there,
I was wondering if there’s any command line utility or API call that I
can use to add users to a group in bulk, in RT4.

I have something like
user1@domain
user2@domain
user3@domain
user4@domain

they are already on the system, but unprivileged.

I want to make them privileged and add to a group.

There is no existing command line utility, but it’s mostly a matter of
a small perl script to load the user, calling SetPrivileged on it and
then calling AddMember on the relevant group object.

-kevin

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thanks Kevin,
I’m having a go with the RT Perl library.

Best regards,
GiuseppeOn 20/08/12 15:44, Kevin Falcone wrote:

On Wed, Aug 15, 2012 at 12:12:21PM +0100, Giuseppe Sollazzo wrote:

Hi there,
I was wondering if there’s any command line utility or API call that I
can use to add users to a group in bulk, in RT4.

I have something like
user1@domain
user2@domain
user3@domain
user4@domain

they are already on the system, but unprivileged.

I want to make them privileged and add to a group.

There is no existing command line utility, but it’s mostly a matter of
a small perl script to load the user, calling SetPrivileged on it and
then calling AddMember on the relevant group object.

-kevin


Giuseppe Sollazzo
Senior Systems Analyst
Computing Services
Information Services
St. George’s, University Of London
Cranmer Terrace
London SW17 0RE

Email: gsollazz@sgul.ac.uk
Direct Dial: +44 20 8725 5160
Fax: +44 20 8725 3583

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJQNKuBAAoJEAqigArPBfJXJyMH/j/cZic1KA+GffHaC7q0DXYA
bj2de9JpgLI3f4W+Rtk7voWwlPeiS3F2Y9ABsK4loyGBdJg9uq5JdfNfhlmlTboM
aqN1H4GCTBvLfNY0KVrolsB73hJKNAfBSlTl/ndjNapiNFG1aANAJQprNM39UBbQ
SAWwg3ghliXG1USGdhZiSEaAvUW6C2A1IoEni3o7VI5e2rR/MYYax9n+TD9n0wGN
XQvVx8tMR8W1EkqtPYVbvCtnDbb7pIyRk7UG5EDFqEL5eiar0/jp3NDAkstNrAnb
Q6+sM0otVLnYvCfbxthSJmXGA0B5h9pzLxUooTw8eZZcNuwc+oHNM/l7NtAhsw8=
=wZ8L
-----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1On 20/08/12 15:44, Kevin Falcone wrote:

On Wed, Aug 15, 2012 at 12:12:21PM +0100, Giuseppe Sollazzo wrote:

There is no existing command line utility, but it’s mostly a matter of
a small perl script to load the user, calling SetPrivileged on it and
then calling AddMember on the relevant group object.

-kevin

Hi Kevin,
I can’t find much docs about the use of RT::User especially on RT4. Any
link, if you have it handy?

What I’m trying to do is something like what follows (edit of scripts
found on the wiki):

#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
BEGIN { die “You must define $RT_HOME\n”
unless exists $ENV{RT_HOME} };
use lib “$ENV{RT_HOME}/lib”;

use RT;

RT::LoadConfig();
RT::Init();

use RT::Interface::CLI qw(GetCurrentUser loc);
use RT::Tickets;

die “We need exactly 2 Arguments, Name & Email\n” unless ($#ARGV==1);

my $UserName=shift @ARGV;
my $Email=shift @ARGV;

my $User = RT::User->new($Email);
#my
($id,$Message)=$User->Create(Name=>$UserName,EmailAddress=>$Email,Privileged=>1,Password=>‘apassword’);*
#if ($id){

print $Message.“\n”;

}

#else{

print"This is a error!\n$Message\n";

#}

Except I don’t want to create a user, I want to load a user from the RT
user database. Is that possible? I’ve been searching for a couple of
days now without much success…

Thanks,
G


Giuseppe Sollazzo
Senior Systems Analyst
Computing Services
Information Services
St. George’s, University Of London
Cranmer Terrace
London SW17 0RE

Email: gsollazz@sgul.ac.uk
Direct Dial: +44 20 8725 5160
Fax: +44 20 8725 3583

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJQNhy5AAoJEAqigArPBfJXRDkH/i9YBY2XHDHqB8hZIP/hZXdD
jx+oqJfoxQa2+QtgbZu+24SZ8XPhqcFmAIhxMaJFrSGrMVD34V0JE1IHWq8mCq1v
XFpj19QHwW2vxAQu5DB6CYX2+DuyYDCJ8/RgAnPmT/ZB7y8mNldmpp8IDAxznPZW
+AtxcJFNAhZDsp+vC6/XJdnQwh67c9tzHGI1tpT66soIsu4RppGNiH9GHMmlaGid
xZnNPlDU6HH6516bWMFC2/+CeZPjEEjqJiNwAXguigzGf3l/67GfTCarAOgVfcAR
JO+oOnFIBOvXaLNPLdDoUeJpVm8KOYauydY+IXxhq2Ay80a2VSiEuA8stP9R+5c=
=R4tq
-----END PGP SIGNATURE-----

Giuseppe,

my $User = RT::User->new($Email);
*
#my
($id,$Message)=$User->Create(Name=>$UserName,EmailAddress=>$Email,Privileged
=>1,Password=>‘apassword’);*
[…]
Except I don’t want to create a user, I want to load a user from the RT
user database. Is that possible? I’ve been >searching for a couple of days
now without much success…

You should rather do:

my $User = RT::User->new($RT::SystemUser);
$User->LoadByEmail($Email);

printf “%s %s %s\n”, $User->Name, $User->EmailAddress, $User->RealName;

Best regards,
Maciek

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Maciek,
thanks - I’ve actually just found a quick solution that is not too
different from yours.

I’m posting it to St George's, University of London · GitHub but in the meantime I’ll add it
here in case anyone needs it:

#!/usr/bin/perl

Usage: ./rt_set_privileged_and_add_to_group.pl

use strict;
use lib “/opt/rt4/lib”;
use RT;
use RT::User;
use RT::Interface::CLI;

RT::LoadConfig();
RT::Init();

Create RT User Object

my $user = new RT::User($RT::SystemUser);

Instantiate the user object with the user passed as parameter

my $usertoadd = $ARGV[0];
$user->Load( $usertoadd );

Set the privileged flag (1=privileged, 0=unprivileged)

$user->SetPrivileged(1);

Get group object and instantiate it with the group name

my $group = new RT::Group($RT::SystemUser);
my $inputgroup = $ARGV[1];
$group->LoadUserDefinedGroup( $inputgroup );

Add user to group

$group->AddMember( $user->PrincipalObj->Id );

exit 1

Thanks,
GiuseppeOn 23/08/12 15:44, reg.bestpractical@posterus.com wrote:

Giuseppe,

my $User = RT::User->new($Email);
*
#my
($id,$Message)=$User->Create(Name=>$UserName,EmailAddress=>$Email,Privileged
=>1,Password=>‘apassword’);*
[…]
Except I don’t want to create a user, I want to load a user from the RT
user database. Is that possible? I’ve been >searching for a couple of days
now without much success…

You should rather do:

my $User = RT::User->new($RT::SystemUser);
$User->LoadByEmail($Email);

printf “%s %s %s\n”, $User->Name, $User->EmailAddress, $User->RealName;

Best regards,
Maciek


Giuseppe Sollazzo
Senior Systems Analyst
Computing Services
Information Services
St. George’s, University Of London
Cranmer Terrace
London SW17 0RE

Email: gsollazz@sgul.ac.uk
Direct Dial: +44 20 8725 5160
Fax: +44 20 8725 3583

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJQNkOvAAoJEAqigArPBfJXIi0H/A20CUWQdGE06rndPgelyuRa
XqryNeC15fQzRLFPTmEpf6LchiFOHSqSmEXfSxw4OXbsS7NzrJ3aPT506tINzDJR
KrZexz8HzpeLEZN44seFF3ONJBqHQD+BFZhGU4qcMVsbJiqKSUVgcgGrF41p/Jg3
GukA5tib4VjZDuX3K/LTpoZi8buy/0FJqgdVDq1z5gBJ5B4y0MIYgJL8NLVY/xkf
Zj0Hh2ffnnx2XQmf1z6jBJLA6Uen+TWQj6iWmLRVfnWUI82EPmgSHiN+QICgLGsH
GfAWJpBJVtw6NT3LrGfLJKNrQG8d6eYiZ3Q0btzKBxBSUnNC5gi3LMVIbbYrQkY=
=ZfSQ
-----END PGP SIGNATURE-----