[Bps-public-commit] RT-Extension-LDAPImport branch, master, updated. 0.31_03-4-g8f8df1f

Alex Vandiver alexmv at bestpractical.com
Wed Dec 22 16:26:17 EST 2010


The branch, master has been updated
       via  8f8df1f433e7ae5b9f4ab7e89752adda186160ae (commit)
       via  38198f9e032deee1cfbbb1a803c07681095b1847 (commit)
       via  fe269f680a4af3de5d4bc5c83f057ea2db203e01 (commit)
       via  9b2d3ff88f7000af37059efa894ec8f1d51ba813 (commit)
      from  43af6887b838d042b99a04c1822e886c3486041f (commit)

Summary of changes:
 lib/RT/Extension/LDAPImport.pm |   31 +++++++++++++------------------
 1 files changed, 13 insertions(+), 18 deletions(-)

- Log -----------------------------------------------------------------
commit 9b2d3ff88f7000af37059efa894ec8f1d51ba813
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Dec 22 11:29:45 2010 -0500

    Fix a POD heading to match the function name

diff --git a/lib/RT/Extension/LDAPImport.pm b/lib/RT/Extension/LDAPImport.pm
index 33b61e9..cc12fdf 100644
--- a/lib/RT/Extension/LDAPImport.pm
+++ b/lib/RT/Extension/LDAPImport.pm
@@ -281,7 +281,7 @@ sub _build_object {
     return $object;
 }
 
-=head3 _parse_ldap_map
+=head3 _parse_ldap_mapping
 
 Internal helper function for import_user
 If we're passed an arrayref, it will recurse 

commit fe269f680a4af3de5d4bc5c83f057ea2db203e01
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Dec 22 11:40:07 2010 -0500

    Save some ->Load calls by storing the member objects themselves

