Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor OC\Server::getUserManager #40154

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

use OCP\IUserManager;
use Psr\Log\LoggerInterface;

$application->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand());
Expand Down Expand Up @@ -130,7 +132,7 @@
\OC::$server->getEncryptionManager(),
\OC::$server->getAppManager(),
\OC::$server->getConfig(),
new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getUserManager(), new \OC\Files\View()),
new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->get(IUserManager::class), new \OC\Files\View()),
summersab marked this conversation as resolved.
Show resolved Hide resolved
new \Symfony\Component\Console\Helper\QuestionHelper())
);

Expand All @@ -140,13 +142,13 @@
$view = new \OC\Files\View();
$util = new \OC\Encryption\Util(
$view,
\OC::$server->getUserManager(),
\OC::$server->get(IUserManager::class),
\OC::$server->getGroupManager(),
\OC::$server->getConfig()
);
$application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot(
$view,
\OC::$server->getUserManager(),
\OC::$server->get(IUserManager::class),
\OC::$server->getConfig(),
$util,
new \Symfony\Component\Console\Helper\QuestionHelper()
Expand All @@ -155,7 +157,7 @@
$application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util));
$application->add(new OC\Core\Command\Encryption\MigrateKeyStorage(
$view,
\OC::$server->getUserManager(),
\OC::$server->get(IUserManager::class),
\OC::$server->getConfig(),
$util,
\OC::$server->getCrypto()
Expand All @@ -182,26 +184,26 @@
$application->add(\OC::$server->query(\OC\Core\Command\Preview\Repair::class));
$application->add(\OC::$server->query(\OC\Core\Command\Preview\ResetRenderedTexts::class));

$application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager()));
$application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager()));
$application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager()));
$application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager()));
$application->add(new OC\Core\Command\User\Add(\OC::$server->get(IUserManager::class), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\User\Delete(\OC::$server->get(IUserManager::class)));
$application->add(new OC\Core\Command\User\Disable(\OC::$server->get(IUserManager::class)));
$application->add(new OC\Core\Command\User\Enable(\OC::$server->get(IUserManager::class)));
$application->add(new OC\Core\Command\User\LastSeen(\OC::$server->get(IUserManager::class)));
$application->add(\OC::$server->get(\OC\Core\Command\User\Report::class));
$application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager(), \OC::$server->getAppManager()));
$application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig()));
$application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\User\SyncAccountDataCommand(\OC::$server->getUserManager(), \OC::$server->get(\OCP\Accounts\IAccountManager::class)));
$application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->get(IUserManager::class), \OC::$server->getAppManager()));
$application->add(new OC\Core\Command\User\Setting(\OC::$server->get(IUserManager::class), \OC::$server->getConfig()));
$application->add(new OC\Core\Command\User\ListCommand(\OC::$server->get(IUserManager::class), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\User\Info(\OC::$server->get(IUserManager::class), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\User\SyncAccountDataCommand(\OC::$server->get(IUserManager::class), \OC::$server->get(\OCP\Accounts\IAccountManager::class)));
$application->add(\OC::$server->get(\OC\Core\Command\User\AuthTokens\Add::class));
$application->add(\OC::$server->get(\OC\Core\Command\User\AuthTokens\ListCommand::class));
$application->add(\OC::$server->get(\OC\Core\Command\User\AuthTokens\Delete::class));

$application->add(new OC\Core\Command\Group\Add(\OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\Group\Delete(\OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\Group\AddUser(\OC::$server->get(IUserManager::class), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->get(IUserManager::class), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\Group\Info(\OC::$server->get(\OCP\IGroupManager::class)));

$application->add(new OC\Core\Command\SystemTag\ListCommand(\OC::$server->get(\OCP\SystemTag\ISystemTagManager::class)));
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Encryption/EncryptionWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OC\Memcache\ArrayCache;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -84,7 +85,7 @@ public function wrapStorage($mountPoint, Storage $storage, IMountPoint $mount) {

$util = new Util(
new View(),
\OC::$server->getUserManager(),
\OC::$server->get(IUserManager::class),
\OC::$server->getGroupManager(),
\OC::$server->getConfig()
);
Expand Down
5 changes: 3 additions & 2 deletions lib/private/Encryption/HookManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OC\Files\Filesystem;
use OC\Files\View;
use OC\Files\SetupManager;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;

class HookManager {
Expand Down Expand Up @@ -54,7 +55,7 @@ private static function getUpdate(?string $owner = null): Update {
if (is_null(self::$updater)) {
$user = \OC::$server->getUserSession()->getUser();
if (!$user && $owner) {
$user = \OC::$server->getUserManager()->get($owner);
$user = \OC::$server->get(IUserManager::class)->get($owner);
}
if (!$user) {
throw new \Exception("Inconsistent data, File unshared, but owner not found. Should not happen");
Expand All @@ -74,7 +75,7 @@ private static function getUpdate(?string $owner = null): Update {
new View(),
new Util(
new View(),
\OC::$server->getUserManager(),
\OC::$server->get(IUserManager::class),
\OC::$server->getGroupManager(),
\OC::$server->getConfig()),
Filesystem::getMountManager(),
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Node/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public function getByIdInPath(int $id, string $path): array {
$absolutePath = rtrim($mount->getMountPoint() . $pathRelativeToMount, '/');
return $this->createNode($absolutePath, new FileInfo(
$absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount,
\OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount))
\OC::$server->get(IUserManager::class)->get($mount->getStorage()->getOwner($pathRelativeToMount))
));
}, $mountsContainingFile);

Expand Down
7 changes: 4 additions & 3 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
use OCP\Files\ReservedWordException;
use OCP\Files\Storage\IStorage;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -105,7 +106,7 @@ public function __construct(string $root = '') {
$this->fakeRoot = $root;
$this->lockingProvider = \OC::$server->getLockingProvider();
$this->lockingEnabled = !($this->lockingProvider instanceof \OC\Lock\NoopLockingProvider);
$this->userManager = \OC::$server->getUserManager();
$this->userManager = \OC::$server->get(IUserManager::class);
$this->logger = \OC::$server->get(LoggerInterface::class);
}

Expand Down Expand Up @@ -1626,7 +1627,7 @@ private function searchCommon($method, $args) {
$mount = $this->getMount('');
$mountPoint = $mount->getMountPoint();
$storage = $mount->getStorage();
$userManager = \OC::$server->getUserManager();
$userManager = \OC::$server->get(IUserManager::class);
if ($storage) {
$cache = $storage->getCache('');

Expand Down Expand Up @@ -1803,7 +1804,7 @@ private function getPartFileInfo(string $path): \OC\Files\FileInfo {
$mount = $this->getMount($path);
$storage = $mount->getStorage();
$internalPath = $mount->getInternalPath($this->getAbsolutePath($path));
$owner = \OC::$server->getUserManager()->get($storage->getOwner($internalPath));
$owner = \OC::$server->get(IUserManager::class)->get($storage->getOwner($internalPath));
return new FileInfo(
$this->getAbsolutePath($path),
$storage,
Expand Down
5 changes: 3 additions & 2 deletions lib/private/Repair.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Collaboration\Resources\IManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUserManager;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use OC\DB\Connection;
Expand Down Expand Up @@ -176,7 +177,7 @@ public static function getRepairSteps(): array {
return [
new Collation(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->getDatabaseConnection(), false),
new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()),
new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->get(IUserManager::class)),
new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
new MoveUpdaterStepFile(\OC::$server->getConfig()),
new MoveAvatars(
Expand All @@ -185,7 +186,7 @@ public static function getRepairSteps(): array {
),
new CleanPreviews(
\OC::$server->getJobList(),
\OC::$server->getUserManager(),
\OC::$server->get(IUserManager::class),
\OC::$server->getConfig()
),
new MigrateOauthTables(\OC::$server->get(Connection::class)),
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
use OCP\Defaults;
use OCP\IGroup;
use OCP\IL10N;
use OCP\IUserManager;
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -382,7 +383,7 @@ public function install($options) {
//create the user and group
$user = null;
try {
$user = \OC::$server->getUserManager()->createUser($username, $password);
$user = \OC::$server->get(IUserManager::class)->createUser($username, $password);
if (!$user) {
$error[] = "User <$username> could not be created.";
}
Expand Down
9 changes: 5 additions & 4 deletions lib/private/Share/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IUserManager;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -195,7 +196,7 @@ public static function getItemSharedWithUser(string $itemType, string $itemSourc

// if we didn't found a result then let's look for a group share.
if (empty($shares) && $user !== null) {
$userObject = \OC::$server->getUserManager()->get($user);
$userObject = \OC::$server->get(IUserManager::class)->get($user);
$groups = [];
if ($userObject) {
$groups = \OC::$server->getGroupManager()->getUserGroupIds($userObject);
Expand Down Expand Up @@ -403,7 +404,7 @@ public static function getItems($itemType, ?string $item = null, ?int $shareType
$qb->expr()->eq('share_with', $qb->createNamedParameter($shareWith))
));

$user = \OC::$server->getUserManager()->get($shareWith);
$user = \OC::$server->get(IUserManager::class)->get($shareWith);
$groups = [];
if ($user) {
$groups = \OC::$server->getGroupManager()->getUserGroupIds($user);
Expand Down Expand Up @@ -592,7 +593,7 @@ public static function getItems($itemType, ?string $item = null, ?int $shareType
$row['share_with_displayname'] = $row['share_with'];
if (isset($row['share_with']) && $row['share_with'] != '' &&
$row['share_type'] === IShare::TYPE_USER) {
$shareWithUser = \OC::$server->getUserManager()->get($row['share_with']);
$shareWithUser = \OC::$server->get(IUserManager::class)->get($row['share_with']);
$row['share_with_displayname'] = $shareWithUser === null ? $row['share_with'] : $shareWithUser->getDisplayName();
} elseif (isset($row['share_with']) && $row['share_with'] != '' &&
$row['share_type'] === IShare::TYPE_REMOTE) {
Expand All @@ -611,7 +612,7 @@ public static function getItems($itemType, ?string $item = null, ?int $shareType
}
}
if (isset($row['uid_owner']) && $row['uid_owner'] != '') {
$ownerUser = \OC::$server->getUserManager()->get($row['uid_owner']);
$ownerUser = \OC::$server->get(IUserManager::class)->get($row['uid_owner']);
$row['displayname_owner'] = $ownerUser === null ? $row['uid_owner'] : $ownerUser->getDisplayName();
}

Expand Down
9 changes: 5 additions & 4 deletions lib/private/Share20/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use OCP\Defaults;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IServerContainer;
use OCP\IUserManager;
use OCP\Share\IManager;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
Expand Down Expand Up @@ -97,7 +98,7 @@ protected function defaultShareProvider() {
if ($this->defaultProvider === null) {
$this->defaultProvider = new DefaultShareProvider(
$this->serverContainer->getDatabaseConnection(),
$this->serverContainer->getUserManager(),
$this->serverContainer->get(IUserManager::class),
$this->serverContainer->getGroupManager(),
$this->serverContainer->getLazyRootFolder(),
$this->serverContainer->getMailer(),
Expand Down Expand Up @@ -157,7 +158,7 @@ protected function federatedShareProvider() {
$l,
$this->serverContainer->getLazyRootFolder(),
$this->serverContainer->getConfig(),
$this->serverContainer->getUserManager(),
$this->serverContainer->get(IUserManager::class),
$this->serverContainer->getCloudIdManager(),
$this->serverContainer->getGlobalScaleConfig(),
$this->serverContainer->getCloudFederationProviderManager(),
Expand Down Expand Up @@ -189,7 +190,7 @@ protected function getShareByMailProvider() {
$this->serverContainer->getConfig(),
$this->serverContainer->getDatabaseConnection(),
$this->serverContainer->getSecureRandom(),
$this->serverContainer->getUserManager(),
$this->serverContainer->get(IUserManager::class),
$this->serverContainer->getLazyRootFolder(),
$this->serverContainer->getL10N('sharebymail'),
$this->serverContainer->getLogger(),
Expand Down Expand Up @@ -231,7 +232,7 @@ protected function getShareByCircleProvider() {
$this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider(
$this->serverContainer->getDatabaseConnection(),
$this->serverContainer->getSecureRandom(),
$this->serverContainer->getUserManager(),
$this->serverContainer->get(IUserManager::class),
$this->serverContainer->getLazyRootFolder(),
$this->serverContainer->getL10N('circles'),
$this->serverContainer->getLogger(),
Expand Down
3 changes: 2 additions & 1 deletion lib/private/User/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use OCP\Cache\CappedMemoryCache;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
use OCP\IUserManager;
use OCP\Security\Events\ValidatePasswordPolicyEvent;
use OCP\User\Backend\ABackend;
use OCP\User\Backend\ICheckPasswordBackend;
Expand Down Expand Up @@ -504,7 +505,7 @@ public static function preLoginNameUsedAsUserName($param) {
throw new \Exception('key uid is expected to be set in $param');
}

$backends = \OC::$server->getUserManager()->getBackends();
$backends = \OC::$server->get(IUserManager::class)->getBackends();
foreach ($backends as $backend) {
if ($backend instanceof Database) {
/** @var \OC\User\Database $backend */
Expand Down
3 changes: 2 additions & 1 deletion lib/private/legacy/OC_Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use OCP\ICacheFactory;
use OCP\IBinaryFinder;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Util;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -575,7 +576,7 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin
$ownerId = $storage->getOwner($path);
$ownerDisplayName = '';
if ($ownerId) {
$ownerDisplayName = \OC::$server->getUserManager()->getDisplayName($ownerId) ?? '';
$ownerDisplayName = \OC::$server->get(IUserManager::class)->getDisplayName($ownerId) ?? '';
}

if (substr_count($mount->getMountPoint(), '/') < 3) {
Expand Down
Loading
Loading