RootCollection.php 7.1 KB

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