1
0

RootCollection.php 7.4 KB

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