RootCollection.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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\CardDAV\AddressBookRoot;
  30. use OCA\DAV\CardDAV\CardDavBackend;
  31. use OCA\DAV\Connector\Sabre\Principal;
  32. use OCA\DAV\DAV\GroupPrincipalBackend;
  33. use OCA\DAV\DAV\SystemPrincipalBackend;
  34. use OCA\DAV\CalDAV\Principal\Collection;
  35. use Sabre\DAV\SimpleCollection;
  36. class RootCollection extends SimpleCollection {
  37. public function __construct() {
  38. $config = \OC::$server->getConfig();
  39. $l10n = \OC::$server->getL10N('dav');
  40. $random = \OC::$server->getSecureRandom();
  41. $logger = \OC::$server->getLogger();
  42. $userManager = \OC::$server->getUserManager();
  43. $groupManager = \OC::$server->getGroupManager();
  44. $shareManager = \OC::$server->getShareManager();
  45. $db = \OC::$server->getDatabaseConnection();
  46. $dispatcher = \OC::$server->getEventDispatcher();
  47. $userPrincipalBackend = new Principal(
  48. $userManager,
  49. $groupManager,
  50. $shareManager,
  51. \OC::$server->getUserSession(),
  52. $config
  53. );
  54. $groupPrincipalBackend = new GroupPrincipalBackend($groupManager);
  55. // as soon as debug mode is enabled we allow listing of principals
  56. $disableListing = !$config->getSystemValue('debug', false);
  57. // setup the first level of the dav tree
  58. $userPrincipals = new Collection($userPrincipalBackend, 'principals/users');
  59. $userPrincipals->disableListing = $disableListing;
  60. $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups');
  61. $groupPrincipals->disableListing = $disableListing;
  62. $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system');
  63. $systemPrincipals->disableListing = $disableListing;
  64. $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
  65. $filesCollection->disableListing = $disableListing;
  66. $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher);
  67. $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users');
  68. $calendarRoot->disableListing = $disableListing;
  69. $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config);
  70. $publicCalendarRoot->disableListing = $disableListing;
  71. $systemTagCollection = new SystemTag\SystemTagsByIdCollection(
  72. \OC::$server->getSystemTagManager(),
  73. \OC::$server->getUserSession(),
  74. $groupManager
  75. );
  76. $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection(
  77. \OC::$server->getSystemTagManager(),
  78. \OC::$server->getSystemTagObjectMapper(),
  79. \OC::$server->getUserSession(),
  80. $groupManager,
  81. \OC::$server->getEventDispatcher()
  82. );
  83. $commentsCollection = new Comments\RootCollection(
  84. \OC::$server->getCommentsManager(),
  85. $userManager,
  86. \OC::$server->getUserSession(),
  87. \OC::$server->getEventDispatcher(),
  88. \OC::$server->getLogger()
  89. );
  90. $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
  91. $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users');
  92. $usersAddressBookRoot->disableListing = $disableListing;
  93. $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
  94. $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system');
  95. $systemAddressBookRoot->disableListing = $disableListing;
  96. $uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users');
  97. $uploadCollection->disableListing = $disableListing;
  98. $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users');
  99. $avatarCollection->disableListing = $disableListing;
  100. $children = [
  101. new SimpleCollection('principals', [
  102. $userPrincipals,
  103. $groupPrincipals,
  104. $systemPrincipals]),
  105. $filesCollection,
  106. $calendarRoot,
  107. $publicCalendarRoot,
  108. new SimpleCollection('addressbooks', [
  109. $usersAddressBookRoot,
  110. $systemAddressBookRoot]),
  111. $systemTagCollection,
  112. $systemTagRelationsCollection,
  113. $commentsCollection,
  114. $uploadCollection,
  115. $avatarCollection
  116. ];
  117. parent::__construct('root', $children);
  118. }
  119. }