RootCollection.php 7.0 KB

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