diff --git a/lib/RT/Extension/LDAPImport.pm b/lib/RT/Extension/LDAPImport.pm
index cc12fdf..f9b3fed 100644
--- a/lib/RT/Extension/LDAPImport.pm
+++ b/lib/RT/Extension/LDAPImport.pm
@@ -696,7 +696,7 @@ sub add_group_members {
     if ($args{group}) {
         my $user_members = $group->UserMembersObj( Recursively => 0);
         while ( my $member = $user_members->Next ) {
-            $rt_group_members->{$member->Name}++;
+            $rt_group_members->{$member->Name} = $member;
         }
     } elsif (not $args{import}) {
         $self->_debug("No group in RT, would create with members:");
@@ -743,13 +743,7 @@ sub add_group_members {
         $self->_debug("\t$username\tin RT, not in LDAP, removing");
         next unless $args{import};
 
-        my $rt_user = RT::User->new($RT::SystemUser);
-        my ($res,$msg) = $rt_user->Load( $username );
-        unless ($res) {
-            $self->_warn("Unable to load $username: $msg");
-            next;
-        }
-        ($res,$msg) = $group->DeleteMember($rt_user->PrincipalObj->Id);
+        my ($res,$msg) = $group->DeleteMember($rt_group_members->{$username}->PrincipalObj->Id);
         unless ($res) {
             $self->_warn("Failed to remove $username to $groupname: $msg");
         }

commit 38198f9e032deee1cfbbb1a803c07681095b1847
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Dec 22 11:41:12 2010 -0500

    There's no reason for this to be a hashref, not a hash

diff --git a/lib/RT/Extension/LDAPImport.pm b/lib/RT/Extension/LDAPImport.pm
index f9b3fed..ed1749a 100644
--- a/lib/RT/Extension/LDAPImport.pm
+++ b/lib/RT/Extension/LDAPImport.pm
@@ -692,11 +692,11 @@ sub add_group_members {
         return;
     }
 
-    my $rt_group_members = {};
+    my %rt_group_members;
     if ($args{group}) {
         my $user_members = $group->UserMembersObj( Recursively => 0);
         while ( my $member = $user_members->Next ) {
-            $rt_group_members->{$member->Name} = $member;
+            $rt_group_members{$member->Name} = $member;
         }
     } elsif (not $args{import}) {
         $self->_debug("No group in RT, would create with members:");
@@ -720,7 +720,7 @@ sub add_group_members {
             my $ldap_user = $ldap_users->shift_entry;
             $dnlist->{lc $member} = $username = $ldap_user->get_value($RT::LDAPMapping->{Name});
         }
-        if ( delete $rt_group_members->{$username} ) {
+        if ( delete $rt_group_members{$username} ) {
             $self->_debug("\t$username\tin RT and LDAP");
             next;
         }
@@ -739,11 +739,11 @@ sub add_group_members {
         }
     }
 
-    for my $username (sort keys %$rt_group_members) {
+    for my $username (sort keys %rt_group_members) {
         $self->_debug("\t$username\tin RT, not in LDAP, removing");
         next unless $args{import};
 
-        my ($res,$msg) = $group->DeleteMember($rt_group_members->{$username}->PrincipalObj->Id);
+        my ($res,$msg) = $group->DeleteMember($rt_group_members{$username}->PrincipalObj->Id);
         unless ($res) {
             $self->_warn("Failed to remove $username to $groupname: $msg");
         }

commit 8f8df1f433e7ae5b9f4ab7e89752adda186160ae
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Dec 22 11:56:53 2010 -0500

    Add an optimization for adding new groups; if we just created it, we know it is empty, so skip the member query

diff --git a/lib/RT/Extension/LDAPImport.pm b/lib/RT/Extension/LDAPImport.pm
index ed1749a..8dc7de5 100644
--- a/lib/RT/Extension/LDAPImport.pm
+++ b/lib/RT/Extension/LDAPImport.pm
@@ -600,9 +600,9 @@ sub _import_group {
     my $ldap_entry = $args{ldap_entry};
 
     $self->_debug("Processing group $group->{Name}");
-    my $group_obj = $self->create_rt_group( %args, group => $group );
+    my ($group_obj, $created) = $self->create_rt_group( %args, group => $group );
     return if $args{import} and not $group_obj;
-    $self->add_group_members( %args, name => $group->{Name}, group => $group_obj, ldap_entry => $ldap_entry );
+    $self->add_group_members( %args, name => $group->{Name}, group => $group_obj, ldap_entry => $ldap_entry, new => $created );
     return;
 }
 
@@ -629,10 +629,10 @@ sub create_rt_group {
     my $group_obj = RT::Group->new($RT::SystemUser);
     $group_obj->LoadUserDefinedGroup( $group->{Name} );
 
+    my $created;
     if ($group_obj->Id) {
-        my $message = "Group $group->{Name} already exists as ".$group_obj->Id;
         if ($args{import}) {
-            $self->_debug("$message, updating their data");
+            $self->_debug("Group $group->{Name} already exists as ".$group_obj->Id.", updating their data");
             my @results = $group_obj->Update( ARGSRef => $group, AttributesRef => [keys %$group] );
             $self->_debug(join("\n", at results)||'no change');
         } else {
@@ -651,6 +651,7 @@ sub create_rt_group {
                 $self->_error("couldn't create group_obj for $group->{Name}: $msg");
                 return;
             }
+            $created = $val;
             $self->_debug("Created group for $group->{Name} with id ".$group_obj->Id);
         } else {
             print "Found new group $group->{Name} to create in RT\n";
@@ -662,7 +663,7 @@ sub create_rt_group {
     unless ($group_obj->Id) {
         $self->_error("We couldn't find or create $group->{Name}. This should never happen");
     }
-    return $group_obj;
+    return ($group_obj, $created);
 
 }
 
@@ -693,7 +694,7 @@ sub add_group_members {
     }
 
     my %rt_group_members;
-    if ($args{group}) {
+    if ($args{group} and not $args{new}) {
         my $user_members = $group->UserMembersObj( Recursively => 0);
         while ( my $member = $user_members->Next ) {
             $rt_group_members{$member->Name} = $member;

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list