RootCollection.php 4.7 KB

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