summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2017-04-24 09:17:55 +0200
committerGitHub <noreply@github.com>2017-04-24 09:17:55 +0200
commitd842b29c5b4074452433e81c2ceecb822a50364e (patch)
treed32922d78fd196f644aa212290e5b20b4a208be6
parent1c2cdc9d3aeae0cb1f2f5d4fe3c19f4666affddf (diff)
parentc89e057d2765f0e594224ec24fcc424b75a01a87 (diff)
downloadnextcloud-server-d842b29c5b4074452433e81c2ceecb822a50364e.tar.gz
nextcloud-server-d842b29c5b4074452433e81c2ceecb822a50364e.zip
Merge pull request #4401 from nextcloud/caldav-carddav-nc-owner-displayname
add owner-displayname property to calendars and addressbooks
-rw-r--r--apps/dav/lib/CalDAV/CalDavBackend.php30
-rw-r--r--apps/dav/lib/CardDAV/CardDavBackend.php49
-rw-r--r--apps/dav/lib/DAV/Sharing/Plugin.php1
-rw-r--r--apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php3
-rw-r--r--apps/dav/tests/unit/CalDAV/CalDavBackendTest.php2
-rw-r--r--apps/dav/tests/unit/CardDAV/CardDavBackendTest.php4
6 files changed, 77 insertions, 12 deletions
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php
index 631593974e7..a4fed4f1982 100644
--- a/apps/dav/lib/CalDAV/CalDavBackend.php
+++ b/apps/dav/lib/CalDAV/CalDavBackend.php
@@ -248,6 +248,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$calendar[$xmlName] = $row[$dbName];
}
+ $this->addOwnerPrincipal($calendar);
+
if (!isset($calendars[$calendar['id']])) {
$calendars[$calendar['id']] = $calendar;
}
@@ -319,6 +321,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$calendar[$xmlName] = $row[$dbName];
}
+ $this->addOwnerPrincipal($calendar);
+
$calendars[$calendar['id']] = $calendar;
}
$result->closeCursor();
@@ -359,6 +363,9 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
foreach($this->propertyMap as $xmlName=>$dbName) {
$calendar[$xmlName] = $row[$dbName];
}
+
+ $this->addOwnerPrincipal($calendar);
+
if (!isset($calendars[$calendar['id']])) {
$calendars[$calendar['id']] = $calendar;
}
@@ -428,6 +435,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$calendar[$xmlName] = $row[$dbName];
}
+ $this->addOwnerPrincipal($calendar);
+
if (!isset($calendars[$calendar['id']])) {
$calendars[$calendar['id']] = $calendar;
}
@@ -492,6 +501,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$calendar[$xmlName] = $row[$dbName];
}
+ $this->addOwnerPrincipal($calendar);
+
return $calendar;
}
@@ -543,6 +554,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$calendar[$xmlName] = $row[$dbName];
}
+ $this->addOwnerPrincipal($calendar);
+
return $calendar;
}
@@ -587,6 +600,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$calendar[$xmlName] = $row[$dbName];
}
+ $this->addOwnerPrincipal($calendar);
+
return $calendar;
}
@@ -1815,4 +1830,19 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
}
return $principalUri;
}
+
+ private function addOwnerPrincipal(&$calendarInfo) {
+ $ownerPrincipalKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal';
+ $displaynameKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname';
+ if (isset($calendarInfo[$ownerPrincipalKey])) {
+ $uri = $calendarInfo[$ownerPrincipalKey];
+ } else {
+ $uri = $calendarInfo['principaluri'];
+ }
+
+ $principalInformation = $this->principalBackend->getPrincipalByPath($uri);
+ if (isset($principalInformation['{DAV:}displayname'])) {
+ $calendarInfo[$displaynameKey] = $principalInformation['{DAV:}displayname'];
+ }
+ }
}
diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php
index f7963c0fa2b..cd010b87f08 100644
--- a/apps/dav/lib/CardDAV/CardDavBackend.php
+++ b/apps/dav/lib/CardDAV/CardDavBackend.php
@@ -155,6 +155,8 @@ class CardDavBackend implements BackendInterface, SyncSupport {
'{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
];
+
+ $this->addOwnerPrincipal($addressBooks[$row['id']]);
}
$result->closeCursor();
@@ -206,6 +208,8 @@ class CardDavBackend implements BackendInterface, SyncSupport {
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'],
$readOnlyPropertyName => $readOnly,
];
+
+ $this->addOwnerPrincipal($addressBooks[$row['id']]);
}
$result->closeCursor();
@@ -232,6 +236,8 @@ class CardDavBackend implements BackendInterface, SyncSupport {
'{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
];
+
+ $this->addOwnerPrincipal($addressBooks[$row['id']]);
}
$result->closeCursor();
@@ -268,7 +274,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
return null;
}
- return [
+ $addressBook = [
'id' => $row['id'],
'uri' => $row['uri'],
'principaluri' => $row['principaluri'],
@@ -277,6 +283,10 @@ class CardDavBackend implements BackendInterface, SyncSupport {
'{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
];
+
+ $this->addOwnerPrincipal($addressBook);
+
+ return $addressBook;
}
/**
@@ -298,15 +308,19 @@ class CardDavBackend implements BackendInterface, SyncSupport {
return null;
}
- return [
- 'id' => $row['id'],
- 'uri' => $row['uri'],
- 'principaluri' => $row['principaluri'],
- '{DAV:}displayname' => $row['displayname'],
- '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
- '{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
- '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
- ];
+ $addressBook = [
+ 'id' => $row['id'],
+ 'uri' => $row['uri'],
+ 'principaluri' => $row['principaluri'],
+ '{DAV:}displayname' => $row['displayname'],
+ '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
+ '{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
+ '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
+ ];
+
+ $this->addOwnerPrincipal($addressBook);
+
+ return $addressBook;
}
/**
@@ -1086,4 +1100,19 @@ class CardDavBackend implements BackendInterface, SyncSupport {
}
return $principalUri;
}
+
+ private function addOwnerPrincipal(&$addressbookInfo) {
+ $ownerPrincipalKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal';
+ $displaynameKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname';
+ if (isset($addressbookInfo[$ownerPrincipalKey])) {
+ $uri = $addressbookInfo[$ownerPrincipalKey];
+ } else {
+ $uri = $addressbookInfo['principaluri'];
+ }
+
+ $principalInformation = $this->principalBackend->getPrincipalByPath($uri);
+ if (isset($principalInformation['{DAV:}displayname'])) {
+ $addressbookInfo[$displaynameKey] = $principalInformation['{DAV:}displayname'];
+ }
+ }
}
diff --git a/apps/dav/lib/DAV/Sharing/Plugin.php b/apps/dav/lib/DAV/Sharing/Plugin.php
index 4cd95fe8a34..6f52721ac1e 100644
--- a/apps/dav/lib/DAV/Sharing/Plugin.php
+++ b/apps/dav/lib/DAV/Sharing/Plugin.php
@@ -37,6 +37,7 @@ use Sabre\HTTP\ResponseInterface;
class Plugin extends ServerPlugin {
const NS_OWNCLOUD = 'http://owncloud.org/ns';
+ const NS_NEXTCLOUD = 'http://nextcloud.com/ns';
/** @var Auth */
private $auth;
diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
index ffdba9c5c8a..bc161b00d91 100644
--- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
@@ -68,7 +68,8 @@ abstract class AbstractCalDavBackendTest extends TestCase {
->getMock();
$this->principal->expects($this->any())->method('getPrincipalByPath')
->willReturn([
- 'uri' => 'principals/best-friend'
+ 'uri' => 'principals/best-friend',
+ '{DAV:}displayname' => 'User\'s displayname',
]);
$this->principal->expects($this->any())->method('getGroupMembership')
->withAnyParameters()
diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
index 63ca03b0d3d..5adda30c19d 100644
--- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
@@ -61,6 +61,7 @@ class CalDavBackendTest extends AbstractCalDavBackendTest {
$this->assertCount(1, $calendars);
$this->assertEquals('Unit test', $calendars[0]['{DAV:}displayname']);
$this->assertEquals('Calendar used for unit testing', $calendars[0]['{urn:ietf:params:xml:ns:caldav}calendar-description']);
+ $this->assertEquals('User\'s displayname', $calendars[0]['{http://nextcloud.com/ns}owner-displayname']);
// delete the address book
$this->dispatcher->expects($this->at(0))
@@ -410,6 +411,7 @@ EOD;
$publicCalendars = $this->backend->getPublicCalendars();
$this->assertCount(1, $publicCalendars);
$this->assertEquals(true, $publicCalendars[0]['{http://owncloud.org/ns}public']);
+ $this->assertEquals('User\'s displayname', $publicCalendars[0]['{http://nextcloud.com/ns}owner-displayname']);
$publicCalendarURI = $publicCalendars[0]['uri'];
$publicCalendar = $this->backend->getPublicCalendar($publicCalendarURI);
diff --git a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
index a4445217469..c108432d65b 100644
--- a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
+++ b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
@@ -82,7 +82,8 @@ class CardDavBackendTest extends TestCase {
->getMock();
$this->principal->method('getPrincipalByPath')
->willReturn([
- 'uri' => 'principals/best-friend'
+ 'uri' => 'principals/best-friend',
+ '{DAV:}displayname' => 'User\'s displayname',
]);
$this->principal->method('getGroupMembership')
->withAnyParameters()
@@ -123,6 +124,7 @@ class CardDavBackendTest extends TestCase {
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
$this->assertEquals(1, count($books));
$this->assertEquals('Example', $books[0]['{DAV:}displayname']);
+ $this->assertEquals('User\'s displayname', $books[0]['{http://nextcloud.com/ns}owner-displayname']);
// update it's display name
$patch = new PropPatch([