Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] chore(absence): Add capability #49595

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions apps/dav/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, absence-replacement?: bool}}
*/
public function getCapabilities() {
$capabilities = [
Expand All @@ -27,6 +30,10 @@ public function getCapabilities() {
if ($this->config->getSystemValueBool('bulkupload.enabled', true)) {
$capabilities['dav']['bulkupload'] = '1.0';
}
if ($this->coordinator->isEnabled()) {
$capabilities['dav']['absence-supported'] = true;
$capabilities['dav']['absence-replacement'] = true;
}
return $capabilities;
}
}
6 changes: 6 additions & 0 deletions apps/dav/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
},
"bulkupload": {
"type": "string"
},
"absence-supported": {
"type": "boolean"
},
"absence-replacement": {
"type": "boolean"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
use OCA\DAV\Capabilities;
use Test\TestCase;

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

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

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

/**
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -43,4 +52,25 @@ 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,
'absence-replacement' => true,
],
];
$this->assertSame($expected, $capabilities->getCapabilities());
}
}
Loading