1
0

AddressBookRoot.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. * @author Anna Larch <anna.larch@gmx.net>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\DAV\CardDAV;
  26. use OCA\DAV\AppInfo\PluginManager;
  27. use OCP\IGroupManager;
  28. use OCP\IUser;
  29. class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot {
  30. /** @var PluginManager */
  31. private $pluginManager;
  32. private ?IUser $user;
  33. private ?IGroupManager $groupManager;
  34. /**
  35. * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend
  36. * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend
  37. * @param string $principalPrefix
  38. */
  39. public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend,
  40. \Sabre\CardDAV\Backend\BackendInterface $carddavBackend,
  41. PluginManager $pluginManager,
  42. ?IUser $user,
  43. ?IGroupManager $groupManager,
  44. string $principalPrefix = 'principals') {
  45. parent::__construct($principalBackend, $carddavBackend, $principalPrefix);
  46. $this->pluginManager = $pluginManager;
  47. $this->user = $user;
  48. $this->groupManager = $groupManager;
  49. }
  50. /**
  51. * This method returns a node for a principal.
  52. *
  53. * The passed array contains principal information, and is guaranteed to
  54. * at least contain a uri item. Other properties may or may not be
  55. * supplied by the authentication backend.
  56. *
  57. * @param array $principal
  58. *
  59. * @return \Sabre\DAV\INode
  60. */
  61. public function getChildForPrincipal(array $principal) {
  62. return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->pluginManager, $this->user, $this->groupManager);
  63. }
  64. public function getName() {
  65. if ($this->principalPrefix === 'principals') {
  66. return parent::getName();
  67. }
  68. // Grabbing all the components of the principal path.
  69. $parts = explode('/', $this->principalPrefix);
  70. // We are only interested in the second part.
  71. return $parts[1];
  72. }
  73. }