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: Extract find by name code for general use
Date Sat, 27 Feb 2021 12:41:14 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 5ae89ee  Extract find by name code for general use
5ae89ee is described below

commit 5ae89ee6495969182c13667a76744bbe4e01e3fb
Author: Sebb <sebb@apache.org>
AuthorDate: Sat Feb 27 12:41:06 2021 +0000

    Extract find by name code for general use
---
 lib/whimsy/asf/ldap.rb         | 23 +++++++++++++++++++++++
 lib/whimsy/asf/member-files.rb | 11 +----------
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/lib/whimsy/asf/ldap.rb b/lib/whimsy/asf/ldap.rb
index 240545c..8724dad 100644
--- a/lib/whimsy/asf/ldap.rb
+++ b/lib/whimsy/asf/ldap.rb
@@ -686,6 +686,29 @@ module ASF
       ASF.search_one(base, filter, 'uid').flatten
     end
 
+    # Get a list of ids matching a name
+    # matches against 'cn', also 'givenName' and 'sn' if the former does not match
+    # returns an array of ids; may be empty
+    # Intended for use when matching a few people individually.
+    def self.find_by_name(name)
+      res = listids("(cn=#{name})")
+      if res.empty?
+        parts = name.split(' ')
+        res = listids("(&(givenName=#{parts[0]})(sn=#{parts[-1]}))")
+      end
+      res
+    end
+
+    # Get id matching a name, or nil
+    # matches against 'cn', also 'givenName' and 'sn' if the former does not match
+    # returns a single id, or nil if there is not a unique match
+    # Intended for use when matching a few people individually.
+    def self.find_by_name!(name)
+      res = find_by_name(name)
+      return nil unless res.size == 1
+      res.first
+    end
+
     # pre-fetch a given set of attributes, for a given list of people
     def self.preload(attributes, people=[])
       list = Hash.new {|hash, name| hash[name] = find(name)}
diff --git a/lib/whimsy/asf/member-files.rb b/lib/whimsy/asf/member-files.rb
index 93b5ed7..5f71fb4 100644
--- a/lib/whimsy/asf/member-files.rb
+++ b/lib/whimsy/asf/member-files.rb
@@ -81,16 +81,7 @@ module ASF
       ASF::MemberFiles.parse_file('board_nominations.txt') do |hdr, nominee|
         # for board, the header currentl looks like this:
         # <PUBLIC NAME>
-        id = ASF::Person.listids("cn=#{hdr}").first
-        # Allow for missing initials; check first and last name
-        unless id
-          gn, sn, rest = hdr.split(' ')
-          if rest # more than two words
-            id = hdr
-          else
-            id = ASF::Person.listids("(&(sn=#{sn})(givenName=#{gn}))").first || hdr
-          end
-        end
+        id = ASF::Person.find_by_name!(hdr) || hdr # default to full name
         nominee['Public Name'] = hdr.force_encoding(Encoding::UTF_8) # the board file does
not have ids, unfortunately
         nominees[id] = nominee
       end


Mime
View raw message