RootCollection.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Georg Ehrke <oc.list@georgehrke.com>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. * @author Vincent Petry <vincent@nextcloud.com>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. namespace OCA\DAV;
  29. use OC\KnownUser\KnownUserService;
  30. use OCA\DAV\AppInfo\PluginManager;
  31. use OCA\DAV\CalDAV\CalDavBackend;
  32. use OCA\DAV\CalDAV\CalendarRoot;
  33. use OCA\DAV\CalDAV\Principal\Collection;
  34. use OCA\DAV\CalDAV\Proxy\ProxyMapper;
  35. use OCA\DAV\CalDAV\PublicCalendarRoot;
  36. use OCA\DAV\CalDAV\ResourceBooking\ResourcePrincipalBackend;
  37. use OCA\DAV\CalDAV\ResourceBooking\RoomPrincipalBackend;
  38. use OCA\DAV\CardDAV\AddressBookRoot;
  39. use OCA\DAV\CardDAV\CardDavBackend;
  40. use OCA\DAV\Connector\Sabre\Principal;
  41. use OCA\DAV\DAV\GroupPrincipalBackend;
  42. use OCA\DAV\DAV\SystemPrincipalBackend;
  43. use OCA\DAV\Provisioning\Apple\AppleProvisioningNode;
  44. use OCA\DAV\Upload\CleanupService;
  45. use OCP\App\IAppManager;
  46. use OCP\AppFramework\Utility\ITimeFactory;
  47. use OCP\EventDispatcher\IEventDispatcher;
  48. use Sabre\DAV\SimpleCollection;
  49. class RootCollection extends SimpleCollection {
  50. public function __construct() {
  51. $config = \OC::$server->getConfig();
  52. $l10n = \OC::$server->getL10N('dav');
  53. $random = \OC::$server->getSecureRandom();
  54. $logger = \OC::$server->getLogger();
  55. $userManager = \OC::$server->getUserManager();
  56. $userSession = \OC::$server->getUserSession();
  57. $groupManager = \OC::$server->getGroupManager();
  58. $shareManager = \OC::$server->getShareManager();
  59. $db = \OC::$server->getDatabaseConnection();
  60. $dispatcher = \OC::$server->get(IEventDispatcher::class);
  61. $legacyDispatcher = \OC::$server->getEventDispatcher();
  62. $proxyMapper = \OC::$server->query(ProxyMapper::class);
  63. $userPrincipalBackend = new Principal(
  64. $userManager,
  65. $groupManager,
  66. $shareManager,
  67. \OC::$server->getUserSession(),
  68. \OC::$server->getAppManager(),
  69. $proxyMapper,
  70. \OC::$server->get(KnownUserService::class),
  71. \OC::$server->getConfig()
  72. );
  73. $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager, $config);
  74. $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper);
  75. $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper);
  76. // as soon as debug mode is enabled we allow listing of principals
  77. $disableListing = !$config->getSystemValue('debug', false);
  78. // setup the first level of the dav tree
  79. $userPrincipals = new Collection($userPrincipalBackend, 'principals/users');
  80. $userPrincipals->disableListing = $disableListing;
  81. $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups');
  82. $groupPrincipals->disableListing = $disableListing;
  83. $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system');
  84. $systemPrincipals->disableListing = $disableListing;
  85. $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources');
  86. $calendarResourcePrincipals->disableListing = $disableListing;
  87. $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms');
  88. $calendarRoomPrincipals->disableListing = $disableListing;
  89. $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
  90. $filesCollection->disableListing = $disableListing;
  91. $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher, $legacyDispatcher);
  92. $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users');
  93. $userCalendarRoot->disableListing = $disableListing;
  94. $resourceCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher, $legacyDispatcher);
  95. $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources');
  96. $resourceCalendarRoot->disableListing = $disableListing;
  97. $roomCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher, $legacyDispatcher);
  98. $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $roomCalendarCaldavBackend, 'principals/calendar-rooms');
  99. $roomCalendarRoot->disableListing = $disableListing;
  100. $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config);
  101. $publicCalendarRoot->disableListing = $disableListing;
  102. $systemTagCollection = new SystemTag\SystemTagsByIdCollection(
  103. \OC::$server->getSystemTagManager(),
  104. \OC::$server->getUserSession(),
  105. $groupManager
  106. );
  107. $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection(
  108. \OC::$server->getSystemTagManager(),
  109. \OC::$server->getSystemTagObjectMapper(),
  110. \OC::$server->getUserSession(),
  111. $groupManager,
  112. \OC::$server->getEventDispatcher()
  113. );
  114. $commentsCollection = new Comments\RootCollection(
  115. \OC::$server->getCommentsManager(),
  116. $userManager,
  117. \OC::$server->getUserSession(),
  118. \OC::$server->getEventDispatcher(),
  119. \OC::$server->getLogger()
  120. );
  121. $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class));
  122. $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher, $legacyDispatcher);
  123. $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, 'principals/users');
  124. $usersAddressBookRoot->disableListing = $disableListing;
  125. $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher, $legacyDispatcher);
  126. $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, 'principals/system');
  127. $systemAddressBookRoot->disableListing = $disableListing;
  128. $uploadCollection = new Upload\RootCollection(
  129. $userPrincipalBackend,
  130. 'principals/users',
  131. \OC::$server->query(CleanupService::class));
  132. $uploadCollection->disableListing = $disableListing;
  133. $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users');
  134. $avatarCollection->disableListing = $disableListing;
  135. $appleProvisioning = new AppleProvisioningNode(
  136. \OC::$server->query(ITimeFactory::class));
  137. $children = [
  138. new SimpleCollection('principals', [
  139. $userPrincipals,
  140. $groupPrincipals,
  141. $systemPrincipals,
  142. $calendarResourcePrincipals,
  143. $calendarRoomPrincipals]),
  144. $filesCollection,
  145. $userCalendarRoot,
  146. new SimpleCollection('system-calendars', [
  147. $resourceCalendarRoot,
  148. $roomCalendarRoot,
  149. ]),
  150. $publicCalendarRoot,
  151. new SimpleCollection('addressbooks', [
  152. $usersAddressBookRoot,
  153. $systemAddressBookRoot]),
  154. $systemTagCollection,
  155. $systemTagRelationsCollection,
  156. $commentsCollection,
  157. $uploadCollection,
  158. $avatarCollection,
  159. new SimpleCollection('provisioning', [
  160. $appleProvisioning
  161. ])
  162. ];
  163. parent::__construct('root', $children);
  164. }
  165. }