summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2022-05-17 15:20:28 +0200
committerRobin Appelman <robin@icewind.nl>2022-05-18 03:47:34 +0200
commit6d6662ec68c8e15c4c6bfdf1c694794badd412d7 (patch)
treebe5fef3090aaadad183cf68b09694daf09c0e65b
parent83f831c26382c648d759384b8c14cac2edc67fa4 (diff)
downloadnextcloud-server-6d6662ec68c8e15c4c6bfdf1c694794badd412d7.tar.gz
nextcloud-server-6d6662ec68c8e15c4c6bfdf1c694794badd412d7.zip
expose displayname cache trough a public interface
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--lib/private/Files/View.php7
-rw-r--r--lib/private/Server.php5
-rw-r--r--lib/private/User/LazyUser.php6
-rw-r--r--lib/private/User/Manager.php11
-rw-r--r--lib/public/IUserManager.php11
-rw-r--r--tests/lib/User/ManagerTest.php1
6 files changed, 30 insertions, 11 deletions
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index 2b6732e2ba0..a555aeb24f1 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -49,9 +49,7 @@ namespace OC\Files;
use Icewind\Streams\CallbackWrapper;
use OC\Files\Mount\MoveableMount;
use OC\Files\Storage\Storage;
-use OC\User\DisplayNameCache;
use OC\User\LazyUser;
-use OC\User\User;
use OCA\Files_Sharing\SharedMount;
use OCP\Constants;
use OCP\Files\Cache\ICacheEntry;
@@ -103,8 +101,6 @@ class View {
private LoggerInterface $logger;
- private DisplayNameCache $displayNameCache;
-
/**
* @param string $root
* @throws \Exception If $root contains an invalid path
@@ -121,7 +117,6 @@ class View {
$this->lockingProvider = \OC::$server->getLockingProvider();
$this->lockingEnabled = !($this->lockingProvider instanceof \OC\Lock\NoopLockingProvider);
$this->userManager = \OC::$server->getUserManager();
- $this->displayNameCache = \OC::$server->get(DisplayNameCache::class);
$this->logger = \OC::$server->get(LoggerInterface::class);
}
@@ -1319,7 +1314,7 @@ class View {
* @return IUser
*/
private function getUserObjectForOwner(string $ownerId) {
- return new LazyUser($ownerId, $this->displayNameCache, $this->userManager);
+ return new LazyUser($ownerId, $this->userManager);
}
/**
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 6e6fa430489..cc855eb0304 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -151,6 +151,7 @@ use OC\SystemTag\ManagerFactory as SystemTagManagerFactory;
use OC\Tagging\TagMapper;
use OC\Talk\Broker;
use OC\Template\JSCombiner;
+use OC\User\DisplayNameCache;
use OCA\Theming\ImageManager;
use OCA\Theming\ThemingDefaults;
use OCA\Theming\Util;
@@ -472,6 +473,10 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class);
$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
+ $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) {
+ return $c->get(\OC\User\Manager::class)->getDisplayNameCache();
+ });
+
$this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) {
$groupManager = new \OC\Group\Manager(
$this->get(IUserManager::class),
diff --git a/lib/private/User/LazyUser.php b/lib/private/User/LazyUser.php
index 8b98b112731..30e44d57061 100644
--- a/lib/private/User/LazyUser.php
+++ b/lib/private/User/LazyUser.php
@@ -28,12 +28,10 @@ use OCP\IUserManager;
class LazyUser implements IUser {
private ?IUser $user = null;
- private DisplayNameCache $displayNameCache;
private string $uid;
private IUserManager $userManager;
- public function __construct(string $uid, DisplayNameCache $displayNameCache, IUserManager $userManager) {
- $this->displayNameCache = $displayNameCache;
+ public function __construct(string $uid, IUserManager $userManager) {
$this->uid = $uid;
$this->userManager = $userManager;
}
@@ -52,7 +50,7 @@ class LazyUser implements IUser {
}
public function getDisplayName() {
- return $this->displayNameCache->getDisplayName($this->uid);
+ return $this->userManager->getDisplayName($this->uid);
}
public function setDisplayName($displayName) {
diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php
index c59cbaa7b20..5a5edbdbd27 100644
--- a/lib/private/User/Manager.php
+++ b/lib/private/User/Manager.php
@@ -93,6 +93,8 @@ class Manager extends PublicEmitter implements IUserManager {
/** @var IEventDispatcher */
private $eventDispatcher;
+ private DisplayNameCache $displayNameCache;
+
public function __construct(IConfig $config,
EventDispatcherInterface $oldDispatcher,
ICacheFactory $cacheFactory,
@@ -106,6 +108,7 @@ class Manager extends PublicEmitter implements IUserManager {
unset($cachedUsers[$user->getUID()]);
});
$this->eventDispatcher = $eventDispatcher;
+ $this->displayNameCache = new DisplayNameCache($cacheFactory, $this);
}
/**
@@ -183,6 +186,10 @@ class Manager extends PublicEmitter implements IUserManager {
return null;
}
+ public function getDisplayName(string $uid): string {
+ return $this->displayNameCache->getDisplayName($uid);
+ }
+
/**
* get or construct the user object
*
@@ -740,4 +747,8 @@ class Manager extends PublicEmitter implements IUserManager {
return !file_exists(rtrim($dataDirectory, '/') . '/' . $uid);
}
+
+ public function getDisplayNameCache(): DisplayNameCache {
+ return $this->displayNameCache;
+ }
}
diff --git a/lib/public/IUserManager.php b/lib/public/IUserManager.php
index e5c220af40c..da7d477ad43 100644
--- a/lib/public/IUserManager.php
+++ b/lib/public/IUserManager.php
@@ -85,6 +85,17 @@ interface IUserManager {
public function get($uid);
/**
+ * Get the display name of a user
+ *
+ * Note that this will return the uid if the user is not found instead of throwing an exception
+ *
+ * @param string $uid
+ * @return string
+ * @since 25.0.0
+ */
+ public function getDisplayName(string $uid): string;
+
+ /**
* check if a user exists
*
* @param string $uid
diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php
index c8c1430d583..26fc39a1e31 100644
--- a/tests/lib/User/ManagerTest.php
+++ b/tests/lib/User/ManagerTest.php
@@ -50,7 +50,6 @@ class ManagerTest extends TestCase {
$this->cache = $this->createMock(ICache::class);
$this->cacheFactory->method('createDistributed')
- ->with('user_backend_map')
->willReturn($this->cache);
}