1
0

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\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. $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms');
  73. $calendarSharingBackend = \OC::$server->get(Backend::class);
  74. $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
  75. $filesCollection->disableListing = $disableListing;
  76. $caldavBackend = new CalDavBackend(
  77. $db,
  78. $userPrincipalBackend,
  79. $userManager,
  80. $random,
  81. $logger,
  82. $dispatcher,
  83. $config,
  84. $calendarSharingBackend,
  85. false,
  86. );
  87. $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users', $logger);
  88. $userCalendarRoot->disableListing = $disableListing;
  89. $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources', $logger);
  90. $resourceCalendarRoot->disableListing = $disableListing;
  91. $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $caldavBackend, 'principals/calendar-rooms', $logger);
  92. $roomCalendarRoot->disableListing = $disableListing;
  93. $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config, $logger);
  94. $systemTagCollection = new SystemTag\SystemTagsByIdCollection(
  95. \OC::$server->getSystemTagManager(),
  96. \OC::$server->getUserSession(),
  97. $groupManager
  98. );
  99. $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection(
  100. \OC::$server->getSystemTagManager(),
  101. \OC::$server->getSystemTagObjectMapper(),
  102. \OC::$server->getUserSession(),
  103. $groupManager,
  104. $dispatcher,
  105. $rootFolder,
  106. );
  107. $systemTagInUseCollection = \OCP\Server::get(SystemTag\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. }