RootCollection.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 Citharel <nextcloud@tcit.fr>
  11. * @author Thomas Müller <thomas.mueller@tmit.eu>
  12. * @author Vincent Petry <vincent@nextcloud.com>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OCA\DAV;
  30. use OC\KnownUser\KnownUserService;
  31. use OCA\DAV\AppInfo\PluginManager;
  32. use OCA\DAV\CalDAV\CalDavBackend;
  33. use OCA\DAV\CalDAV\CalendarRoot;
  34. use OCA\DAV\CalDAV\Principal\Collection;
  35. use OCA\DAV\CalDAV\Proxy\ProxyMapper;
  36. use OCA\DAV\CalDAV\PublicCalendarRoot;
  37. use OCA\DAV\CalDAV\ResourceBooking\ResourcePrincipalBackend;
  38. use OCA\DAV\CalDAV\ResourceBooking\RoomPrincipalBackend;
  39. use OCA\DAV\CardDAV\AddressBookRoot;
  40. use OCA\DAV\CardDAV\CardDavBackend;
  41. use OCA\DAV\Connector\Sabre\Principal;
  42. use OCA\DAV\DAV\GroupPrincipalBackend;
  43. use OCA\DAV\DAV\SystemPrincipalBackend;
  44. use OCA\DAV\Provisioning\Apple\AppleProvisioningNode;
  45. use OCA\DAV\Upload\CleanupService;
  46. use OCP\Accounts\IAccountManager;
  47. use OCP\App\IAppManager;
  48. use OCP\AppFramework\Utility\ITimeFactory;
  49. use OCP\EventDispatcher\IEventDispatcher;
  50. use OCP\IConfig;
  51. use Psr\Log\LoggerInterface;
  52. use Sabre\DAV\SimpleCollection;
  53. class RootCollection extends SimpleCollection {
  54. public function __construct() {
  55. $l10n = \OC::$server->getL10N('dav');
  56. $random = \OC::$server->getSecureRandom();
  57. $logger = \OC::$server->get(LoggerInterface::class);
  58. $userManager = \OC::$server->getUserManager();
  59. $userSession = \OC::$server->getUserSession();
  60. $groupManager = \OC::$server->getGroupManager();
  61. $shareManager = \OC::$server->getShareManager();
  62. $db = \OC::$server->getDatabaseConnection();
  63. $dispatcher = \OC::$server->get(IEventDispatcher::class);
  64. $config = \OC::$server->get(IConfig::class);
  65. $proxyMapper = \OC::$server->query(ProxyMapper::class);
  66. $userPrincipalBackend = new Principal(
  67. $userManager,
  68. $groupManager,
  69. \OC::$server->get(IAccountManager::class),
  70. $shareManager,
  71. \OC::$server->getUserSession(),
  72. \OC::$server->getAppManager(),
  73. $proxyMapper,
  74. \OC::$server->get(KnownUserService::class),
  75. \OC::$server->getConfig(),
  76. \OC::$server->getL10NFactory()
  77. );
  78. $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager, $config);
  79. $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper);
  80. $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper);
  81. // as soon as debug mode is enabled we allow listing of principals
  82. $disableListing = !$config->getSystemValue('debug', false);
  83. // setup the first level of the dav tree
  84. $userPrincipals = new Collection($userPrincipalBackend, 'principals/users');
  85. $userPrincipals->disableListing = $disableListing;
  86. $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups');
  87. $groupPrincipals->disableListing = $disableListing;
  88. $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system');
  89. $systemPrincipals->disableListing = $disableListing;
  90. $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources');
  91. $calendarResourcePrincipals->disableListing = $disableListing;
  92. $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms');
  93. $calendarRoomPrincipals->disableListing = $disableListing;
  94. $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
  95. $filesCollection->disableListing = $disableListing;
  96. $caldavBackend = new CalDavBackend(
  97. $db,
  98. $userPrincipalBackend,
  99. $userManager,
  100. $groupManager,
  101. $random,
  102. $logger,
  103. $dispatcher,
  104. $config
  105. );
  106. $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users', $logger);
  107. $userCalendarRoot->disableListing = $disableListing;
  108. $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources', $logger);
  109. $resourceCalendarRoot->disableListing = $disableListing;
  110. $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $caldavBackend, 'principals/calendar-rooms', $logger);
  111. $roomCalendarRoot->disableListing = $disableListing;
  112. $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config, $logger);
  113. $systemTagCollection = new SystemTag\SystemTagsByIdCollection(
  114. \OC::$server->getSystemTagManager(),
  115. \OC::$server->getUserSession(),
  116. $groupManager
  117. );
  118. $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection(
  119. \OC::$server->getSystemTagManager(),
  120. \OC::$server->getSystemTagObjectMapper(),
  121. \OC::$server->getUserSession(),
  122. $groupManager,
  123. \OC::$server->getEventDispatcher()
  124. );
  125. $commentsCollection = new Comments\RootCollection(
  126. \OC::$server->getCommentsManager(),
  127. $userManager,
  128. \OC::$server->getUserSession(),
  129. \OC::$server->getEventDispatcher(),
  130. $logger
  131. );
  132. $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class));
  133. $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
  134. $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, 'principals/users');
  135. $usersAddressBookRoot->disableListing = $disableListing;
  136. $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
  137. $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, '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. $commentsCollection,
  168. $uploadCollection,
  169. $avatarCollection,
  170. new SimpleCollection('provisioning', [
  171. $appleProvisioning
  172. ])
  173. ];
  174. parent::__construct('root', $children);
  175. }
  176. }