RootCollection.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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;
  8. use OC\KnownUser\KnownUserService;
  9. use OCA\DAV\AppInfo\PluginManager;
  10. use OCA\DAV\CalDAV\CalDavBackend;
  11. use OCA\DAV\CalDAV\CalendarRoot;
  12. use OCA\DAV\CalDAV\Principal\Collection;
  13. use OCA\DAV\CalDAV\Proxy\ProxyMapper;
  14. use OCA\DAV\CalDAV\PublicCalendarRoot;
  15. use OCA\DAV\CalDAV\ResourceBooking\ResourcePrincipalBackend;
  16. use OCA\DAV\CalDAV\ResourceBooking\RoomPrincipalBackend;
  17. use OCA\DAV\CalDAV\Sharing\Backend;
  18. use OCA\DAV\CardDAV\AddressBookRoot;
  19. use OCA\DAV\CardDAV\CardDavBackend;
  20. use OCA\DAV\Connector\Sabre\Principal;
  21. use OCA\DAV\DAV\GroupPrincipalBackend;
  22. use OCA\DAV\DAV\SystemPrincipalBackend;
  23. use OCA\DAV\Provisioning\Apple\AppleProvisioningNode;
  24. use OCA\DAV\SystemTag\SystemTagsByIdCollection;
  25. use OCA\DAV\SystemTag\SystemTagsInUseCollection;
  26. use OCA\DAV\SystemTag\SystemTagsRelationsCollection;
  27. use OCA\DAV\Upload\CleanupService;
  28. use OCP\Accounts\IAccountManager;
  29. use OCP\App\IAppManager;
  30. use OCP\AppFramework\Utility\ITimeFactory;
  31. use OCP\EventDispatcher\IEventDispatcher;
  32. use OCP\Files\IRootFolder;
  33. use OCP\IConfig;
  34. use OCP\Server;
  35. use Psr\Log\LoggerInterface;
  36. use Sabre\DAV\SimpleCollection;
  37. class RootCollection extends SimpleCollection {
  38. public function __construct() {
  39. $l10n = \OC::$server->getL10N('dav');
  40. $random = \OC::$server->getSecureRandom();
  41. $logger = \OC::$server->get(LoggerInterface::class);
  42. $userManager = \OC::$server->getUserManager();
  43. $userSession = \OC::$server->getUserSession();
  44. $groupManager = \OC::$server->getGroupManager();
  45. $shareManager = \OC::$server->getShareManager();
  46. $db = \OC::$server->getDatabaseConnection();
  47. $dispatcher = \OC::$server->get(IEventDispatcher::class);
  48. $config = \OC::$server->get(IConfig::class);
  49. $proxyMapper = \OC::$server->query(ProxyMapper::class);
  50. $rootFolder = Server::get(IRootFolder::class);
  51. $userPrincipalBackend = new Principal(
  52. $userManager,
  53. $groupManager,
  54. \OC::$server->get(IAccountManager::class),
  55. $shareManager,
  56. \OC::$server->getUserSession(),
  57. \OC::$server->getAppManager(),
  58. $proxyMapper,
  59. \OC::$server->get(KnownUserService::class),
  60. \OC::$server->getConfig(),
  61. \OC::$server->getL10NFactory()
  62. );
  63. $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager, $config);
  64. $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper);
  65. $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper);
  66. // as soon as debug mode is enabled we allow listing of principals
  67. $disableListing = !$config->getSystemValue('debug', false);
  68. // setup the first level of the dav tree
  69. $userPrincipals = new Collection($userPrincipalBackend, 'principals/users');
  70. $userPrincipals->disableListing = $disableListing;
  71. $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups');
  72. $groupPrincipals->disableListing = $disableListing;
  73. $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system');
  74. $systemPrincipals->disableListing = $disableListing;
  75. $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources');
  76. $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms');
  77. $calendarSharingBackend = \OC::$server->get(Backend::class);
  78. $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
  79. $filesCollection->disableListing = $disableListing;
  80. $caldavBackend = new CalDavBackend(
  81. $db,
  82. $userPrincipalBackend,
  83. $userManager,
  84. $random,
  85. $logger,
  86. $dispatcher,
  87. $config,
  88. $calendarSharingBackend,
  89. false,
  90. );
  91. $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users', $logger);
  92. $userCalendarRoot->disableListing = $disableListing;
  93. $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources', $logger);
  94. $resourceCalendarRoot->disableListing = $disableListing;
  95. $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $caldavBackend, 'principals/calendar-rooms', $logger);
  96. $roomCalendarRoot->disableListing = $disableListing;
  97. $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config, $logger);
  98. $systemTagCollection = Server::get(SystemTagsByIdCollection::class);
  99. $systemTagRelationsCollection = new SystemTagsRelationsCollection(
  100. \OC::$server->getSystemTagManager(),
  101. \OC::$server->getSystemTagObjectMapper(),
  102. \OC::$server->getUserSession(),
  103. $groupManager,
  104. $dispatcher,
  105. $rootFolder,
  106. );
  107. $systemTagInUseCollection = Server::get(SystemTagsInUseCollection::class);
  108. $commentsCollection = new Comments\RootCollection(
  109. \OC::$server->getCommentsManager(),
  110. $userManager,
  111. \OC::$server->getUserSession(),
  112. $dispatcher,
  113. $logger
  114. );
  115. $contactsSharingBackend = \OC::$server->get(\OCA\DAV\CardDAV\Sharing\Backend::class);
  116. $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class));
  117. $usersCardDavBackend = new CardDavBackend(
  118. $db,
  119. $userPrincipalBackend,
  120. $userManager,
  121. $dispatcher,
  122. $contactsSharingBackend,
  123. );
  124. $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/users');
  125. $usersAddressBookRoot->disableListing = $disableListing;
  126. $systemCardDavBackend = new CardDavBackend(
  127. $db,
  128. $userPrincipalBackend,
  129. $userManager,
  130. $dispatcher,
  131. $contactsSharingBackend,
  132. );
  133. $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/system');
  134. $systemAddressBookRoot->disableListing = $disableListing;
  135. $uploadCollection = new Upload\RootCollection(
  136. $userPrincipalBackend,
  137. 'principals/users',
  138. \OC::$server->query(CleanupService::class));
  139. $uploadCollection->disableListing = $disableListing;
  140. $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users');
  141. $avatarCollection->disableListing = $disableListing;
  142. $appleProvisioning = new AppleProvisioningNode(
  143. \OC::$server->query(ITimeFactory::class));
  144. $children = [
  145. new SimpleCollection('principals', [
  146. $userPrincipals,
  147. $groupPrincipals,
  148. $systemPrincipals,
  149. $calendarResourcePrincipals,
  150. $calendarRoomPrincipals]),
  151. $filesCollection,
  152. $userCalendarRoot,
  153. new SimpleCollection('system-calendars', [
  154. $resourceCalendarRoot,
  155. $roomCalendarRoot,
  156. ]),
  157. $publicCalendarRoot,
  158. new SimpleCollection('addressbooks', [
  159. $usersAddressBookRoot,
  160. $systemAddressBookRoot]),
  161. $systemTagCollection,
  162. $systemTagRelationsCollection,
  163. $systemTagInUseCollection,
  164. $commentsCollection,
  165. $uploadCollection,
  166. $avatarCollection,
  167. new SimpleCollection('provisioning', [
  168. $appleProvisioning
  169. ])
  170. ];
  171. parent::__construct('root', $children);
  172. }
  173. }