[rt-users] Batch user add to group

Giuseppe Sollazzo gsollazz at sgul.ac.uk
Thu Aug 23 10:52:33 EDT 2012


-----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 http://github.com/sgul 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 <username> <group>


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,
Giuseppe




On 23/08/12 15:44, reg.bestpractical at 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 at 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-----




More information about the rt-users mailing list