RootCollection.php 4.4 KB

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