FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 4ff0035f authored by Robin Goodall's avatar Robin Goodall :speech_balloon:
Browse files

Merge branch 'issue-5-naming' into 'master'

naming: prefer displayName over cn/sn

Closes #5

See merge request !4
parents 0d289d93 c2be7330
No related branches found
No related tags found
1 merge request!4naming: prefer displayName over cn/sn
Checking pipeline status
......@@ -38,26 +38,6 @@ def get_names(*, uid, display_name=None, cn=None, sn=None):
Names(given_name='Stephen',
family_name='Quill-RomanXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
For compatibility with the existing authenticator, if we have common name and surname and the
common name ends with the surname, this is used to form the given names assuming there is some
string left. (Once we're happy with the sync, we should remove this.)
>>> get_names(uid='spqr1', sn='Quill Roman', cn='Prof. S.P. Quill Roman')
Names(given_name='Prof. S.P.', family_name='Quill Roman')
For similar compatibility reasons, if we have a cn, split it at the final space character
irrespective of display name.
>>> get_names(uid='spqr1', cn='Prof. S.P. Quill Roman', display_name='Foo Bar')
Names(given_name='Prof. S.P. Quill', family_name='Roman')
>>> get_names(
... uid='spqr1', sn='spqr1', display_name='Stephen P. Q. Roman',
... cn='Prof. S.P.Q. Roman')
Names(given_name='Prof. S.P.Q.', family_name='Roman')
(In the future we will probably remove the compatibility layer but not until we're happy with
the rest of the sync.)
If we have display name and surname and the display name ends with the surname, this is used to
form the given names assuming there is some string left.
......@@ -73,6 +53,19 @@ def get_names(*, uid, display_name=None, cn=None, sn=None):
>>> get_names(uid='spqr1', display_name='Stephen Quill Roman')
Names(given_name='Stephen Quill', family_name='Roman')
If we have common name and surname and the common name ends with the surname, this is used to
form the given names assuming there is some string left.
>>> get_names(uid='spqr1', sn='Quill Roman', cn='Prof. S.P. Quill Roman')
Names(given_name='Prof. S.P.', family_name='Quill Roman')
If we *only* have a cn, split it at the final space character.
>>> get_names(uid='spqr1', cn='Prof. S.P. Quill Roman')
Names(given_name='Prof. S.P. Quill', family_name='Roman')
>>> get_names(uid='spqr1', sn='spqr1', cn='Prof. S.P.Q. Roman')
Names(given_name='Prof. S.P.Q.', family_name='Roman')
Support Wookey.
>>> get_names(uid='spqr1', display_name='Wookey')
......@@ -102,30 +95,30 @@ def get_names(*, uid, display_name=None, cn=None, sn=None):
def _make_ret(*, family_name, given_name):
return Names(family_name=_clean(family_name)[:60], given_name=_clean(given_name)[:40])
# If we have a sn and cn and the cn ends with sn, split out the sn.
if cn is not None and sn is not None and cn.endswith(sn):
given_name = cn[:-len(sn)].strip()
# If we have a sn and display name and the display name ends with sn, split out the sn.
if display_name is not None and sn is not None and display_name.endswith(sn):
given_name = display_name[:-len(sn)].strip()
if given_name != '':
return _make_ret(family_name=sn, given_name=given_name)
# If we have cn, split at space and see if we have two parts.
if cn is not None:
components = cn.split()
# If we have the display name, split at space and see if we have two parts.
if display_name is not None:
components = display_name.split()
if len(components) > 0:
family_name = components[-1]
given_name = ' '.join(components[:-1])
if given_name != '' and family_name != '':
return _make_ret(family_name=family_name, given_name=given_name)
# If we have a sn and display name and the display name ends with sn, split out the sn.
if display_name is not None and sn is not None and display_name.endswith(sn):
given_name = display_name[:-len(sn)].strip()
# If we have a sn and cn and the cn ends with sn, split out the sn.
if cn is not None and sn is not None and cn.endswith(sn):
given_name = cn[:-len(sn)].strip()
if given_name != '':
return _make_ret(family_name=sn, given_name=given_name)
# If we have the display name, split at space and see if we have two parts.
if display_name is not None:
components = display_name.split()
# If we have cn, split at space and see if we have two parts.
if cn is not None:
components = cn.split()
if len(components) > 0:
family_name = components[-1]
given_name = ' '.join(components[:-1])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment