Skip to content

Commit

Permalink
chore(absence): Add capability for absence api
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <[email protected]>
  • Loading branch information
SystemKeeper committed Dec 5, 2024
1 parent ce56897 commit 1c198aa
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
10 changes: 8 additions & 2 deletions apps/dav/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,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 = [
Expand All @@ -46,6 +49,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;
}
}
3 changes: 3 additions & 0 deletions apps/dav/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
},
"bulkupload": {
"type": "string"
},
"absence-supported": {
"type": "boolean"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
use OCA\DAV\Capabilities;
use Test\TestCase;

/**
* @group DB
*/
class NotificationProviderManagerTest extends TestCase {

/** @var NotificationProviderManager|\PHPUnit\Framework\MockObject\MockObject */
Expand Down
33 changes: 31 additions & 2 deletions apps/dav/tests/unit/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use OCA\DAV\Capabilities;
use OCP\IConfig;
use OCP\User\IAvailabilityCoordinator;
use Test\TestCase;

/**
Expand All @@ -37,7 +38,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',
Expand All @@ -52,7 +57,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',
Expand All @@ -61,4 +70,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());
}
}

0 comments on commit 1c198aa

Please sign in to comment.