diff options
-rw-r--r-- | apps/dav/lib/CardDAV/SyncService.php | 6 | ||||
-rw-r--r-- | apps/federation/lib/SyncFederationAddressBooks.php | 20 | ||||
-rw-r--r-- | apps/federation/lib/SyncJob.php | 17 | ||||
-rw-r--r-- | apps/federation/tests/SyncFederationAddressbooksTest.php | 20 | ||||
-rw-r--r-- | build/integration/composer.json | 2 | ||||
-rw-r--r-- | lib/private/AppFramework/Bootstrap/Coordinator.php | 2 | ||||
-rw-r--r-- | lib/private/AppFramework/Bootstrap/RegistrationContext.php | 4 | ||||
-rw-r--r-- | lib/private/Dashboard/Manager.php | 32 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/S3ObjectTrait.php | 9 | ||||
-rw-r--r-- | lib/public/Dashboard/IManager.php | 2 |
10 files changed, 72 insertions, 42 deletions
diff --git a/apps/dav/lib/CardDAV/SyncService.php b/apps/dav/lib/CardDAV/SyncService.php index 73bfaf01b60..021d6abea8b 100644 --- a/apps/dav/lib/CardDAV/SyncService.php +++ b/apps/dav/lib/CardDAV/SyncService.php @@ -99,9 +99,11 @@ class SyncService { if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { // remote server revoked access to the address book, remove it $this->backend->deleteAddressBook($addressBookId); - $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); - throw $ex; + $this->logger->error('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); + } else { + $this->logger->error('Client exception:', ['app' => 'dav', 'exception' => $ex]); } + throw $ex; } // 3. apply changes diff --git a/apps/federation/lib/SyncFederationAddressBooks.php b/apps/federation/lib/SyncFederationAddressBooks.php index ace5c07065a..f1803ad7864 100644 --- a/apps/federation/lib/SyncFederationAddressBooks.php +++ b/apps/federation/lib/SyncFederationAddressBooks.php @@ -29,6 +29,7 @@ use OC\OCS\DiscoveryService; use OCA\DAV\CardDAV\SyncService; use OCP\AppFramework\Http; use OCP\OCS\IDiscoveryService; +use Psr\Log\LoggerInterface; class SyncFederationAddressBooks { @@ -41,18 +42,18 @@ class SyncFederationAddressBooks { /** @var DiscoveryService */ private $ocsDiscoveryService; - /** - * @param DbHandler $dbHandler - * @param SyncService $syncService - * @param IDiscoveryService $ocsDiscoveryService - */ + /** @var LoggerInterface */ + private $logger; + public function __construct(DbHandler $dbHandler, SyncService $syncService, - IDiscoveryService $ocsDiscoveryService + IDiscoveryService $ocsDiscoveryService, + LoggerInterface $logger ) { $this->syncService = $syncService; $this->dbHandler = $dbHandler; $this->ocsDiscoveryService = $ocsDiscoveryService; + $this->logger = $logger; } /** @@ -71,6 +72,7 @@ class SyncFederationAddressBooks { $addressBookUrl = isset($endPoints['system-address-book']) ? trim($endPoints['system-address-book'], '/') : 'remote.php/dav/addressbooks/system/system/system'; if (is_null($sharedSecret)) { + $this->logger->error('Shared secret is null'); continue; } $targetBookId = $trustedServer['url_hash']; @@ -82,10 +84,16 @@ class SyncFederationAddressBooks { $newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties); if ($newToken !== $syncToken) { $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken); + } else { + $this->logger->info('Token unchanged from previous sync.'); } } catch (\Exception $ex) { if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_ACCESS_REVOKED); + $this->logger->error('Server sync failed because of revoked access.'); + } else { + $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_FAILURE); + $this->logger->error('Server sync failed.'); } $callback($url, $ex); } diff --git a/apps/federation/lib/SyncJob.php b/apps/federation/lib/SyncJob.php index f16d08a80d8..bbf346f3192 100644 --- a/apps/federation/lib/SyncJob.php +++ b/apps/federation/lib/SyncJob.php @@ -26,21 +26,20 @@ namespace OCA\Federation; use OC\BackgroundJob\TimedJob; -use OCP\ILogger; +use Psr\Log\LoggerInterface; class SyncJob extends TimedJob { /** @var SyncFederationAddressBooks */ protected $syncService; - /** @var ILogger */ + /** @var LoggerInterface */ protected $logger; /** * @param SyncFederationAddressBooks $syncService - * @param ILogger $logger */ - public function __construct(SyncFederationAddressBooks $syncService, ILogger $logger) { + public function __construct(SyncFederationAddressBooks $syncService, LoggerInterface $logger) { // Run once a day $this->setInterval(24 * 60 * 60); $this->syncService = $syncService; @@ -50,11 +49,11 @@ class SyncJob extends TimedJob { protected function run($argument) { $this->syncService->syncThemAll(function ($url, $ex) { if ($ex instanceof \Exception) { - $this->logger->logException($ex, [ - 'message' => "Error while syncing $url.", - 'level' => ILogger::INFO, - 'app' => 'fed-sync', - ]); + $this->logger->error("Error while syncing $url.", + [ + 'exception' => $ex + ] + ); } }); } diff --git a/apps/federation/tests/SyncFederationAddressbooksTest.php b/apps/federation/tests/SyncFederationAddressbooksTest.php index 36dd43e7cd2..b39a80d95e4 100644 --- a/apps/federation/tests/SyncFederationAddressbooksTest.php +++ b/apps/federation/tests/SyncFederationAddressbooksTest.php @@ -31,25 +31,31 @@ namespace OCA\Federation\Tests; use OC\OCS\DiscoveryService; use OCA\Federation\DbHandler; use OCA\Federation\SyncFederationAddressBooks; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; class SyncFederationAddressbooksTest extends \Test\TestCase { /** @var array */ private $callBacks = []; - /** @var \PHPUnit\Framework\MockObject\MockObject | DiscoveryService */ + /** @var MockObject | DiscoveryService */ private $discoveryService; + /** @var MockObject|LoggerInterface */ + private $logger; + protected function setUp(): void { parent::setUp(); $this->discoveryService = $this->getMockBuilder(DiscoveryService::class) ->disableOriginalConstructor()->getMock(); $this->discoveryService->expects($this->any())->method('discover')->willReturn([]); + $this->logger = $this->createMock(LoggerInterface::class); } public function testSync() { - /** @var DbHandler | \PHPUnit\Framework\MockObject\MockObject $dbHandler */ + /** @var DbHandler | MockObject $dbHandler */ $dbHandler = $this->getMockBuilder('OCA\Federation\DbHandler')-> disableOriginalConstructor()-> getMock(); @@ -62,8 +68,8 @@ class SyncFederationAddressbooksTest extends \Test\TestCase { 'sync_token' => '0' ] ]); - $dbHandler->expects($this->once())->method('setServerStatus')-> - with('https://cloud.drop.box', 1, '1'); + $dbHandler->expects($this->once())->method('setServerStatus') + ->with('https://cloud.drop.box', 1, '1'); $syncService = $this->getMockBuilder('OCA\DAV\CardDAV\SyncService') ->disableOriginalConstructor() ->getMock(); @@ -71,7 +77,7 @@ class SyncFederationAddressbooksTest extends \Test\TestCase { ->willReturn(1); /** @var \OCA\DAV\CardDAV\SyncService $syncService */ - $s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService); + $s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->logger); $s->syncThemAll(function ($url, $ex) { $this->callBacks[] = [$url, $ex]; }); @@ -79,7 +85,7 @@ class SyncFederationAddressbooksTest extends \Test\TestCase { } public function testException() { - /** @var DbHandler | \PHPUnit\Framework\MockObject\MockObject $dbHandler */ + /** @var DbHandler | MockObject $dbHandler */ $dbHandler = $this->getMockBuilder('OCA\Federation\DbHandler')-> disableOriginalConstructor()-> getMock(); @@ -99,7 +105,7 @@ class SyncFederationAddressbooksTest extends \Test\TestCase { ->willThrowException(new \Exception('something did not work out')); /** @var \OCA\DAV\CardDAV\SyncService $syncService */ - $s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService); + $s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->logger); $s->syncThemAll(function ($url, $ex) { $this->callBacks[] = [$url, $ex]; }); diff --git a/build/integration/composer.json b/build/integration/composer.json index cc8f1b9f292..6ce49514a16 100644 --- a/build/integration/composer.json +++ b/build/integration/composer.json @@ -4,7 +4,7 @@ "behat/behat": "~3.10.0", "guzzlehttp/guzzle": "6.5.8", "jarnaiz/behat-junit-formatter": "^1.3", - "sabre/dav": "4.3.1", + "sabre/dav": "4.4.0", "symfony/event-dispatcher": "~5.3" } } diff --git a/lib/private/AppFramework/Bootstrap/Coordinator.php b/lib/private/AppFramework/Bootstrap/Coordinator.php index 6e05b7fdc88..d68f9d507f1 100644 --- a/lib/private/AppFramework/Bootstrap/Coordinator.php +++ b/lib/private/AppFramework/Bootstrap/Coordinator.php @@ -143,7 +143,7 @@ class Coordinator { */ $this->registrationContext->delegateCapabilityRegistrations($apps); $this->registrationContext->delegateCrashReporterRegistrations($apps, $this->registry); - $this->registrationContext->delegateDashboardPanelRegistrations($apps, $this->dashboardManager); + $this->registrationContext->delegateDashboardPanelRegistrations($this->dashboardManager); $this->registrationContext->delegateEventListenerRegistrations($this->eventDispatcher); $this->registrationContext->delegateContainerRegistrations($apps); $this->registrationContext->delegateMiddlewareRegistrations($apps); diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php index 6a9073b576b..292d453d614 100644 --- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php +++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php @@ -394,10 +394,10 @@ class RegistrationContext { /** * @param App[] $apps */ - public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void { + public function delegateDashboardPanelRegistrations(IManager $dashboardManager): void { while (($panel = array_shift($this->dashboardPanels)) !== null) { try { - $dashboardManager->lazyRegisterWidget($panel->getService()); + $dashboardManager->lazyRegisterWidget($panel->getService(), $panel->getAppId()); } catch (Throwable $e) { $appId = $panel->getAppId(); $this->logger->error("Error during dashboard registration of $appId: " . $e->getMessage(), [ diff --git a/lib/private/Dashboard/Manager.php b/lib/private/Dashboard/Manager.php index a77c389cdeb..6a381d62bab 100644 --- a/lib/private/Dashboard/Manager.php +++ b/lib/private/Dashboard/Manager.php @@ -27,11 +27,12 @@ declare(strict_types=1); namespace OC\Dashboard; use InvalidArgumentException; -use OCP\AppFramework\QueryException; +use OCP\App\IAppManager; use OCP\Dashboard\IManager; use OCP\Dashboard\IWidget; use OCP\ILogger; -use OCP\IServerContainer; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\ContainerInterface; use Throwable; class Manager implements IManager { @@ -42,10 +43,13 @@ class Manager implements IManager { /** @var IWidget[] */ private $widgets = []; - /** @var IServerContainer */ + /** @var ContainerInterface */ private $serverContainer; - public function __construct(IServerContainer $serverContainer) { + /** @var ?IAppManager */ + private $appManager = null; + + public function __construct(ContainerInterface $serverContainer) { $this->serverContainer = $serverContainer; } @@ -57,17 +61,25 @@ class Manager implements IManager { $this->widgets[$widget->getId()] = $widget; } - public function lazyRegisterWidget(string $widgetClass): void { - $this->lazyWidgets[] = $widgetClass; + public function lazyRegisterWidget(string $widgetClass, string $appId): void { + $this->lazyWidgets[] = ['class' => $widgetClass, 'appId' => $appId]; } public function loadLazyPanels(): void { - $classes = $this->lazyWidgets; - foreach ($classes as $class) { + if ($this->appManager === null) { + $this->appManager = $this->serverContainer->get(IAppManager::class); + } + $services = $this->lazyWidgets; + foreach ($services as $service) { + /** @psalm-suppress InvalidCatch */ try { + if (!$this->appManager->isEnabledForUser($service['appId'])) { + // all apps are registered, but some may not be enabled for the user + continue; + } /** @var IWidget $widget */ - $widget = $this->serverContainer->query($class); - } catch (QueryException $e) { + $widget = $this->serverContainer->get($service['class']); + } catch (ContainerExceptionInterface $e) { /* * There is a circular dependency between the logger and the registry, so * we can not inject it. Thus the static call. diff --git a/lib/private/Files/ObjectStore/S3ObjectTrait.php b/lib/private/Files/ObjectStore/S3ObjectTrait.php index a92c5c139ea..0458079b66c 100644 --- a/lib/private/Files/ObjectStore/S3ObjectTrait.php +++ b/lib/private/Files/ObjectStore/S3ObjectTrait.php @@ -69,11 +69,14 @@ trait S3ObjectTrait { 'http' => [ 'protocol_version' => $request->getProtocolVersion(), 'header' => $headers, - ], - 'ssl' => [ - 'cafile' => $this->getCertificateBundlePath() ] ]; + $bundle = $this->getCertificateBundlePath(); + if ($bundle) { + $opts['ssl'] = [ + 'cafile' => $bundle + ]; + } if ($this->getProxy()) { $opts['http']['proxy'] = $this->getProxy(); diff --git a/lib/public/Dashboard/IManager.php b/lib/public/Dashboard/IManager.php index 396624876ef..d9e73c89eb9 100644 --- a/lib/public/Dashboard/IManager.php +++ b/lib/public/Dashboard/IManager.php @@ -36,7 +36,7 @@ interface IManager { * @param string $widgetClass * @since 20.0.0 */ - public function lazyRegisterWidget(string $widgetClass): void; + public function lazyRegisterWidget(string $widgetClass, string $appId): void; /** * @since 20.0.0 |