From 40056c807a56bb08dc9464cb531a5e1d1e12b6f0 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 9 Aug 2023 09:33:07 +0200 Subject: [PATCH] fix: always use display name from correct backend Overwrite the display name after the account is initialized when using an instacne of IGetDisplayNameBackend. Before when using a variation of user_oidc and registering a Backend.php implementing IGetDisplayNameBackend the personal setting page shows 'uid'. The UserManager/AccountManager seems not to use consistently the correct backend. The correct backend is used in this sequence: server/lib/private/TemplateLayout.php $userDisplayName = \OC_User::getDisplayName(); $this->assign(user_displayname, $userDisplayName); In the settings page, it definitely not calls the registered backend, but seems to fall back to default Backend and shows (usually) uid or a value from the standard account property table. Signed-off-by: Max --- lib/private/Accounts/AccountManager.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php index 20e0add1ccb68..9b1aca320ef37 100644 --- a/lib/private/Accounts/AccountManager.php +++ b/lib/private/Accounts/AccountManager.php @@ -61,6 +61,7 @@ use OCP\Mail\IMailer; use OCP\Security\ICrypto; use OCP\Security\VerificationToken\IVerificationToken; +use OCP\User\Backend\IGetDisplayNameBackend; use OCP\Util; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -791,6 +792,10 @@ public function getAccount(IUser $user): IAccount { return $this->internalCache->get($user->getUID()); } $account = $this->parseAccountData($user, $this->getUser($user)); + if ($user->getBackend() instanceof IGetDisplayNameBackend) { + $property = $account->getProperty(self::PROPERTY_DISPLAYNAME); + $account->setProperty(self::PROPERTY_DISPLAYNAME, $user->getDisplayName(), $property->getScope(), $property->getVerified()); + } $this->internalCache->set($user->getUID(), $account); return $account; }