Compare commits

...

2 Commits

Author SHA1 Message Date
Morris Jobke 22ed863dd7
Use DI for files_sharing Cache
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
2021-04-01 22:48:21 +02:00
Morris Jobke e2042fb562
Use proper methods for display name retrieval
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
2021-04-01 22:47:03 +02:00
4 changed files with 32 additions and 42 deletions

View File

@ -34,6 +34,7 @@ use OC\Files\Cache\Wrapper\CacheJail;
use OC\Files\Storage\Wrapper\Jail;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\StorageNotAvailableException;
use OCP\IUserManager;
/**
* Metadata cache for shared files
@ -41,15 +42,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;
@ -57,13 +55,10 @@ class Cache extends CacheJail {
private $numericId;
/**
* @param \OCA\Files_Sharing\SharedStorage $storage
* @param ICacheEntry $sourceRootInfo
*/
public function __construct($storage, ICacheEntry $sourceRootInfo) {
public function __construct(SharedStorage $storage, ICacheEntry $sourceRootInfo, IUserManager $userManager) {
$this->storage = $storage;
$this->sourceRootInfo = $sourceRootInfo;
$this->userManager = $userManager;
$this->numericId = $sourceRootInfo->getStorageId();
parent::__construct(
@ -170,7 +165,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;
}

View File

@ -44,6 +44,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;
@ -386,7 +387,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;
}

View File

@ -53,6 +53,7 @@ use OCP\Defaults;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\INavigationManager;
use OCP\IUserSession;
use OCP\Support\Subscription\IRegistry;
use OCP\Util;
@ -122,7 +123,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());
@ -153,7 +159,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) {

View File

@ -317,32 +317,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
*