diff options
author | Morris Jobke <hey@morrisjobke.de> | 2021-03-22 23:21:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-22 23:21:53 +0300 |
commit | 1eb084cfd37875adfe37301dcef7801634f7e28a (patch) | |
tree | 21855a42c198da8206df0a766d1983a3e12344de | |
parent | 268acd301dafa90917e30cea8370b9cc27b7a2c6 (diff) | |
parent | 2dac72ddea918c01495ba78e61cb1daf83daf33a (diff) |
Merge pull request #25498 from Worteks/feat-federatedfilesharing-logging
feat(federatedfilesharing): log errors, as suggested by @maxbes
-rw-r--r-- | apps/federatedfilesharing/lib/Notifications.php | 31 | ||||
-rw-r--r-- | apps/federatedfilesharing/tests/NotificationsTest.php | 7 | ||||
-rw-r--r-- | lib/private/Share20/ProviderFactory.php | 1 |
3 files changed, 39 insertions, 0 deletions
diff --git a/apps/federatedfilesharing/lib/Notifications.php b/apps/federatedfilesharing/lib/Notifications.php index 4689f048d85..68acfc98f8b 100644 --- a/apps/federatedfilesharing/lib/Notifications.php +++ b/apps/federatedfilesharing/lib/Notifications.php @@ -35,6 +35,7 @@ use OCP\Federation\ICloudFederationFactory; use OCP\Federation\ICloudFederationProviderManager; use OCP\Http\Client\IClientService; use OCP\OCS\IDiscoveryService; +use OCP\ILogger; class Notifications { public const RESPONSE_FORMAT = 'json'; // default response format for ocs calls @@ -60,10 +61,14 @@ class Notifications { /** @var IEventDispatcher */ private $eventDispatcher; + /** @var ILogger */ + private $logger; + public function __construct( AddressHandler $addressHandler, IClientService $httpClientService, IDiscoveryService $discoveryService, + ILogger $logger, IJobList $jobList, ICloudFederationProviderManager $federationProviderManager, ICloudFederationFactory $cloudFederationFactory, @@ -73,6 +78,7 @@ class Notifications { $this->httpClientService = $httpClientService; $this->discoveryService = $discoveryService; $this->jobList = $jobList; + $this->logger = $logger; $this->federationProviderManager = $federationProviderManager; $this->cloudFederationFactory = $cloudFederationFactory; $this->eventDispatcher = $eventDispatcher; @@ -123,7 +129,17 @@ class Notifications { $event = new FederatedShareAddedEvent($remote); $this->eventDispatcher->dispatchTyped($event); return true; + } else { + $this->logger->info( + "failed sharing $name with $shareWith", + ['app' => 'federatedfilesharing'] + ); } + } else { + $this->logger->info( + "could not share $name, invalid contact $shareWith", + ['app' => 'federatedfilesharing'] + ); } return false; @@ -174,6 +190,21 @@ class Notifications { $status['ocs']['data']['token'], $status['ocs']['data']['remoteId'] ]; + } elseif (!$validToken) { + $this->logger->info( + "invalid or missing token requesting re-share for $filename to $remote", + ['app' => 'federatedfilesharing'] + ); + } elseif (!$validRemoteId) { + $this->logger->info( + "missing remote id requesting re-share for $filename to $remote", + ['app' => 'federatedfilesharing'] + ); + } else { + $this->logger->info( + "failed requesting re-share for $filename to $remote", + ['app' => 'federatedfilesharing'] + ); } return false; diff --git a/apps/federatedfilesharing/tests/NotificationsTest.php b/apps/federatedfilesharing/tests/NotificationsTest.php index 4251f13f222..a1c06f09769 100644 --- a/apps/federatedfilesharing/tests/NotificationsTest.php +++ b/apps/federatedfilesharing/tests/NotificationsTest.php @@ -32,6 +32,7 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudFederationFactory; use OCP\Federation\ICloudFederationProviderManager; use OCP\Http\Client\IClientService; +use OCP\ILogger; use OCP\OCS\IDiscoveryService; class NotificationsTest extends \Test\TestCase { @@ -57,6 +58,9 @@ class NotificationsTest extends \Test\TestCase { /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ private $eventDispatcher; + /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + private $logger; + protected function setUp(): void { parent::setUp(); @@ -65,6 +69,7 @@ class NotificationsTest extends \Test\TestCase { $this->httpClientService = $this->getMockBuilder('OCP\Http\Client\IClientService')->getMock(); $this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler') ->disableOriginalConstructor()->getMock(); + $this->logger = $this->createMock(ILogger::class); $this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class); $this->cloudFederationFactory = $this->createMock(ICloudFederationFactory::class); $this->eventDispatcher = $this->createMock(IEventDispatcher::class); @@ -82,6 +87,7 @@ class NotificationsTest extends \Test\TestCase { $this->addressHandler, $this->httpClientService, $this->discoveryService, + $this->logger, $this->jobList, $this->cloudFederationProviderManager, $this->cloudFederationFactory, @@ -94,6 +100,7 @@ class NotificationsTest extends \Test\TestCase { $this->addressHandler, $this->httpClientService, $this->discoveryService, + $this->logger, $this->jobList, $this->cloudFederationProviderManager, $this->cloudFederationFactory, diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index 1998da1682f..0c59d39d6bc 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -138,6 +138,7 @@ class ProviderFactory implements IProviderFactory { $addressHandler, $this->serverContainer->getHTTPClientService(), $this->serverContainer->query(\OCP\OCS\IDiscoveryService::class), + $this->serverContainer->getLogger(), $this->serverContainer->getJobList(), \OC::$server->getCloudFederationProviderManager(), \OC::$server->getCloudFederationFactory(), |