RootCollection.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. $rootFolder,
  130. );
  131. $systemTagInUseCollection = \OCP\Server::get(SystemTag\SystemTagsInUseCollection::class);
  132. $commentsCollection = new Comments\RootCollection(
  133. \OC::$server->getCommentsManager(),
  134. $userManager,
  135. \OC::$server->getUserSession(),
  136. $dispatcher,
  137. $logger
  138. );
  139. $contactsSharingBackend = \OC::$server->get(\OCA\DAV\CardDAV\Sharing\Backend::class);
  140. $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class));
  141. $usersCardDavBackend = new CardDavBackend(
  142. $db,
  143. $userPrincipalBackend,
  144. $userManager,
  145. $dispatcher,
  146. $contactsSharingBackend,
  147. );
  148. $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/users');
  149. $usersAddressBookRoot->disableListing = $disableListing;
  150. $systemCardDavBackend = new CardDavBackend(
  151. $db,
  152. $userPrincipalBackend,
  153. $userManager,
  154. $dispatcher,
  155. $contactsSharingBackend,
  156. );
  157. $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/system');
  158. $systemAddressBookRoot->disableListing = $disableListing;
  159. $uploadCollection = new Upload\RootCollection(
  160. $userPrincipalBackend,
  161. 'principals/users',
  162. \OC::$server->query(CleanupService::class));
  163. $uploadCollection->disableListing = $disableListing;
  164. $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users');
  165. $avatarCollection->disableListing = $disableListing;
  166. $appleProvisioning = new AppleProvisioningNode(
  167. \OC::$server->query(ITimeFactory::class));
  168. $children = [
  169. new SimpleCollection('principals', [
  170. $userPrincipals,
  171. $groupPrincipals,
  172. $systemPrincipals,
  173. $calendarResourcePrincipals,
  174. $calendarRoomPrincipals]),
  175. $filesCollection,
  176. $userCalendarRoot,
  177. new SimpleCollection('system-calendars', [
  178. $resourceCalendarRoot,
  179. $roomCalendarRoot,
  180. ]),
  181. $publicCalendarRoot,
  182. new SimpleCollection('addressbooks', [
  183. $usersAddressBookRoot,
  184. $systemAddressBookRoot]),
  185. $systemTagCollection,
  186. $systemTagRelationsCollection,
  187. $systemTagInUseCollection,
  188. $commentsCollection,
  189. $uploadCollection,
  190. $avatarCollection,
  191. new SimpleCollection('provisioning', [
  192. $appleProvisioning
  193. ])
  194. ];
  195. parent::__construct('root', $children);
  196. }
  197. }