RootCollection.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 = new SystemTagsByIdCollection(
  99. \OC::$server->getSystemTagManager(),
  100. \OC::$server->getUserSession(),
  101. $groupManager
  102. );
  103. $systemTagRelationsCollection = new SystemTagsRelationsCollection(
  104. \OC::$server->getSystemTagManager(),
  105. \OC::$server->getSystemTagObjectMapper(),
  106. \OC::$server->getUserSession(),
  107. $groupManager,
  108. $dispatcher,
  109. $rootFolder,
  110. );
  111. $systemTagInUseCollection = Server::get(SystemTagsInUseCollection::class);
  112. $commentsCollection = new Comments\RootCollection(
  113. \OC::$server->getCommentsManager(),
  114. $userManager,
  115. \OC::$server->getUserSession(),
  116. $dispatcher,
  117. $logger
  118. );
  119. $contactsSharingBackend = \OC::$server->get(\OCA\DAV\CardDAV\Sharing\Backend::class);
  120. $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class));
  121. $usersCardDavBackend = new CardDavBackend(
  122. $db,
  123. $userPrincipalBackend,
  124. $userManager,
  125. $dispatcher,
  126. $contactsSharingBackend,
  127. );
  128. $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/users');
  129. $usersAddressBookRoot->disableListing = $disableListing;
  130. $systemCardDavBackend = new CardDavBackend(
  131. $db,
  132. $userPrincipalBackend,
  133. $userManager,
  134. $dispatcher,
  135. $contactsSharingBackend,
  136. );
  137. $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/system');
  138. $systemAddressBookRoot->disableListing = $disableListing;
  139. $uploadCollection = new Upload\RootCollection(
  140. $userPrincipalBackend,
  141. 'principals/users',
  142. \OC::$server->query(CleanupService::class));
  143. $uploadCollection->disableListing = $disableListing;
  144. $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users');
  145. $avatarCollection->disableListing = $disableListing;
  146. $appleProvisioning = new AppleProvisioningNode(
  147. \OC::$server->query(ITimeFactory::class));
  148. $children = [
  149. new SimpleCollection('principals', [
  150. $userPrincipals,
  151. $groupPrincipals,
  152. $systemPrincipals,
  153. $calendarResourcePrincipals,
  154. $calendarRoomPrincipals]),
  155. $filesCollection,
  156. $userCalendarRoot,
  157. new SimpleCollection('system-calendars', [
  158. $resourceCalendarRoot,
  159. $roomCalendarRoot,
  160. ]),
  161. $publicCalendarRoot,
  162. new SimpleCollection('addressbooks', [
  163. $usersAddressBookRoot,
  164. $systemAddressBookRoot]),
  165. $systemTagCollection,
  166. $systemTagRelationsCollection,
  167. $systemTagInUseCollection,
  168. $commentsCollection,
  169. $uploadCollection,
  170. $avatarCollection,
  171. new SimpleCollection('provisioning', [
  172. $appleProvisioning
  173. ])
  174. ];
  175. parent::__construct('root', $children);
  176. }
  177. }