Searching user custom field in RT 4.4.x

Found a little gotcha (and a fix!):

When creating new users via LDAP we were getting failures logged. Looking into it, it appears that the RT::User Create() method doesn’t understand about ‘UserCF.*’ fields from the RT_SiteConfig.pm which rt-ldapimport passes into it. Thus updating users that already existed in RT worked fine, but new users wouldn’t be created. A quick fix is to pop this patch into the Create() method of RT::User:

# diff -c /opt/rt4/lib/RT/User.pm /opt/rt4/local/lib/RT/User.pm 
*** /opt/rt4/lib/RT/User.pm	2019-03-18 10:38:50.277276621 +0000
--- /opt/rt4/local/lib/RT/User.pm	2020-02-12 10:29:55.512468977 +0000
***************
*** 185,190 ****
--- 185,195 ----
  
      delete $args{'Disabled'};
  
+     foreach my  $thisArg (keys %args) {
+         next if($thisArg !~ /^UserCF\./);
+         delete $args{$thisArg};
+     }
+ 
      $self->SUPER::Create(id => $principal_id , %args);
      my $id = $self->Id;

What this does is remove all UserCF.* arguments being passed into create before it calls the SUPER::Create() method. This allows the user object to be created successfully, and rt-ldapimport then updates the custom fields correctly. Phew!

1 Like