Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 2 additions & 39 deletions apps/user_ldap/lib/User_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public function getHome($uid) {
/**
* get display name of the user
* @param string $uid user ID of the user
* @return string|false display name
* @return ?string|false display name

Check notice

Code scanning / Psalm

ImplementedReturnTypeMismatch

The inherited return type 'string' for OCP\UserInterface::getDisplayName is different to the implemented return type for OCA\User_LDAP\User_LDAP::getdisplayname 'false|null|string'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the interface this should always return a string. It seems other backends return the uid when a display name cannot be found.

*/
public function getDisplayName($uid) {
if ($this->userPluginManager->implementsActions(Backend::GET_DISPLAYNAME)) {
Expand All @@ -472,44 +472,7 @@ public function getDisplayName($uid) {
return false;
}

$cacheKey = 'getDisplayName'.$uid;
if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
return $displayName;
}

//Check whether the display name is configured to have a 2nd feature
$additionalAttribute = $this->access->connection->ldapUserDisplayName2;
$displayName2 = '';
if ($additionalAttribute !== '') {
$displayName2 = $this->access->readAttribute(
$this->access->username2dn($uid),
$additionalAttribute);
}

$displayName = $this->access->readAttribute(
$this->access->username2dn($uid),
$this->access->connection->ldapUserDisplayName);

if ($displayName && (count($displayName) > 0)) {
$displayName = $displayName[0];

if (is_array($displayName2)) {
$displayName2 = count($displayName2) > 0 ? $displayName2[0] : '';
}

$user = $this->access->userManager->get($uid);
if ($user instanceof User) {
$displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
$this->access->connection->writeToCache($cacheKey, $displayName);
}
if ($user instanceof OfflineUser) {
/** @var OfflineUser $user*/
$displayName = $user->getDisplayName();
}
return $displayName;
}

return null;
return $this->ocConfig->getUserValue($uid, 'user_ldap', 'displayName', null);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/private/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function getDisplayName() {
if (!empty($displayName)) {
$this->displayName = $displayName;
} else {
$this->displayName = $this->uid;
return $this->uid;
}
}
return $this->displayName;
Expand Down