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 468b9b9 Add draft method to convert cn to sn + givenName
468b9b9 is described below
commit 468b9b9faab3f33b34633a00b369cd1705212762
Author: Sebb
AuthorDate: Mon Jul 26 23:26:05 2021 +0100
Add draft method to convert cn to sn + givenName
---
lib/spec/lib/person_spec.rb | 38 ++
lib/whimsy/asf/person.rb| 16
2 files changed, 54 insertions(+)
diff --git a/lib/spec/lib/person_spec.rb b/lib/spec/lib/person_spec.rb
new file mode 100644
index 000..c662c54
--- /dev/null
+++ b/lib/spec/lib/person_spec.rb
@@ -0,0 +1,38 @@
+require 'spec_helper'
+require 'whimsy/asf'
+
+describe ASF::Person do
+ it "ldap_parse_cn_DRAFT('', false) should return [nil, []]" do
+res = ASF::Person.ldap_parse_cn_DRAFT('', false)
+expect(res).to eq([nil, []])
+ end
+ it "ldap_parse_cn_DRAFT('', true) should return [nil, []]" do
+res = ASF::Person.ldap_parse_cn_DRAFT('', true)
+expect(res).to eq([nil, []])
+ end
+ # If there is only one name, it must be the surname
+ it "ldap_parse_cn_DRAFT('one', false) should return ['one', []]" do
+res = ASF::Person.ldap_parse_cn_DRAFT('one', false)
+expect(res).to eq(['one', []])
+ end
+ it "ldap_parse_cn_DRAFT('one', true) should return ['one', []]" do
+res = ASF::Person.ldap_parse_cn_DRAFT('one', true)
+expect(res).to eq(['one', []])
+ end
+ it "ldap_parse_cn_DRAFT('one two', false) should return ['two', ['one']]" do
+res = ASF::Person.ldap_parse_cn_DRAFT('one two', false)
+expect(res).to eq(['two', ['one']])
+ end
+ it "ldap_parse_cn_DRAFT('one two', true) should return ['one', ['two']]" do
+res = ASF::Person.ldap_parse_cn_DRAFT('one two', true)
+expect(res).to eq(['one', ['two']])
+ end
+ it "ldap_parse_cn_DRAFT('one two three', false) should return ['three',
['one', 'two']]" do
+res = ASF::Person.ldap_parse_cn_DRAFT('one two three', false)
+expect(res).to eq(['three', ['one', 'two']])
+ end
+ it "ldap_parse_cn_DRAFT('one two three', tru) should return ['one', ['two',
'three']]" do
+res = ASF::Person.ldap_parse_cn_DRAFT('one two three', true)
+expect(res).to eq(['one', ['two', 'three']])
+ end
+end
\ No newline at end of file
diff --git a/lib/whimsy/asf/person.rb b/lib/whimsy/asf/person.rb
index 8ba6fc4..49508cd 100644
--- a/lib/whimsy/asf/person.rb
+++ b/lib/whimsy/asf/person.rb
@@ -165,6 +165,22 @@ module ASF
result
end
+# extract sn and givenName from cn (needed for LDAP entries)
+# returns sn, [givenName,...]
+# DRAFT version: not for general use yet
+# Does not handle multi-word family names or honorifics etc
+def self.ldap_parse_cn_DRAFT(cn, familyFirst)
+ words = cn.split(' ')
+ if familyFirst
+sn = words.shift
+givenName = words
+ else
+sn = words.pop
+givenName = words
+ end
+ return sn, givenName
+end
+
# Name equivalences
names = [
%w(Alex Alexander Alexandru),