diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-27 13:14:55 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-12-02 09:14:41 +0100 |
commit | 6a2dde64009fdffc6483b920717721634348a12f (patch) | |
tree | 83f18063b86de35406dad2654690db0a16298e4c | |
parent | dcfd089a6caed18f040284802cb3fe7e5475c4c5 (diff) | |
download | nextcloud-server-6a2dde64009fdffc6483b920717721634348a12f.tar.gz nextcloud-server-6a2dde64009fdffc6483b920717721634348a12f.zip |
user and system addressbooks are now living in sub folders
-rw-r--r-- | apps/dav/command/syncsystemaddressbook.php | 3 | ||||
-rw-r--r-- | apps/dav/lib/carddav/addressbook.php | 4 | ||||
-rw-r--r-- | apps/dav/lib/carddav/addressbookroot.php | 12 | ||||
-rw-r--r-- | apps/dav/lib/carddav/plugin.php | 47 | ||||
-rw-r--r-- | apps/dav/lib/carddav/useraddressbooks.php | 12 | ||||
-rw-r--r-- | apps/dav/lib/rootcollection.php | 13 | ||||
-rw-r--r-- | apps/dav/lib/server.php | 2 |
7 files changed, 78 insertions, 15 deletions
diff --git a/apps/dav/command/syncsystemaddressbook.php b/apps/dav/command/syncsystemaddressbook.php index 3139813fc4f..460d398a8b7 100644 --- a/apps/dav/command/syncsystemaddressbook.php +++ b/apps/dav/command/syncsystemaddressbook.php @@ -100,6 +100,7 @@ class SyncSystemAddressBook extends Command { } } $progress->finish(); + $output->writeln(''); } protected function ensureSystemAddressBookExists() { @@ -107,7 +108,7 @@ class SyncSystemAddressBook extends Command { if (!is_null($book)) { return $book; } - $systemPrincipal = "principals/system"; + $systemPrincipal = "principals/system/system"; $this->backend->createAddressBook($systemPrincipal, 'system', [ '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' ]); diff --git a/apps/dav/lib/carddav/addressbook.php b/apps/dav/lib/carddav/addressbook.php index 41227088ece..1e6ecf622da 100644 --- a/apps/dav/lib/carddav/addressbook.php +++ b/apps/dav/lib/carddav/addressbook.php @@ -54,7 +54,7 @@ class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareableAddres function getACL() { $acl = parent::getACL(); - if ($this->getOwner() === 'principals/system') { + if ($this->getOwner() === 'principals/system/system') { $acl[] = [ 'privilege' => '{DAV:}read', 'principal' => '{DAV:}authenticated', @@ -67,7 +67,7 @@ class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareableAddres function getChildACL() { $acl = parent::getChildACL(); - if ($this->getOwner() === 'principals/system') { + if ($this->getOwner() === 'principals/system/system') { $acl[] = [ 'privilege' => '{DAV:}read', 'principal' => '{DAV:}authenticated', diff --git a/apps/dav/lib/carddav/addressbookroot.php b/apps/dav/lib/carddav/addressbookroot.php index ee99ac8d798..8c78d024556 100644 --- a/apps/dav/lib/carddav/addressbookroot.php +++ b/apps/dav/lib/carddav/addressbookroot.php @@ -20,4 +20,14 @@ class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot { } -}
\ No newline at end of file + function getName() { + + // Grabbing all the components of the principal path. + $parts = explode('/', $this->principalPrefix); + + // We are only interested in the second part. + return $parts[1]; + + } + +} diff --git a/apps/dav/lib/carddav/plugin.php b/apps/dav/lib/carddav/plugin.php new file mode 100644 index 00000000000..f2b3dcbfda9 --- /dev/null +++ b/apps/dav/lib/carddav/plugin.php @@ -0,0 +1,47 @@ +<?php +/** + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCA\DAV\CardDAV; + +use Sabre\HTTP\URLUtil; + +class Plugin extends \Sabre\CardDAV\Plugin { + + /** + * Returns the addressbook home for a given principal + * + * @param string $principal + * @return string + */ + protected function getAddressbookHomeForPrincipal($principal) { + + if (strrpos($principal, 'principals/users', -strlen($principal)) !== FALSE) { + list(, $principalId) = URLUtil::splitPath($principal); + return self::ADDRESSBOOK_ROOT . '/users/' . $principalId; + } + if (strrpos($principal, 'principals/system', -strlen($principal)) !== FALSE) { + list(, $principalId) = URLUtil::splitPath($principal); + return self::ADDRESSBOOK_ROOT . '/system/' . $principalId; + } + + throw new \LogicException('This is not supposed to happen'); + } +} diff --git a/apps/dav/lib/carddav/useraddressbooks.php b/apps/dav/lib/carddav/useraddressbooks.php index 2e630942e74..093cee0e1b2 100644 --- a/apps/dav/lib/carddav/useraddressbooks.php +++ b/apps/dav/lib/carddav/useraddressbooks.php @@ -11,12 +11,12 @@ class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome { */ function getChildren() { - $addressbooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); - $objs = []; - foreach($addressbooks as $addressbook) { - $objs[] = new AddressBook($this->carddavBackend, $addressbook); + $addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); + $objects = []; + foreach($addressBooks as $addressBook) { + $objects[] = new AddressBook($this->carddavBackend, $addressBook); } - return $objs; + return $objects; } @@ -35,7 +35,7 @@ class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome { function getACL() { $acl = parent::getACL(); - if ($this->principalUri === 'principals/system') { + if ($this->principalUri === 'principals/system/system') { $acl[] = [ 'privilege' => '{DAV:}read', 'principal' => '{DAV:}authenticated', diff --git a/apps/dav/lib/rootcollection.php b/apps/dav/lib/rootcollection.php index 11fdc7c9605..c1635c9cde5 100644 --- a/apps/dav/lib/rootcollection.php +++ b/apps/dav/lib/rootcollection.php @@ -34,10 +34,13 @@ class RootCollection extends SimpleCollection { $calendarRoot = new CalendarRoot($principalBackend, $caldavBackend, 'principals/users'); $calendarRoot->disableListing = $disableListing; - $cardDavBackend = new CardDavBackend(\OC::$server->getDatabaseConnection(), $principalBackend); + $usersCardDavBackend = new CardDavBackend($db, $principalBackend); + $usersAddressBookRoot = new AddressBookRoot($principalBackend, $usersCardDavBackend, 'principals/users'); + $usersAddressBookRoot->disableListing = $disableListing; - $addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend, 'principals/users'); - $addressBookRoot->disableListing = $disableListing; + $systemCardDavBackend = new CardDavBackend($db, $principalBackend); + $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system'); + $systemAddressBookRoot->disableListing = $disableListing; $children = [ new SimpleCollection('principals', [ @@ -45,7 +48,9 @@ class RootCollection extends SimpleCollection { $systemPrincipals]), $filesCollection, $calendarRoot, - $addressBookRoot, + new SimpleCollection('addressbooks', [ + $usersAddressBookRoot, + $systemAddressBookRoot]), ]; parent::__construct('root', $children); diff --git a/apps/dav/lib/server.php b/apps/dav/lib/server.php index ffdb917085e..a031f2c442b 100644 --- a/apps/dav/lib/server.php +++ b/apps/dav/lib/server.php @@ -58,7 +58,7 @@ class Server { $this->server->addPlugin(new CardDAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); // addressbook plugins - $this->server->addPlugin(new \Sabre\CardDAV\Plugin()); + $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); // Finder on OS X requires Class 2 WebDAV support (locking), since we do // not provide locking we emulate it using a fake locking plugin. |