Fix DI for federated file sharing controller

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2018-04-23 10:44:49 +02:00
parent 3ff041f86d
commit 093cd01ac2
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
3 changed files with 22 additions and 8 deletions

View File

@ -67,7 +67,8 @@ class Application extends App {
$notification, $notification,
$addressHandler, $addressHandler,
$server->getUserManager(), $server->getUserManager(),
$server->getCloudIdManager() $server->getCloudIdManager(),
$server->getLogger()
); );
}); });
} }

View File

@ -43,6 +43,7 @@ use OCP\Constants;
use OCP\Federation\ICloudIdManager; use OCP\Federation\ICloudIdManager;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\ILogger;
use OCP\IRequest; use OCP\IRequest;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\Share; use OCP\Share;
@ -74,6 +75,9 @@ class RequestHandlerController extends OCSController {
/** @var ICloudIdManager */ /** @var ICloudIdManager */
private $cloudIdManager; private $cloudIdManager;
/** @var ILogger */
private $logger;
/** /**
* Server2Server constructor. * Server2Server constructor.
* *
@ -95,7 +99,8 @@ class RequestHandlerController extends OCSController {
Notifications $notifications, Notifications $notifications,
AddressHandler $addressHandler, AddressHandler $addressHandler,
IUserManager $userManager, IUserManager $userManager,
ICloudIdManager $cloudIdManager ICloudIdManager $cloudIdManager,
ILogger $logger
) { ) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
@ -106,6 +111,7 @@ class RequestHandlerController extends OCSController {
$this->addressHandler = $addressHandler; $this->addressHandler = $addressHandler;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->cloudIdManager = $cloudIdManager; $this->cloudIdManager = $cloudIdManager;
$this->logger = $logger;
} }
/** /**
@ -140,14 +146,13 @@ class RequestHandlerController extends OCSController {
} }
// FIXME this should be a method in the user management instead // FIXME this should be a method in the user management instead
$logger = \OC::$server->getLogger(); $this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']);
$logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']);
\OCP\Util::emitHook( \OCP\Util::emitHook(
'\OCA\Files_Sharing\API\Server2Server', '\OCA\Files_Sharing\API\Server2Server',
'preLoginNameUsedAsUserName', 'preLoginNameUsedAsUserName',
array('uid' => &$shareWith) array('uid' => &$shareWith)
); );
$logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']); $this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']);
if (!\OC::$server->getUserManager()->userExists($shareWith)) { if (!\OC::$server->getUserManager()->userExists($shareWith)) {
throw new OCSException('User does not exists', 400); throw new OCSException('User does not exists', 400);
@ -210,7 +215,7 @@ class RequestHandlerController extends OCSController {
return new Http\DataResponse(); return new Http\DataResponse();
} catch (\Exception $e) { } catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, [ $this->logger->logException($e, [
'message' => 'Server can not add remote share.', 'message' => 'Server can not add remote share.',
'level' => \OCP\Util::ERROR, 'level' => \OCP\Util::ERROR,
'app' => 'files_sharing' 'app' => 'files_sharing'

View File

@ -38,6 +38,7 @@ use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService; use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse; use OCP\Http\Client\IResponse;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\Share\IShare; use OCP\Share\IShare;
@ -79,6 +80,9 @@ class RequestHandlerControllerTest extends TestCase {
/** @var ICloudIdManager */ /** @var ICloudIdManager */
private $cloudIdManager; private $cloudIdManager;
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
private $logger;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
@ -103,6 +107,8 @@ class RequestHandlerControllerTest extends TestCase {
$this->cloudIdManager = new CloudIdManager(); $this->cloudIdManager = new CloudIdManager();
$this->logger = $this->createMock(ILogger::class);
$this->s2s = new RequestHandlerController( $this->s2s = new RequestHandlerController(
'federatedfilesharing', 'federatedfilesharing',
\OC::$server->getRequest(), \OC::$server->getRequest(),
@ -112,7 +118,8 @@ class RequestHandlerControllerTest extends TestCase {
$this->notifications, $this->notifications,
$this->addressHandler, $this->addressHandler,
$this->userManager, $this->userManager,
$this->cloudIdManager $this->cloudIdManager,
$this->logger
); );
$this->connection = \OC::$server->getDatabaseConnection(); $this->connection = \OC::$server->getDatabaseConnection();
@ -177,7 +184,8 @@ class RequestHandlerControllerTest extends TestCase {
$this->notifications, $this->notifications,
$this->addressHandler, $this->addressHandler,
$this->userManager, $this->userManager,
$this->cloudIdManager $this->cloudIdManager,
$this->logger,
] ]
)->setMethods(['executeDeclineShare', 'verifyShare'])->getMock(); )->setMethods(['executeDeclineShare', 'verifyShare'])->getMock();