You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RootCollection.php 7.6KB

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