From 235e1fb878529938b6ff459172bd12d1c016e46e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sun, 1 Dec 2024 22:22:38 +0100 Subject: [PATCH] chore(absence): Add capability for absence api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- apps/dav/lib/Capabilities.php | 10 ++++-- apps/dav/openapi.json | 3 ++ .../NotificationProviderManagerTest.php | 3 ++ apps/dav/tests/unit/CapabilitiesTest.php | 33 +++++++++++++++++-- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/apps/dav/lib/Capabilities.php b/apps/dav/lib/Capabilities.php index 1de64e16e4101..63f10eab58fe3 100644 --- a/apps/dav/lib/Capabilities.php +++ b/apps/dav/lib/Capabilities.php @@ -7,16 +7,19 @@ use OCP\Capabilities\ICapability; use OCP\IConfig; +use OCP\User\IAvailabilityCoordinator; class Capabilities implements ICapability { private IConfig $config; + private IAvailabilityCoordinator $coordinator; - public function __construct(IConfig $config) { + public function __construct(IConfig $config, IAvailabilityCoordinator $coordinator) { $this->config = $config; + $this->coordinator = $coordinator; } /** - * @return array{dav: array{chunking: string, bulkupload?: string}} + * @return array{dav: array{chunking: string, bulkupload?: string, absence-supported?: bool}} */ public function getCapabilities() { $capabilities = [ @@ -27,6 +30,9 @@ public function getCapabilities() { if ($this->config->getSystemValueBool('bulkupload.enabled', true)) { $capabilities['dav']['bulkupload'] = '1.0'; } + if ($this->coordinator->isEnabled()) { + $capabilities['dav']['absence-supported'] = true; + } return $capabilities; } } diff --git a/apps/dav/openapi.json b/apps/dav/openapi.json index 7045a7f9b274c..e212796304d42 100644 --- a/apps/dav/openapi.json +++ b/apps/dav/openapi.json @@ -37,6 +37,9 @@ }, "bulkupload": { "type": "string" + }, + "absence-supported": { + "type": "boolean" } } } diff --git a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProviderManagerTest.php b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProviderManagerTest.php index 98d49552b0207..662bb89e6f5e1 100644 --- a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProviderManagerTest.php +++ b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProviderManagerTest.php @@ -16,6 +16,9 @@ use OCA\DAV\Capabilities; use Test\TestCase; +/** + * @group DB + */ class NotificationProviderManagerTest extends TestCase { /** @var NotificationProviderManager|\PHPUnit\Framework\MockObject\MockObject */ diff --git a/apps/dav/tests/unit/CapabilitiesTest.php b/apps/dav/tests/unit/CapabilitiesTest.php index acdfb4a244324..4a2d7e8dba692 100644 --- a/apps/dav/tests/unit/CapabilitiesTest.php +++ b/apps/dav/tests/unit/CapabilitiesTest.php @@ -7,6 +7,7 @@ use OCA\DAV\Capabilities; use OCP\IConfig; +use OCP\User\IAvailabilityCoordinator; use Test\TestCase; /** @@ -19,7 +20,11 @@ public function testGetCapabilities(): void { ->method('getSystemValueBool') ->with('bulkupload.enabled', $this->isType('bool')) ->willReturn(false); - $capabilities = new Capabilities($config); + $coordinator = $this->createMock(IAvailabilityCoordinator::class); + $coordinator->expects($this->once()) + ->method('isEnabled') + ->willReturn(false); + $capabilities = new Capabilities($config, $coordinator); $expected = [ 'dav' => [ 'chunking' => '1.0', @@ -34,7 +39,11 @@ public function testGetCapabilitiesWithBulkUpload(): void { ->method('getSystemValueBool') ->with('bulkupload.enabled', $this->isType('bool')) ->willReturn(true); - $capabilities = new Capabilities($config); + $coordinator = $this->createMock(IAvailabilityCoordinator::class); + $coordinator->expects($this->once()) + ->method('isEnabled') + ->willReturn(false); + $capabilities = new Capabilities($config, $coordinator); $expected = [ 'dav' => [ 'chunking' => '1.0', @@ -43,4 +52,24 @@ public function testGetCapabilitiesWithBulkUpload(): void { ]; $this->assertSame($expected, $capabilities->getCapabilities()); } + + public function testGetCapabilitiesWithAbsence(): void { + $config = $this->createMock(IConfig::class); + $config->expects($this->once()) + ->method('getSystemValueBool') + ->with('bulkupload.enabled', $this->isType('bool')) + ->willReturn(false); + $coordinator = $this->createMock(IAvailabilityCoordinator::class); + $coordinator->expects($this->once()) + ->method('isEnabled') + ->willReturn(true); + $capabilities = new Capabilities($config, $coordinator); + $expected = [ + 'dav' => [ + 'chunking' => '1.0', + 'absence-supported' => true, + ], + ]; + $this->assertSame($expected, $capabilities->getCapabilities()); + } }