Skip to content

Commit

Permalink
fix: fix carddav group-member-set propfind call (#2219)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Dec 27, 2018
1 parent 946abec commit 8e5a01a
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Enhancements:

Fixes:
* Fix exception when user is logged out (again)
* Fix carddav group-member-set propfind call

RELEASED VERSIONS:

Expand Down
26 changes: 24 additions & 2 deletions app/Models/CardDAV/Backends/MonicaPrincipalBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,28 @@ public function updatePrincipal($path, DAV\PropPatch $propPatch)
*/
public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof')
{
$result = [];
$principals = $this->getPrincipalsByPrefix($prefixPath);
if (! $principals) {
return $result;
}

foreach ($principals as $principal) {
$ok = false;
foreach ($searchProperties as $key => $value) {
if ($principal[$key] == $value) {
$ok = true;
} elseif ($test == 'allof') {
$ok = false;
break;
}
}
if ($ok) {
$result[] = $principal['uri'];
}
}

return $result;
}

/**
Expand All @@ -141,10 +163,10 @@ public function getGroupMemberSet($principal)
{
$principal = $this->getPrincipalByPath($principal);
if (! $principal) {
throw new \Sabre\DAV\Exception('Principal not found');
return [];
}

return $principal['uri'];
return [$principal['uri']];
}

/**
Expand Down
89 changes: 89 additions & 0 deletions tests/Api/Carddav/CarddavServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,93 @@ public function test_carddav_propfind_one_contact()

$response->assertSee("<d:response><d:href>/carddav/addressbooks/{$user->email}/contacts/{$contact->uuid}</d:href>");
}

/**
* @group carddav
*/
public function test_carddav_propfind_groupmemberset()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account->id,
]);

$response = $this->call('PROPFIND', "/carddav/principals/{$user->email}/", [], [], [],
[
'content-type' => 'application/xml; charset=utf-8',
],
'<propfind xmlns="DAV:"
xmlns:CAL="urn:ietf:params:xml:ns:caldav"
xmlns:CARD="urn:ietf:params:xml:ns:carddav">
<prop>
<CARD:addressbook-home-set />
<group-member-set />
</prop>
</propfind>'
);

$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');

$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav">'.
'<d:response>'.
"<d:href>/carddav/principals/{$user->email}/</d:href>".
'<d:propstat>'.
'<d:prop>'.
'<card:addressbook-home-set>'.
"<d:href>/carddav/addressbooks/{$user->email}/</d:href>".
'</card:addressbook-home-set>'.
'<d:group-member-set>'.
"<d:href>/carddav/principals/{$user->email}/</d:href>".
'</d:group-member-set>'.
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>'.
'</d:multistatus>');
}

/**
* @group carddav
*/
public function test_carddav_report_propertysearch()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account->id,
]);

$response = $this->call('REPORT', '/carddav/principals/', [], [], [],
[
'HTTP_DEPTH' => '0',
'content-type' => 'application/xml; charset=utf-8',
],
"<principal-property-search xmlns=\"DAV:\">
<property-search>
<match>{$user->name}</match>
<prop>
<displayname/>
</prop>
</property-search>
<prop>
<displayname/>
</prop>
</principal-property-search>"
);

$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');

$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav">'.
'<d:response>'.
"<d:href>/carddav/principals/{$user->email}/</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<d:displayname>{$user->name}</d:displayname>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>'.
'</d:multistatus>');
}
}

0 comments on commit 8e5a01a

Please sign in to comment.