Skip to content

Commit

Permalink
fix: do not fetch LDAP display name all the time
Browse files Browse the repository at this point in the history
- use cache and rely on background update mechanism
- with ajax cron it will still run
- core User must not cache uid as displayname to address edge case (early
  announcement with displayname not ready)

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Jun 2, 2023
1 parent 2188505 commit aa6fd30
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 40 deletions.
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 @@ -462,7 +462,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 Note

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'
*/
public function getDisplayName($uid) {
if ($this->userPluginManager->implementsActions(Backend::GET_DISPLAYNAME)) {
Expand All @@ -473,44 +473,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 @@ -147,7 +147,7 @@ public function getDisplayName() {
if (!empty($displayName)) {
$this->displayName = $displayName;
} else {
$this->displayName = $this->uid;
return $this->uid;
}
}
return $this->displayName;
Expand Down

0 comments on commit aa6fd30

Please sign in to comment.