[Rt-commit] r8665 - rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT
ruz at bestpractical.com
ruz at bestpractical.com
Tue Aug 21 08:54:21 EDT 2007
Author: ruz
Date: Tue Aug 21 08:54:17 2007
New Revision: 8665
Modified:
rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Test.pm
Log:
* add MemberOf argument to load_or_create_user
Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Test.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Test.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Test.pm Tue Aug 21 08:54:17 2007
@@ -176,6 +176,11 @@
sub load_or_create_user {
my $self = shift;
my %args = ( Privileged => 1, Disabled => 0, @_ );
+
+ my $MemberOf = delete $args{'MemberOf'};
+ $MemberOf = [ $MemberOf ] if defined $MemberOf && !ref $MemberOf;
+ $MemberOf ||= [];
+
my $obj = RT::User->new( $RT::SystemUser );
if ( $args{'Name'} ) {
$obj->LoadByCols( Name => $args{'Name'} );
@@ -195,6 +200,28 @@
die "$msg" unless $val;
}
+ # clean group membership
+ {
+ require RT::GroupMembers;
+ my $gms = RT::GroupMembers->new( $RT::SystemUser );
+ my $groups_alias = $gms->Join(
+ FIELD1 => 'GroupId', TABLE2 => 'Groups', FIELD2 => 'id',
+ );
+ $gms->Limit( ALIAS => $groups_alias, FIELD => 'Domain', VALUE => 'UserDefined' );
+ $gms->Limit( FIELD => 'MemberId', VALUE => $obj->id );
+ while ( my $group_member_record = $gms->Next ) {
+ $group_member_record->Delete;
+ }
+ }
+
+ # add new user to groups
+ foreach ( @$MemberOf ) {
+ my $group = RT::Group->new( RT::SystemUser() );
+ $group->LoadUserDefinedGroup( $_ );
+ die "couldn't load group '$_'" unless $group->id;
+ $group->AddMember( $obj->id );
+ }
+
return $obj;
}
More information about the Rt-commit
mailing list