Merge pull request #25498 from Worteks/feat-federatedfilesharing-logging
feat(federatedfilesharing): log errors, as suggested by @maxbes
This commit is contained in:
commit
1eb084cfd3
|
@ -35,6 +35,7 @@ use OCP\Federation\ICloudFederationFactory;
|
||||||
use OCP\Federation\ICloudFederationProviderManager;
|
use OCP\Federation\ICloudFederationProviderManager;
|
||||||
use OCP\Http\Client\IClientService;
|
use OCP\Http\Client\IClientService;
|
||||||
use OCP\OCS\IDiscoveryService;
|
use OCP\OCS\IDiscoveryService;
|
||||||
|
use OCP\ILogger;
|
||||||
|
|
||||||
class Notifications {
|
class Notifications {
|
||||||
public const RESPONSE_FORMAT = 'json'; // default response format for ocs calls
|
public const RESPONSE_FORMAT = 'json'; // default response format for ocs calls
|
||||||
|
@ -60,10 +61,14 @@ class Notifications {
|
||||||
/** @var IEventDispatcher */
|
/** @var IEventDispatcher */
|
||||||
private $eventDispatcher;
|
private $eventDispatcher;
|
||||||
|
|
||||||
|
/** @var ILogger */
|
||||||
|
private $logger;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AddressHandler $addressHandler,
|
AddressHandler $addressHandler,
|
||||||
IClientService $httpClientService,
|
IClientService $httpClientService,
|
||||||
IDiscoveryService $discoveryService,
|
IDiscoveryService $discoveryService,
|
||||||
|
ILogger $logger,
|
||||||
IJobList $jobList,
|
IJobList $jobList,
|
||||||
ICloudFederationProviderManager $federationProviderManager,
|
ICloudFederationProviderManager $federationProviderManager,
|
||||||
ICloudFederationFactory $cloudFederationFactory,
|
ICloudFederationFactory $cloudFederationFactory,
|
||||||
|
@ -73,6 +78,7 @@ class Notifications {
|
||||||
$this->httpClientService = $httpClientService;
|
$this->httpClientService = $httpClientService;
|
||||||
$this->discoveryService = $discoveryService;
|
$this->discoveryService = $discoveryService;
|
||||||
$this->jobList = $jobList;
|
$this->jobList = $jobList;
|
||||||
|
$this->logger = $logger;
|
||||||
$this->federationProviderManager = $federationProviderManager;
|
$this->federationProviderManager = $federationProviderManager;
|
||||||
$this->cloudFederationFactory = $cloudFederationFactory;
|
$this->cloudFederationFactory = $cloudFederationFactory;
|
||||||
$this->eventDispatcher = $eventDispatcher;
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
|
@ -123,7 +129,17 @@ class Notifications {
|
||||||
$event = new FederatedShareAddedEvent($remote);
|
$event = new FederatedShareAddedEvent($remote);
|
||||||
$this->eventDispatcher->dispatchTyped($event);
|
$this->eventDispatcher->dispatchTyped($event);
|
||||||
return true;
|
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;
|
return false;
|
||||||
|
@ -174,6 +190,21 @@ class Notifications {
|
||||||
$status['ocs']['data']['token'],
|
$status['ocs']['data']['token'],
|
||||||
$status['ocs']['data']['remoteId']
|
$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;
|
return false;
|
||||||
|
|
|
@ -32,6 +32,7 @@ use OCP\EventDispatcher\IEventDispatcher;
|
||||||
use OCP\Federation\ICloudFederationFactory;
|
use OCP\Federation\ICloudFederationFactory;
|
||||||
use OCP\Federation\ICloudFederationProviderManager;
|
use OCP\Federation\ICloudFederationProviderManager;
|
||||||
use OCP\Http\Client\IClientService;
|
use OCP\Http\Client\IClientService;
|
||||||
|
use OCP\ILogger;
|
||||||
use OCP\OCS\IDiscoveryService;
|
use OCP\OCS\IDiscoveryService;
|
||||||
|
|
||||||
class NotificationsTest extends \Test\TestCase {
|
class NotificationsTest extends \Test\TestCase {
|
||||||
|
@ -57,6 +58,9 @@ class NotificationsTest extends \Test\TestCase {
|
||||||
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
|
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
|
||||||
private $eventDispatcher;
|
private $eventDispatcher;
|
||||||
|
|
||||||
|
/** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
|
||||||
|
private $logger;
|
||||||
|
|
||||||
protected function setUp(): void {
|
protected function setUp(): void {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
@ -65,6 +69,7 @@ class NotificationsTest extends \Test\TestCase {
|
||||||
$this->httpClientService = $this->getMockBuilder('OCP\Http\Client\IClientService')->getMock();
|
$this->httpClientService = $this->getMockBuilder('OCP\Http\Client\IClientService')->getMock();
|
||||||
$this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler')
|
$this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$this->logger = $this->createMock(ILogger::class);
|
||||||
$this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class);
|
$this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class);
|
||||||
$this->cloudFederationFactory = $this->createMock(ICloudFederationFactory::class);
|
$this->cloudFederationFactory = $this->createMock(ICloudFederationFactory::class);
|
||||||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||||
|
@ -82,6 +87,7 @@ class NotificationsTest extends \Test\TestCase {
|
||||||
$this->addressHandler,
|
$this->addressHandler,
|
||||||
$this->httpClientService,
|
$this->httpClientService,
|
||||||
$this->discoveryService,
|
$this->discoveryService,
|
||||||
|
$this->logger,
|
||||||
$this->jobList,
|
$this->jobList,
|
||||||
$this->cloudFederationProviderManager,
|
$this->cloudFederationProviderManager,
|
||||||
$this->cloudFederationFactory,
|
$this->cloudFederationFactory,
|
||||||
|
@ -94,6 +100,7 @@ class NotificationsTest extends \Test\TestCase {
|
||||||
$this->addressHandler,
|
$this->addressHandler,
|
||||||
$this->httpClientService,
|
$this->httpClientService,
|
||||||
$this->discoveryService,
|
$this->discoveryService,
|
||||||
|
$this->logger,
|
||||||
$this->jobList,
|
$this->jobList,
|
||||||
$this->cloudFederationProviderManager,
|
$this->cloudFederationProviderManager,
|
||||||
$this->cloudFederationFactory,
|
$this->cloudFederationFactory,
|
||||||
|
|
|
@ -138,6 +138,7 @@ class ProviderFactory implements IProviderFactory {
|
||||||
$addressHandler,
|
$addressHandler,
|
||||||
$this->serverContainer->getHTTPClientService(),
|
$this->serverContainer->getHTTPClientService(),
|
||||||
$this->serverContainer->query(\OCP\OCS\IDiscoveryService::class),
|
$this->serverContainer->query(\OCP\OCS\IDiscoveryService::class),
|
||||||
|
$this->serverContainer->getLogger(),
|
||||||
$this->serverContainer->getJobList(),
|
$this->serverContainer->getJobList(),
|
||||||
\OC::$server->getCloudFederationProviderManager(),
|
\OC::$server->getCloudFederationProviderManager(),
|
||||||
\OC::$server->getCloudFederationFactory(),
|
\OC::$server->getCloudFederationFactory(),
|
||||||
|
|
Loading…
Reference in New Issue