CalDAV and CardDAV plugins need to be registered for the principals collection as well

9f2e6431b8

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-04-23 13:54:58 +02:00
parent 240006bdf5
commit 69e650d0e8
No known key found for this signature in database
GPG key ID: F941078878347C0C
2 changed files with 29 additions and 15 deletions

View file

@ -71,7 +71,7 @@ class Server {
private $baseUri;
/** @var Connector\Sabre\Server */
private $server;
public $server;
public function __construct(IRequest $request, $baseUri) {
$this->request = $request;
@ -136,7 +136,7 @@ class Server {
$this->server->addPlugin($acl);
// calendar plugins
if ($this->requestIsForSubtree('calendars')) {
if ($this->requestIsForSubtree(['calendars', 'principals'])) {
$this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
$this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
$this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin());
@ -153,7 +153,8 @@ class Server {
}
// addressbook plugins
if ($this->requestIsForSubtree('addressbooks')) {
if ($this->requestIsForSubtree(['addressbooks', 'principals'])) {
$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
$this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
$this->server->addPlugin(new VCFExportPlugin());
$this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache'))));
@ -284,12 +285,13 @@ class Server {
$this->server->exec();
}
/**
* @param string $subTree
* @return bool
*/
private function requestIsForSubtree($subTree) {
$subTree = trim($subTree, " /");
return strpos($this->server->getRequestUri(), "$subTree/") === 0;
private function requestIsForSubtree(array $subTrees): bool {
foreach ($subTrees as $subTree) {
$subTree = trim($subTree, ' /');
if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) {
return true;
}
}
return false;
}
}

View file

@ -38,12 +38,24 @@ use OCA\DAV\AppInfo\PluginManager;
*/
class ServerTest extends \Test\TestCase {
public function test() {
/** @var IRequest $r */
/**
* @dataProvider providesUris
*/
public function test($uri, array $plugins) {
/** @var IRequest | \PHPUnit_Framework_MockObject_MockObject $r */
$r = $this->createMock(IRequest::class);
$r->method('getRequestUri')
->willReturn('/');
$r->expects($this->any())->method('getRequestUri')->willReturn($uri);
$s = new Server($r, '/');
$this->assertInstanceOf('OCA\DAV\Server', $s);
$this->assertNotNull($s->server);
foreach ($plugins as $plugin) {
$this->assertNotNull($s->server->getPlugin($plugin));
}
}
public function providesUris() {
return [
'principals' => ['principals/users/admin', ['caldav', 'oc-resource-sharing', 'carddav']],
'calendars' => ['calendars/admin', ['caldav', 'oc-resource-sharing']],
'addressbooks' => ['addressbooks/admin', ['carddav', 'oc-resource-sharing']],
];
}
}