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::getGroupManager #40153

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
22 changes: 12 additions & 10 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\IGroupManager;
use Psr\Log\LoggerInterface;

$application->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand());
Expand All @@ -73,7 +75,7 @@

if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
$application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager()));
$application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager(), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager(), \OC::$server->get(IGroupManager::class)));
$application->add(new OC\Core\Command\App\Install());
$application->add(new OC\Core\Command\App\GetPath());
$application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager()));
Expand Down Expand Up @@ -141,7 +143,7 @@
$util = new \OC\Encryption\Util(
$view,
\OC::$server->getUserManager(),
\OC::$server->getGroupManager(),
\OC::$server->get(IGroupManager::class),
\OC::$server->getConfig()
);
$application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot(
Expand Down Expand Up @@ -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\Add(\OC::$server->getUserManager(), \OC::$server->get(IGroupManager::class)));
$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(\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\ListCommand(\OC::$server->getUserManager(), \OC::$server->get(IGroupManager::class)));
$application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->get(IGroupManager::class)));
$application->add(new OC\Core\Command\User\SyncAccountDataCommand(\OC::$server->getUserManager(), \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\Add(\OC::$server->get(IGroupManager::class)));
$application->add(new OC\Core\Command\Group\Delete(\OC::$server->get(IGroupManager::class)));
$application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->get(IGroupManager::class)));
$application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->get(IGroupManager::class)));
$application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->get(IGroupManager::class)));
$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/AppFramework/DependencyInjection/DIContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
use OCP\Group\ISubAdmin;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IInitialStateService;
use OCP\IL10N;
use OCP\ILogger;
Expand Down Expand Up @@ -253,7 +254,7 @@ public function __construct(string $appName, array $urlParams = [], ServerContai
$server->get(LoggerInterface::class),
$c->get('AppName'),
$server->getUserSession()->isLoggedIn(),
$this->getUserId() !== null && $server->getGroupManager()->isAdmin($this->getUserId()),
$this->getUserId() !== null && $server->get(IGroupManager::class)->isAdmin($this->getUserId()),
$server->getUserSession()->getUser() !== null && $server->query(ISubAdmin::class)->isSubAdmin($server->getUserSession()->getUser()),
$server->getAppManager(),
$server->getL10N('lib'),
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\IGroupManager;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -85,7 +86,7 @@ public function wrapStorage($mountPoint, Storage $storage, IMountPoint $mount) {
$util = new Util(
new View(),
\OC::$server->getUserManager(),
\OC::$server->getGroupManager(),
\OC::$server->get(IGroupManager::class),
\OC::$server->getConfig()
);
$update = new Update(
Expand Down
3 changes: 2 additions & 1 deletion 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\IGroupManager;
use Psr\Log\LoggerInterface;

class HookManager {
Expand Down Expand Up @@ -75,7 +76,7 @@ private static function getUpdate(?string $owner = null): Update {
new Util(
new View(),
\OC::$server->getUserManager(),
\OC::$server->getGroupManager(),
\OC::$server->get(IGroupManager::class),
\OC::$server->getConfig()),
Filesystem::getMountManager(),
\OC::$server->getEncryptionManager(),
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\IGroupManager;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use OC\DB\Connection;
Expand Down Expand Up @@ -198,7 +199,7 @@ public static function getRepairSteps(): array {
new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()),
new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->get(LoggerInterface::class)),
new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()),
new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OCP\Server::get(ITimeFactory::class)),
new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->get(IGroupManager::class), \OC::$server->getNotificationManager(), \OCP\Server::get(ITimeFactory::class)),
new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OCP\Server::get(IManager::class)),
\OCP\Server::get(ResetGeneratedAvatarFlag::class),
\OCP\Server::get(EncryptionLegacyCipher::class),
Expand All @@ -223,7 +224,7 @@ public static function getRepairSteps(): array {
*/
public static function getExpensiveRepairSteps() {
return [
new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()),
new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->get(IGroupManager::class)),
\OC::$server->get(ValidatePhoneNumber::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 @@ -59,6 +59,7 @@
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Defaults;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -401,7 +402,7 @@ public function install($options) {
$config->setSystemValue('updater.release.channel', $vendorData['channel']);
}

$group = \OC::$server->getGroupManager()->createGroup('admin');
$group = \OC::$server->get(IGroupManager::class)->createGroup('admin');
if ($group instanceof IGroup) {
$group->addUser($user);
}
Expand Down
5 changes: 3 additions & 2 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\IGroupManager;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -198,7 +199,7 @@ public static function getItemSharedWithUser(string $itemType, string $itemSourc
$userObject = \OC::$server->getUserManager()->get($user);
$groups = [];
if ($userObject) {
$groups = \OC::$server->getGroupManager()->getUserGroupIds($userObject);
$groups = \OC::$server->get(IGroupManager::class)->getUserGroupIds($userObject);
}

if (!empty($groups)) {
Expand Down Expand Up @@ -406,7 +407,7 @@ public static function getItems($itemType, ?string $item = null, ?int $shareType
$user = \OC::$server->getUserManager()->get($shareWith);
$groups = [];
if ($user) {
$groups = \OC::$server->getGroupManager()->getUserGroupIds($user);
$groups = \OC::$server->get(IGroupManager::class)->getUserGroupIds($user);
}
if (!empty($groups)) {
$qb->orWhere($qb->expr()->andX(
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Share20/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use OCA\Talk\Share\RoomShareProvider;
use OCP\Defaults;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IGroupManager;
use OCP\IServerContainer;
use OCP\Share\IManager;
use OCP\Share\IProviderFactory;
Expand Down Expand Up @@ -98,7 +99,7 @@ protected function defaultShareProvider() {
$this->defaultProvider = new DefaultShareProvider(
$this->serverContainer->getDatabaseConnection(),
$this->serverContainer->getUserManager(),
$this->serverContainer->getGroupManager(),
$this->serverContainer->get(IGroupManager::class),
$this->serverContainer->getLazyRootFolder(),
$this->serverContainer->getMailer(),
$this->serverContainer->query(Defaults::class),
Expand Down
3 changes: 2 additions & 1 deletion lib/private/SystemTag/ManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace OC\SystemTag;

use OCP\EventDispatcher\IEventDispatcher;
use OCP\IGroupManager;
use OCP\IServerContainer;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagManagerFactory;
Expand Down Expand Up @@ -64,7 +65,7 @@ public function __construct(IServerContainer $serverContainer) {
public function getManager(): ISystemTagManager {
return new SystemTagManager(
$this->serverContainer->getDatabaseConnection(),
$this->serverContainer->getGroupManager(),
$this->serverContainer->get(IGroupManager::class),
$this->serverContainer->get(IEventDispatcher::class),
);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/private/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Defaults;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IInitialStateService;
use OCP\INavigationManager;
use OCP\IUserSession;
Expand Down Expand Up @@ -231,7 +232,7 @@ public function __construct($renderAs, $appId = '') {
\OC::$server->getSession(),
\OC::$server->getUserSession()->getUser(),
$this->config,
\OC::$server->getGroupManager(),
\OC::$server->get(IGroupManager::class),
\OC::$server->get(IniGetWrapper::class),
\OC::$server->getURLGenerator(),
\OC::$server->getCapabilitiesManager(),
Expand Down
3 changes: 2 additions & 1 deletion lib/private/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
use OCP\Group\Events\UserRemovedEvent;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IImage;
use OCP\IURLGenerator;
use OCP\IUser;
Expand Down Expand Up @@ -277,7 +278,7 @@ public function delete() {
if ($result) {
// FIXME: Feels like an hack - suggestions?

$groupManager = \OC::$server->getGroupManager();
$groupManager = \OC::$server->get(IGroupManager::class);
// We have to delete the user from all groups
foreach ($groupManager->getUserGroupIds($this) as $groupId) {
$group = $groupManager->get($groupId);
Expand Down
3 changes: 2 additions & 1 deletion lib/private/legacy/OC_App.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
use OCP\App\ManagerEvent;
use OCP\Authentication\IAlternativeLogin;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IGroupManager;
use OCP\ILogger;
use OC\AppFramework\Bootstrap\Coordinator;
use OC\App\DependencyAnalyzer;
Expand Down Expand Up @@ -266,7 +267,7 @@ public function enable(string $appId,

$appManager = \OC::$server->getAppManager();
if ($groups !== []) {
$groupManager = \OC::$server->getGroupManager();
$groupManager = \OC::$server->get(IGroupManager::class);
$groupsList = [];
foreach ($groups as $group) {
$groupItem = $groupManager->get($group);
Expand Down
3 changes: 2 additions & 1 deletion lib/private/legacy/OC_User.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

use OC\User\LoginException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUserManager;
use OCP\User\Events\BeforeUserLoggedInEvent;
Expand Down Expand Up @@ -323,7 +324,7 @@ public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) {
* @return bool
*/
public static function isAdminUser($uid) {
$group = \OC::$server->getGroupManager()->get('admin');
$group = \OC::$server->get(IGroupManager::class)->get('admin');
$user = \OC::$server->getUserManager()->get($uid);
if ($group && $user && $group->inGroup($user) && self::$incognitoMode === false) {
return true;
Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Command/Apps/AppsEnableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace Tests\Core\Command\Config;

use OC\Core\Command\App\Enable;
use OCP\IGroupManager;
use Symfony\Component\Console\Tester\CommandTester;
use Test\TestCase;

Expand All @@ -41,7 +42,7 @@ protected function setUp(): void {

$command = new Enable(
\OC::$server->getAppManager(),
\OC::$server->getGroupManager()
\OC::$server->get(IGroupManager::class)
);

$this->commandTester = new CommandTester($command);
Expand Down
5 changes: 3 additions & 2 deletions tests/lib/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OC\AppConfig;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
use OCP\IGroupManager;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -459,7 +460,7 @@ public function appConfigValuesProvider() {
*/
public function testEnabledApps($user, $expectedApps, $forceAll) {
$userManager = \OC::$server->getUserManager();
$groupManager = \OC::$server->getGroupManager();
$groupManager = \OC::$server->get(IGroupManager::class);
$user1 = $userManager->createUser(self::TEST_USER1, self::TEST_USER1);
$user2 = $userManager->createUser(self::TEST_USER2, self::TEST_USER2);
$user3 = $userManager->createUser(self::TEST_USER3, self::TEST_USER3);
Expand Down Expand Up @@ -558,7 +559,7 @@ private function registerAppConfig(AppConfig $appConfig) {
\OC::$server->getUserSession(),
\OC::$server->getConfig(),
$appConfig,
\OC::$server->getGroupManager(),
\OC::$server->get(IGroupManager::class),
\OC::$server->getMemCacheFactory(),
\OC::$server->get(IEventDispatcher::class),
\OC::$server->get(LoggerInterface::class)
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/Files/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use OCP\Files\Mount\IMountManager;
use OCP\Files\Storage\IStorage;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use OCP\Share\IShare;
Expand Down Expand Up @@ -99,7 +100,7 @@ protected function setUp(): void {

//login
$userManager = \OC::$server->getUserManager();
$groupManager = \OC::$server->getGroupManager();
$groupManager = \OC::$server->get(IGroupManager::class);
$this->user = 'test';
$this->userObject = $userManager->createUser('test', 'test');

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Share/ShareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ShareTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();

$this->groupManager = \OC::$server->getGroupManager();
$this->groupManager = \OC::$server->get(IGroupManager::class);
$this->userManager = \OC::$server->getUserManager();

$this->userManager->clearBackends();
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/Share20/DefaultShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2512,7 +2512,7 @@ public function testUserDeletedFromGroup($group, $user, $toDelete) {

public function testGetSharesInFolder() {
$userManager = \OC::$server->getUserManager();
$groupManager = \OC::$server->getGroupManager();
$groupManager = \OC::$server->get(IGroupManager::class);
$rootFolder = \OC::$server->getRootFolder();

$provider = new DefaultShareProvider(
Expand Down Expand Up @@ -2610,7 +2610,7 @@ public function testGetSharesInFolder() {

public function testGetAccessListNoCurrentAccessRequired() {
$userManager = \OC::$server->getUserManager();
$groupManager = \OC::$server->getGroupManager();
$groupManager = \OC::$server->get(IGroupManager::class);
$rootFolder = \OC::$server->getRootFolder();

$provider = new DefaultShareProvider(
Expand Down Expand Up @@ -2706,7 +2706,7 @@ public function testGetAccessListNoCurrentAccessRequired() {

public function testGetAccessListCurrentAccessRequired() {
$userManager = \OC::$server->getUserManager();
$groupManager = \OC::$server->getGroupManager();
$groupManager = \OC::$server->get(IGroupManager::class);
$rootFolder = \OC::$server->getRootFolder();

$provider = new DefaultShareProvider(
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/SubAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Group\Events\SubAdminAddedEvent;
use OCP\Group\Events\SubAdminRemovedEvent;
use OCP\IGroupManager;

/**
* @group DB
Expand Down Expand Up @@ -54,7 +55,7 @@ protected function setUp(): void {
$this->groups = [];

$this->userManager = \OC::$server->getUserManager();
$this->groupManager = \OC::$server->getGroupManager();
$this->groupManager = \OC::$server->get(IGroupManager::class);
$this->dbConn = \OC::$server->getDatabaseConnection();
$this->eventDispatcher = \OC::$server->get(IEventDispatcher::class);

Expand Down