Skip to content

Commit

Permalink
Added none_if_unfound parameter in get_user_fullname function
Browse files Browse the repository at this point in the history
  • Loading branch information
sgeulette committed Jan 26, 2023
1 parent eb171ce commit 486068c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -6,6 +6,8 @@ Changelog

- Added `transmogrifier` module with `get_main_path` and `relative_path` functions.
[sgeulette]
- Added `none_if_unfound` parameter in `get_user_fullname` function
[sgeulette]

0.65 (2022-12-07)
-----------------
Expand Down
7 changes: 4 additions & 3 deletions src/imio/helpers/content.py
Expand Up @@ -682,12 +682,13 @@ def object_ids(context, class_names):
return res


def get_user_fullname(userid, none_if_no_user=False):
def get_user_fullname(userid, none_if_no_user=False, none_if_unfound=False):
"""Get fullname without using getMemberInfo that is slow slow slow...
We get it only from mutable_properties or authentic.
:param userid: principal id
:param none_if_no_user: return None if principal is not a user or is not found
:param none_if_no_user: return None if principal is not a user
:param none_if_unfound: return None if principal is not found
:return: fullname or userid if fullname is empty.
"""
userid = safe_unicode(userid)
Expand All @@ -714,7 +715,7 @@ def get_user_fullname(userid, none_if_no_user=False):
fullname = data._identities['authentic-agents'].data['fullname']
break
else: # we didn't find this userid
if none_if_no_user:
if none_if_unfound:
return None
return userid
return safe_unicode(fullname) or userid
4 changes: 1 addition & 3 deletions src/imio/helpers/tests/test_content.py
Expand Up @@ -392,9 +392,7 @@ def test_object_ids(self):

def test_user_fullname(self):
self.assertIsNone(get_user_fullname(None))
self.assertEqual(get_user_fullname("", none_if_no_user=True), None)
self.assertEqual(get_user_fullname(""), "")
self.assertEqual(get_user_fullname("unknown_user", none_if_no_user=True), None)
self.assertEqual(get_user_fullname("unknown_user", none_if_unfound=True), None)
self.assertEqual(get_user_fullname("unknown_user"), "unknown_user")
# create some users
user1 = api.user.create('a@b.be', 'user1', '12345', properties={'fullname': 'Stéphan Smith'})
Expand Down

0 comments on commit 486068c

Please sign in to comment.