summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Wurst <ChristophWurst@users.noreply.github.com>2021-06-17 18:17:28 +0200
committerGitHub <noreply@github.com>2021-06-17 18:17:28 +0200
commitb73f40eabbfb3e7941b5628b7243b58211e07d58 (patch)
tree735f80d79f1bec875bdd20c0bdf820abf11e45f4
parent18ff2612a1a7908b613490a38b6d49ee2dc18a19 (diff)
parent2690481cbad009b74292fdfbd028fc8b5b01a394 (diff)
downloadnextcloud-server-b73f40eabbfb3e7941b5628b7243b58211e07d58.tar.gz
nextcloud-server-b73f40eabbfb3e7941b5628b7243b58211e07d58.zip
Merge pull request #24318 from nextcloud/techdebt/noid/remove-oc_user-getDisplayName
Use proper methods for display name retrieval
-rw-r--r--apps/files_sharing/lib/Cache.php24
-rw-r--r--apps/files_sharing/lib/SharedStorage.php7
-rw-r--r--lib/private/TemplateLayout.php14
-rw-r--r--lib/private/legacy/OC_User.php26
4 files changed, 32 insertions, 39 deletions
diff --git a/apps/files_sharing/lib/Cache.php b/apps/files_sharing/lib/Cache.php
index 25e92d23962..8729426221b 100644
--- a/apps/files_sharing/lib/Cache.php
+++ b/apps/files_sharing/lib/Cache.php
@@ -38,6 +38,7 @@ use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchComparison;
use OCP\Files\Search\ISearchOperator;
use OCP\Files\StorageNotAvailableException;
+use OCP\IUserManager;
/**
* Metadata cache for shared files
@@ -45,15 +46,12 @@ use OCP\Files\StorageNotAvailableException;
* don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead
*/
class Cache extends CacheJail {
- /**
- * @var \OCA\Files_Sharing\SharedStorage
- */
+ /** @var \OCA\Files_Sharing\SharedStorage */
private $storage;
-
- /**
- * @var ICacheEntry
- */
+ /** @var ICacheEntry */
private $sourceRootInfo;
+ /** @var IUserManager */
+ private $userManager;
private $rootUnchanged = true;
@@ -63,11 +61,11 @@ class Cache extends CacheJail {
/**
* @param \OCA\Files_Sharing\SharedStorage $storage
- * @param ICacheEntry $sourceRootInfo
*/
- public function __construct($storage, ICacheEntry $sourceRootInfo) {
+ public function __construct($storage, ICacheEntry $sourceRootInfo, IUserManager $userManager) {
$this->storage = $storage;
$this->sourceRootInfo = $sourceRootInfo;
+ $this->userManager = $userManager;
$this->numericId = $sourceRootInfo->getStorageId();
parent::__construct(
@@ -174,7 +172,13 @@ class Cache extends CacheJail {
private function getOwnerDisplayName() {
if (!$this->ownerDisplayName) {
- $this->ownerDisplayName = \OC_User::getDisplayName($this->storage->getOwner(''));
+ $uid = $this->storage->getOwner('');
+ $user = $this->userManager->get($uid);
+ if ($user) {
+ $this->ownerDisplayName = $user->getDisplayName();
+ } else {
+ $this->ownerDisplayName = $uid;
+ }
}
return $this->ownerDisplayName;
}
diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php
index 662c5ad3651..f4a525ce871 100644
--- a/apps/files_sharing/lib/SharedStorage.php
+++ b/apps/files_sharing/lib/SharedStorage.php
@@ -43,6 +43,7 @@ use OCP\Files\Cache\ICacheEntry;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IDisableEncryptionStorage;
use OCP\Files\Storage\IStorage;
+use OCP\IUserManager;
use OCP\Lock\ILockingProvider;
use OCP\Share\IShare;
@@ -385,7 +386,11 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
return new FailedCache();
}
- $this->cache = new \OCA\Files_Sharing\Cache($storage, $sourceRoot, $this->superShare);
+ $this->cache = new \OCA\Files_Sharing\Cache(
+ $storage,
+ $sourceRoot,
+ \OC::$server->get(IUserManager::class)
+ );
return $this->cache;
}
diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php
index 82bd0fd22e7..16d4423838b 100644
--- a/lib/private/TemplateLayout.php
+++ b/lib/private/TemplateLayout.php
@@ -52,6 +52,7 @@ use OCP\Defaults;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\INavigationManager;
+use OCP\IUserSession;
use OCP\Support\Subscription\IRegistry;
use OCP\Util;
@@ -121,7 +122,12 @@ class TemplateLayout extends \OC_Template {
break;
}
}
- $userDisplayName = \OC_User::getDisplayName();
+
+ $userDisplayName = false;
+ $user = \OC::$server->get(IUserSession::class)->getUser();
+ if ($user) {
+ $userDisplayName = $user->getDisplayName();
+ }
$this->assign('user_displayname', $userDisplayName);
$this->assign('user_uid', \OC_User::getUser());
@@ -152,7 +158,11 @@ class TemplateLayout extends \OC_Template {
\OC_Util::addStyle('guest');
$this->assign('bodyid', 'body-login');
- $userDisplayName = \OC_User::getDisplayName();
+ $userDisplayName = false;
+ $user = \OC::$server->get(IUserSession::class)->getUser();
+ if ($user) {
+ $userDisplayName = $user->getDisplayName();
+ }
$this->assign('user_displayname', $userDisplayName);
$this->assign('user_uid', \OC_User::getUser());
} elseif ($renderAs === TemplateResponse::RENDER_AS_PUBLIC) {
diff --git a/lib/private/legacy/OC_User.php b/lib/private/legacy/OC_User.php
index dd97fb63e33..f955c5c6938 100644
--- a/lib/private/legacy/OC_User.php
+++ b/lib/private/legacy/OC_User.php
@@ -329,32 +329,6 @@ class OC_User {
}
/**
- * get the display name of the user currently logged in.
- *
- * @param string $uid
- * @return string|bool uid or false
- * @deprecated 8.1.0 fetch \OCP\IUser (has getDisplayName()) by using method
- * get() of \OCP\IUserManager - \OC::$server->getUserManager()
- */
- public static function getDisplayName($uid = null) {
- if ($uid) {
- $user = \OC::$server->getUserManager()->get($uid);
- if ($user) {
- return $user->getDisplayName();
- } else {
- return $uid;
- }
- } else {
- $user = \OC::$server->getUserSession()->getUser();
- if ($user) {
- return $user->getDisplayName();
- } else {
- return false;
- }
- }
- }
-
- /**
* Set password
*
* @param string $uid The username