Use proper dependency injection for app manager

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2019-03-05 16:00:47 +01:00
parent 789aaa489d
commit dd2496b275
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
8 changed files with 26 additions and 7 deletions

View File

@ -47,6 +47,7 @@ $principalBackend = new Principal(
\OC::$server->getShareManager(), \OC::$server->getShareManager(),
\OC::$server->getUserSession(), \OC::$server->getUserSession(),
\OC::$server->getConfig(), \OC::$server->getConfig(),
\OC::$server->getAppManager(),
'principals/' 'principals/'
); );
$db = \OC::$server->getDatabaseConnection(); $db = \OC::$server->getDatabaseConnection();

View File

@ -48,6 +48,7 @@ $principalBackend = new Principal(
\OC::$server->getShareManager(), \OC::$server->getShareManager(),
\OC::$server->getUserSession(), \OC::$server->getUserSession(),
\OC::$server->getConfig(), \OC::$server->getConfig(),
\OC::$server->getAppManager(),
'principals/' 'principals/'
); );
$db = \OC::$server->getDatabaseConnection(); $db = \OC::$server->getDatabaseConnection();

View File

@ -78,7 +78,8 @@ class CreateCalendar extends Command {
$this->groupManager, $this->groupManager,
\OC::$server->getShareManager(), \OC::$server->getShareManager(),
\OC::$server->getUserSession(), \OC::$server->getUserSession(),
\OC::$server->getConfig() \OC::$server->getConfig(),
\OC::$server->getAppManager()
); );
$random = \OC::$server->getSecureRandom(); $random = \OC::$server->getSecureRandom();
$logger = \OC::$server->getLogger(); $logger = \OC::$server->getLogger();

View File

@ -35,6 +35,7 @@
namespace OCA\DAV\Connector\Sabre; namespace OCA\DAV\Connector\Sabre;
use OCA\Circles\Exceptions\CircleDoesNotExistException; use OCA\Circles\Exceptions\CircleDoesNotExistException;
use OCP\App\IAppManager;
use OCP\AppFramework\QueryException; use OCP\AppFramework\QueryException;
use OCP\IConfig; use OCP\IConfig;
use OCP\IGroup; use OCP\IGroup;
@ -64,6 +65,9 @@ class Principal implements BackendInterface {
/** @var IConfig */ /** @var IConfig */
private $config; private $config;
/** @var IAppManager */
private $appManager;
/** @var string */ /** @var string */
private $principalPrefix; private $principalPrefix;
@ -86,12 +90,14 @@ class Principal implements BackendInterface {
IShareManager $shareManager, IShareManager $shareManager,
IUserSession $userSession, IUserSession $userSession,
IConfig $config, IConfig $config,
IAppManager $appManager,
$principalPrefix = 'principals/users/') { $principalPrefix = 'principals/users/') {
$this->userManager = $userManager; $this->userManager = $userManager;
$this->groupManager = $groupManager; $this->groupManager = $groupManager;
$this->shareManager = $shareManager; $this->shareManager = $shareManager;
$this->userSession = $userSession; $this->userSession = $userSession;
$this->config = $config; $this->config = $config;
$this->appManager = $appManager;
$this->principalPrefix = trim($principalPrefix, '/'); $this->principalPrefix = trim($principalPrefix, '/');
$this->hasGroups = $this->hasCircles = ($principalPrefix === 'principals/users/'); $this->hasGroups = $this->hasCircles = ($principalPrefix === 'principals/users/');
} }
@ -404,7 +410,7 @@ class Principal implements BackendInterface {
* @suppress PhanUndeclaredClassCatch * @suppress PhanUndeclaredClassCatch
*/ */
protected function circleToPrincipal($circleUniqueId) { protected function circleToPrincipal($circleUniqueId) {
if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) { if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) {
return null; return null;
} }
@ -438,7 +444,7 @@ class Principal implements BackendInterface {
* @suppress PhanUndeclaredClassMethod * @suppress PhanUndeclaredClassMethod
*/ */
public function getCircleMembership($principal):array { public function getCircleMembership($principal):array {
if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) { if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) {
return []; return [];
} }

View File

@ -58,7 +58,8 @@ class RootCollection extends SimpleCollection {
$groupManager, $groupManager,
$shareManager, $shareManager,
\OC::$server->getUserSession(), \OC::$server->getUserSession(),
$config $config,
\OC::$server->getAppManager()
); );
$groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager, $l10n); $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager, $l10n);
$calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger); $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger);

View File

@ -29,6 +29,7 @@
namespace OCA\DAV\Tests\unit\Connector\Sabre; namespace OCA\DAV\Tests\unit\Connector\Sabre;
use OC\User\User; use OC\User\User;
use OCP\App\IAppManager;
use OCP\IConfig; use OCP\IConfig;
use OCP\IGroup; use OCP\IGroup;
use OCP\IGroupManager; use OCP\IGroupManager;
@ -59,19 +60,25 @@ class PrincipalTest extends TestCase {
/** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */ /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
private $config; private $config;
/** @var IAppManager | \PHPUnit_Framework_MockObject_MockObject */
private $appManager;
public function setUp() { public function setUp() {
$this->userManager = $this->createMock(IUserManager::class); $this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class); $this->groupManager = $this->createMock(IGroupManager::class);
$this->shareManager = $this->createMock(IManager::class); $this->shareManager = $this->createMock(IManager::class);
$this->userSession = $this->createMock(IUserSession::class); $this->userSession = $this->createMock(IUserSession::class);
$this->config = $this->createMock(IConfig::class); $this->config = $this->createMock(IConfig::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->connector = new \OCA\DAV\Connector\Sabre\Principal( $this->connector = new \OCA\DAV\Connector\Sabre\Principal(
$this->userManager, $this->userManager,
$this->groupManager, $this->groupManager,
$this->shareManager, $this->shareManager,
$this->userSession, $this->userSession,
$this->config); $this->config,
$this->appManager
);
parent::setUp(); parent::setUp();
} }

View File

@ -61,7 +61,8 @@ class Application extends App {
\OC::$server->getGroupManager(), \OC::$server->getGroupManager(),
\OC::$server->getShareManager(), \OC::$server->getShareManager(),
\OC::$server->getUserSession(), \OC::$server->getUserSession(),
\OC::$server->getConfig() \OC::$server->getConfig(),
\OC::$server->getAppManager()
); );
}); });

View File

@ -51,7 +51,8 @@ class Application extends App {
$server->getGroupManager(), $server->getGroupManager(),
$server->getShareManager(), $server->getShareManager(),
$server->getUserSession(), $server->getUserSession(),
$server->getConfig() $server->getConfig(),
$server->getAppManager()
); );
}); });