RootCollection.php 7.0 KB

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