RootCollection.php 7.8 KB

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