whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [whimsy] branch master updated: Allow for dropping givenName
Date Sat, 19 Jun 2021 21:44:43 GMT
This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 7bb7aaf  Allow for dropping givenName
7bb7aaf is described below

commit 7bb7aafb59a69fd0cc05c8bf9c3ca91dae47bcda
Author: Sebb <sebb@apache.org>
AuthorDate: Sat Jun 19 22:44:35 2021 +0100

    Allow for dropping givenName
---
 lib/whimsy/asf/ldap.rb | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/lib/whimsy/asf/ldap.rb b/lib/whimsy/asf/ldap.rb
index 3432061..88887c5 100644
--- a/lib/whimsy/asf/ldap.rb
+++ b/lib/whimsy/asf/ldap.rb
@@ -899,12 +899,23 @@ module ASF
       end
     end
 
+    # is argument an empty string on its own or in a singleton array?
+    def arg_empty?(arg)
+      return arg.empty? || (arg.is_a?(Array) && arg.size == 1 && arg.first.empty?)
+    end
+
     # update an LDAP attribute for this person.  This needs to be run
     # either inside or after ASF::LDAP.bind.
     def modify(attr, value)
-      ASF::LDAP.modify(self.dn, [ASF::Base.mod_replace(attr.to_s, value)])
-      # attributes are expected to be arrays
-      attrs[attr.to_s] = value.is_a?(String) ? [value] : value
+      # OK to remove the attribute? Only support givenName for now...
+      if attr == 'givenName' and arg_empty?(value)
+        ASF::LDAP.modify(self.dn, [ASF::Base.mod_delete(attr.to_s, nil)])
+        attrs.delete(attr.to_s) # remove the cached entry
+      else
+        ASF::LDAP.modify(self.dn, [ASF::Base.mod_replace(attr.to_s, value)])
+        # attributes are expected to be arrays
+        attrs[attr.to_s] = value.is_a?(String) ? [value] : value
+      end
     end
 
     # add a new person to LDAP.  Attrs must include uid, cn, and mail

Mime
View raw message