1
0

AddressBookRoot.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\CardDAV;
  8. use OCA\DAV\AppInfo\PluginManager;
  9. use OCP\IGroupManager;
  10. use OCP\IUser;
  11. class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot {
  12. /** @var PluginManager */
  13. private $pluginManager;
  14. private ?IUser $user;
  15. private ?IGroupManager $groupManager;
  16. /**
  17. * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend
  18. * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend
  19. * @param string $principalPrefix
  20. */
  21. public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend,
  22. \Sabre\CardDAV\Backend\BackendInterface $carddavBackend,
  23. PluginManager $pluginManager,
  24. ?IUser $user,
  25. ?IGroupManager $groupManager,
  26. string $principalPrefix = 'principals') {
  27. parent::__construct($principalBackend, $carddavBackend, $principalPrefix);
  28. $this->pluginManager = $pluginManager;
  29. $this->user = $user;
  30. $this->groupManager = $groupManager;
  31. }
  32. /**
  33. * This method returns a node for a principal.
  34. *
  35. * The passed array contains principal information, and is guaranteed to
  36. * at least contain a uri item. Other properties may or may not be
  37. * supplied by the authentication backend.
  38. *
  39. * @param array $principal
  40. *
  41. * @return \Sabre\DAV\INode
  42. */
  43. public function getChildForPrincipal(array $principal) {
  44. return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->pluginManager, $this->user, $this->groupManager);
  45. }
  46. public function getName() {
  47. if ($this->principalPrefix === 'principals') {
  48. return parent::getName();
  49. }
  50. // Grabbing all the components of the principal path.
  51. $parts = explode('/', $this->principalPrefix);
  52. // We are only interested in the second part.
  53. return $parts[1];
  54. }
  55. }