diff options
author | Anna Larch <anna@nextcloud.com> | 2023-05-11 18:59:30 +0200 |
---|---|---|
committer | Anna Larch <anna@nextcloud.com> | 2023-05-11 18:59:30 +0200 |
commit | 5c2eb732f123c907201a2db36f12f0a269722ce7 (patch) | |
tree | 93f3ac458e66635c7546cf33c81080e00962d088 /apps/dav/lib/CardDAV/UserAddressBooks.php | |
parent | 9d2d3d482bce004d134dd87d7b37c3dfb6513412 (diff) | |
download | nextcloud-server-5c2eb732f123c907201a2db36f12f0a269722ce7.tar.gz nextcloud-server-5c2eb732f123c907201a2db36f12f0a269722ce7.zip |
fix(carddav): expose system address book
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'apps/dav/lib/CardDAV/UserAddressBooks.php')
-rw-r--r-- | apps/dav/lib/CardDAV/UserAddressBooks.php | 53 |
1 files changed, 44 insertions, 9 deletions
diff --git a/apps/dav/lib/CardDAV/UserAddressBooks.php b/apps/dav/lib/CardDAV/UserAddressBooks.php index 85795604f28..938575bd1a7 100644 --- a/apps/dav/lib/CardDAV/UserAddressBooks.php +++ b/apps/dav/lib/CardDAV/UserAddressBooks.php @@ -9,6 +9,7 @@ declare(strict_types=1); * @author Joas Schilling <coding@schilljs.com> * @author Roeland Jago Douma <roeland@famdouma.nl> * @author Thomas Müller <thomas.mueller@tmit.eu> + * @author Anna Larch <anna.larch@gmx.net> * * @license AGPL-3.0 * @@ -33,8 +34,11 @@ use OCA\DAV\CardDAV\Integration\ExternalAddressBook; use OCA\Federation\TrustedServers; use OCP\AppFramework\QueryException; use OCP\IConfig; +use OCP\IGroupManager; use OCP\IL10N; use OCP\IRequest; +use OCP\IUser; +use OCP\IUserSession; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use Sabre\CardDAV\Backend; @@ -44,7 +48,6 @@ use function array_map; use Sabre\DAV\MkCol; class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome { - /** @var IL10N */ protected $l10n; @@ -53,12 +56,18 @@ class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome { /** @var PluginManager */ private $pluginManager; + private ?IUser $user; + private ?IGroupManager $groupManager; public function __construct(Backend\BackendInterface $carddavBackend, string $principalUri, - PluginManager $pluginManager) { + PluginManager $pluginManager, + ?IUser $user, + ?IGroupManager $groupManager) { parent::__construct($carddavBackend, $principalUri); $this->pluginManager = $pluginManager; + $this->user = $user; + $this->groupManager = $groupManager; } /** @@ -74,10 +83,25 @@ class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome { $this->config = \OC::$server->getConfig(); } + /** @var string|array $principal */ + $principal = $this->principalUri; $addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); - /** @var IAddressBook[] $objects */ - $objects = array_map(function (array $addressBook) { - if ($addressBook['principaluri'] === 'principals/system/system') { + // add the system address book + $systemAddressBook = null; + if (is_string($principal) && $principal !== 'principals/system/system' && $this->carddavBackend instanceof CardDavBackend) { + $systemAddressBook = $this->carddavBackend->getAddressBooksByUri('principals/system/system', 'system'); + if ($systemAddressBook !== null) { + $systemAddressBook['uri'] = SystemAddressbook::URI_SHARED; + } + } + if (!is_null($systemAddressBook)) { + $addressBooks[] = $systemAddressBook; + } + + $objects = []; + if (!empty($addressBooks)) { + /** @var IAddressBook[] $objects */ + $objects = array_map(function (array $addressBook) { $trustedServers = null; $request = null; try { @@ -86,11 +110,22 @@ class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome { } catch (NotFoundExceptionInterface | ContainerExceptionInterface $e) { // nothing to do, the request / trusted servers don't exist } - return new SystemAddressbook($this->carddavBackend, $addressBook, $this->l10n, $this->config, $request, $trustedServers); - } + if ($addressBook['principaluri'] === 'principals/system/system') { + return new SystemAddressbook( + $this->carddavBackend, + $addressBook, + $this->l10n, + $this->config, + \OCP\Server::get(IUserSession::class), + $request, + $trustedServers, + $this->groupManager + ); + } - return new AddressBook($this->carddavBackend, $addressBook, $this->l10n); - }, $addressBooks); + return new AddressBook($this->carddavBackend, $addressBook, $this->l10n); + }, $addressBooks); + } /** @var IAddressBook[][] $objectsFromPlugins */ $objectsFromPlugins = array_map(function (IAddressBookProvider $plugin): array { return $plugin->fetchAllForAddressBookHome($this->principalUri); |