RootCollection.php 7.1 KB

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