whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject [whimsy] branch master updated: rough in ASF::Person#rename support (untested)
Date Sat, 24 Feb 2018 00:10:15 GMT
This is an automated email from the ASF dual-hosted git repository.

rubys 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 d71f1df  rough in ASF::Person#rename support (untested)
d71f1df is described below

commit d71f1dffb3131c94ce6b6d5a53a8ee3e97ccb24a
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Fri Feb 23 19:09:53 2018 -0500

    rough in ASF::Person#rename support (untested)
---
 lib/whimsy/asf/ldap.rb | 59 +++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 49 insertions(+), 10 deletions(-)

diff --git a/lib/whimsy/asf/ldap.rb b/lib/whimsy/asf/ldap.rb
index 709b42f..f3d1e40 100644
--- a/lib/whimsy/asf/ldap.rb
+++ b/lib/whimsy/asf/ldap.rb
@@ -554,6 +554,43 @@ module ASF
       person
     end
 
+    # rename a person
+    def rename(newid, attrs={})
+      # ensure person exists in LDAP
+      raise ArgumentError(self.id) unless self.dn
+
+      # create a new person
+      new_person = ASF::Person.create(self.attrs.merge(attrs).merge(uid: newid))
+
+      # determine what groups the individual is a member of
+      uid_groups = ASF.search_subtree('dc=apache,dc=org', 
+        'memberUid=#{self.id}', 'dn').flatten
+      dn_groups = ASF.search_subtree('dc=apache,dc=org', 
+        'member=#{self.dn}', 'dn').flatten
+
+      # add new user to all groups
+      uid_groups.each do |dn|
+        ASF::LDAP.modify(dn, [ASF::Base.mod_add('memberUid', new_person.id)])
+      end
+      dn_groups.each do |dn|
+        ASF::LDAP.modify(dn, [ASF::Base.mod_add('member', new_person.dn)])
+      end
+
+      # remove original user from all groups
+      uid_groups.each do |dn|
+        ASF::LDAP.modify(dn, [ASF::Base.mod_delete('memberUid', self.id)])
+      end
+      dn_groups.each do |dn|
+        ASF::LDAP.modify(dn, [ASF::Base.mod_delete('member', self.dn)])
+      end
+
+      # remove original user
+      ASF::Person.remove(person.id)
+
+      # return new user
+      new_person
+    end
+
     # completely remove a committer from LDAP
     # ** DO NOT USE **
     # In almost all cases, use deregister instead
@@ -813,9 +850,19 @@ module ASF
         ASF::search_one(ASF::Person.base, 'uid=*', 'uidNumber').
           flatten.map(&:to_i).max + 1
 
-      nextgid = attrs['gidNumber'] ||
-        ASF::search_one(group_base, 'cn=*', 'gidNumber').
+      nextgid = attrs['gidNumber']
+      unless nextgid
+        nextgid = ASF::search_one(group_base, 'cn=*', 'gidNumber').
           flatten.map(&:to_i).max + 1
+
+        # create new LDAP group
+        entry = [
+          mod_add('objectClass', ['posixGroup', 'top']),
+          mod_add('cn', availid),
+          mod_add('userPassword', '{crypt}*'),
+          mod_add('gidNumber', nextgid.to_s),
+        ]
+      end
  
       # fixed attributes
       attrs.merge!({
@@ -842,14 +889,6 @@ module ASF
         end
       end
 
-      # create new LDAP group
-      entry = [
-        mod_add('objectClass', ['posixGroup', 'top']),
-        mod_add('cn', availid),
-        mod_add('userPassword', '{crypt}*'),
-        mod_add('gidNumber', nextgid.to_s),
-      ]
-
       ASF::LDAP.add("cn=#{availid},#{group_base}", entry)
 
       # create new LDAP person

-- 
To stop receiving notification emails like this one, please contact
rubys@apache.org.

Mime
View raw message