RootCollection.php 7.7 KB

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