RootCollection.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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\CalDAV\Sharing\Backend;
  40. use OCA\DAV\CardDAV\AddressBookRoot;
  41. use OCA\DAV\CardDAV\CardDavBackend;
  42. use OCA\DAV\Connector\Sabre\Principal;
  43. use OCA\DAV\DAV\GroupPrincipalBackend;
  44. use OCA\DAV\DAV\SystemPrincipalBackend;
  45. use OCA\DAV\Provisioning\Apple\AppleProvisioningNode;
  46. use OCA\DAV\Upload\CleanupService;
  47. use OCP\Accounts\IAccountManager;
  48. use OCP\App\IAppManager;
  49. use OCP\AppFramework\Utility\ITimeFactory;
  50. use OCP\EventDispatcher\IEventDispatcher;
  51. use OCP\Files\IRootFolder;
  52. use OCP\IConfig;
  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. $calendarSharingBackend = \OC::$server->get(Backend::class);
  98. $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
  99. $filesCollection->disableListing = $disableListing;
  100. $caldavBackend = new CalDavBackend(
  101. $db,
  102. $userPrincipalBackend,
  103. $userManager,
  104. $random,
  105. $logger,
  106. $dispatcher,
  107. $config,
  108. $calendarSharingBackend,
  109. false,
  110. );
  111. $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users', $logger);
  112. $userCalendarRoot->disableListing = $disableListing;
  113. $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources', $logger);
  114. $resourceCalendarRoot->disableListing = $disableListing;
  115. $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $caldavBackend, 'principals/calendar-rooms', $logger);
  116. $roomCalendarRoot->disableListing = $disableListing;
  117. $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config, $logger);
  118. $systemTagCollection = new SystemTag\SystemTagsByIdCollection(
  119. \OC::$server->getSystemTagManager(),
  120. \OC::$server->getUserSession(),
  121. $groupManager
  122. );
  123. $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection(
  124. \OC::$server->getSystemTagManager(),
  125. \OC::$server->getSystemTagObjectMapper(),
  126. \OC::$server->getUserSession(),
  127. $groupManager,
  128. $dispatcher
  129. );
  130. $systemTagInUseCollection = \OCP\Server::get(SystemTag\SystemTagsInUseCollection::class);
  131. $commentsCollection = new Comments\RootCollection(
  132. \OC::$server->getCommentsManager(),
  133. $userManager,
  134. \OC::$server->getUserSession(),
  135. $dispatcher,
  136. $logger
  137. );
  138. $contactsSharingBackend = \OC::$server->get(\OCA\DAV\CardDAV\Sharing\Backend::class);
  139. $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class));
  140. $usersCardDavBackend = new CardDavBackend(
  141. $db,
  142. $userPrincipalBackend,
  143. $userManager,
  144. $dispatcher,
  145. $contactsSharingBackend,
  146. );
  147. $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/users');
  148. $usersAddressBookRoot->disableListing = $disableListing;
  149. $systemCardDavBackend = new CardDavBackend(
  150. $db,
  151. $userPrincipalBackend,
  152. $userManager,
  153. $dispatcher,
  154. $contactsSharingBackend,
  155. );
  156. $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/system');
  157. $systemAddressBookRoot->disableListing = $disableListing;
  158. $uploadCollection = new Upload\RootCollection(
  159. $userPrincipalBackend,
  160. 'principals/users',
  161. \OC::$server->query(CleanupService::class));
  162. $uploadCollection->disableListing = $disableListing;
  163. $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users');
  164. $avatarCollection->disableListing = $disableListing;
  165. $appleProvisioning = new AppleProvisioningNode(
  166. \OC::$server->query(ITimeFactory::class));
  167. $children = [
  168. new SimpleCollection('principals', [
  169. $userPrincipals,
  170. $groupPrincipals,
  171. $systemPrincipals,
  172. $calendarResourcePrincipals,
  173. $calendarRoomPrincipals]),
  174. $filesCollection,
  175. $userCalendarRoot,
  176. new SimpleCollection('system-calendars', [
  177. $resourceCalendarRoot,
  178. $roomCalendarRoot,
  179. ]),
  180. $publicCalendarRoot,
  181. new SimpleCollection('addressbooks', [
  182. $usersAddressBookRoot,
  183. $systemAddressBookRoot]),
  184. $systemTagCollection,
  185. $systemTagRelationsCollection,
  186. $systemTagInUseCollection,
  187. $commentsCollection,
  188. $uploadCollection,
  189. $avatarCollection,
  190. new SimpleCollection('provisioning', [
  191. $appleProvisioning
  192. ])
  193. ];
  194. parent::__construct('root', $children);
  195. }
  196. }