From 00e462bce0fc4d1a1cd8829c27edef422278b580 Mon Sep 17 00:00:00 2001
From: Benjamin Bertrand <benjamin.bertrand@ess.eu>
Date: Wed, 25 Nov 2020 18:13:29 +0100
Subject: [PATCH] Fix display name in syncusers command

JIRA INFRA-2909
---
 app/commands.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/app/commands.py b/app/commands.py
index 87860a3..1075ba1 100644
--- a/app/commands.py
+++ b/app/commands.py
@@ -54,7 +54,9 @@ def sync_user(connection, user):
             disable_user(user)
         else:
             attributes = ldap_user["attributes"]
-            user.display_name = utils.attribute_to_string(attributes["cn"])
+            user.display_name = (
+                utils.attribute_to_string(attributes["cn"]) or user.username
+            )
             user.email = utils.attribute_to_string(attributes["mail"])
             groups = ldap_manager.get_user_groups(
                 dn=ldap3.utils.conv.escape_filter_chars(ldap_user["dn"]),
-- 
GitLab