diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-02-27 16:54:07 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-03-09 13:12:18 +0100 |
commit | ec245d5feccc63abae3944c2ed59c99fbad3e6d7 (patch) | |
tree | f2d5b6bfe21649707b7edd05f516a1572b593d05 /apps/dav/lib/CardDAV/UserAddressBooks.php | |
parent | ac03f54079535fd9e047fbe3fbbe2a5768eb6e83 (diff) | |
download | nextcloud-server-ec245d5feccc63abae3944c2ed59c99fbad3e6d7.tar.gz nextcloud-server-ec245d5feccc63abae3944c2ed59c99fbad3e6d7.zip |
Add address book plugins
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/dav/lib/CardDAV/UserAddressBooks.php')
-rw-r--r-- | apps/dav/lib/CardDAV/UserAddressBooks.php | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/apps/dav/lib/CardDAV/UserAddressBooks.php b/apps/dav/lib/CardDAV/UserAddressBooks.php index 3ba20cfffac..f3803cf1692 100644 --- a/apps/dav/lib/CardDAV/UserAddressBooks.php +++ b/apps/dav/lib/CardDAV/UserAddressBooks.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright Copyright (c) 2016, ownCloud, Inc. * @@ -24,8 +27,10 @@ namespace OCA\DAV\CardDAV; +use OCA\DAV\AppInfo\PluginManager; use OCP\IConfig; use OCP\IL10N; +use Sabre\CardDAV\Backend; class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome { @@ -35,8 +40,18 @@ class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome { /** @var IConfig */ protected $config; + /** @var PluginManager */ + private $pluginManager; + + public function __construct(Backend\BackendInterface $carddavBackend, + string $principalUri, + PluginManager $pluginManager) { + parent::__construct($carddavBackend, $principalUri); + $this->pluginManager = $pluginManager; + } + /** - * Returns a list of addressbooks + * Returns a list of address books * * @return array */ @@ -49,13 +64,15 @@ class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome { } $addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); - $objects = []; - foreach($addressBooks as $addressBook) { + $objects = array_map(function(array $addressBook) { if ($addressBook['principaluri'] === 'principals/system/system') { - $objects[] = new SystemAddressbook($this->carddavBackend, $addressBook, $this->l10n, $this->config); - } else { - $objects[] = new AddressBook($this->carddavBackend, $addressBook, $this->l10n); + return new SystemAddressbook($this->carddavBackend, $addressBook, $this->l10n, $this->config); } + + return new AddressBook($this->carddavBackend, $addressBook, $this->l10n); + }, $addressBooks); + foreach ($this->pluginManager->getAddressBookPlugins() as $plugin) { + $plugin->fetchAllForAddressBookHome($this->principalUri); } return $objects; @@ -78,9 +95,9 @@ class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome { $acl = parent::getACL(); if ($this->principalUri === 'principals/system/system') { $acl[] = [ - 'privilege' => '{DAV:}read', - 'principal' => '{DAV:}authenticated', - 'protected' => true, + 'privilege' => '{DAV:}read', + 'principal' => '{DAV:}authenticated', + 'protected' => true, ]; } |