InvitationResponseServer.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018, Georg Ehrke.
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Thomas Citharel <nextcloud@tcit.fr>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\DAV\CalDAV\InvitationResponse;
  27. use OCA\DAV\AppInfo\PluginManager;
  28. use OCA\DAV\CalDAV\Auth\CustomPrincipalPlugin;
  29. use OCA\DAV\CalDAV\Auth\PublicPrincipalPlugin;
  30. use OCA\DAV\CalDAV\DefaultCalendarValidator;
  31. use OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin;
  32. use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
  33. use OCA\DAV\Connector\Sabre\CachingTree;
  34. use OCA\DAV\Connector\Sabre\DavAclPlugin;
  35. use OCA\DAV\Events\SabrePluginAuthInitEvent;
  36. use OCA\DAV\RootCollection;
  37. use OCP\EventDispatcher\IEventDispatcher;
  38. use Psr\Log\LoggerInterface;
  39. use Sabre\VObject\ITip\Message;
  40. class InvitationResponseServer {
  41. /** @var \OCA\DAV\Connector\Sabre\Server */
  42. public $server;
  43. /**
  44. * InvitationResponseServer constructor.
  45. */
  46. public function __construct(bool $public = true) {
  47. $baseUri = \OC::$WEBROOT . '/remote.php/dav/';
  48. $logger = \OC::$server->get(LoggerInterface::class);
  49. /** @var IEventDispatcher $dispatcher */
  50. $dispatcher = \OC::$server->query(IEventDispatcher::class);
  51. $root = new RootCollection();
  52. $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
  53. // Add maintenance plugin
  54. $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
  55. // Set URL explicitly due to reverse-proxy situations
  56. $this->server->httpRequest->setUrl($baseUri);
  57. $this->server->setBaseUri($baseUri);
  58. $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
  59. $this->server->addPlugin(new AnonymousOptionsPlugin());
  60. // allow custom principal uri option
  61. if ($public) {
  62. $this->server->addPlugin(new PublicPrincipalPlugin());
  63. } else {
  64. $this->server->addPlugin(new CustomPrincipalPlugin());
  65. }
  66. // allow setup of additional auth backends
  67. $event = new SabrePluginAuthInitEvent($this->server);
  68. $dispatcher->dispatchTyped($event);
  69. $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger));
  70. $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
  71. $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
  72. // acl
  73. $acl = new DavAclPlugin();
  74. $acl->principalCollectionSet = [
  75. 'principals/users', 'principals/groups'
  76. ];
  77. $this->server->addPlugin($acl);
  78. // calendar plugins
  79. $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
  80. $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
  81. $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DefaultCalendarValidator::class)));
  82. $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
  83. $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
  84. //$this->server->addPlugin(new \OCA\DAV\DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
  85. $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
  86. \OC::$server->getConfig(),
  87. \OC::$server->getURLGenerator()
  88. ));
  89. // wait with registering these until auth is handled and the filesystem is setup
  90. $this->server->on('beforeMethod:*', function () use ($root): void {
  91. // register plugins from apps
  92. $pluginManager = new PluginManager(
  93. \OC::$server,
  94. \OC::$server->getAppManager()
  95. );
  96. foreach ($pluginManager->getAppPlugins() as $appPlugin) {
  97. $this->server->addPlugin($appPlugin);
  98. }
  99. foreach ($pluginManager->getAppCollections() as $appCollection) {
  100. $root->addChild($appCollection);
  101. }
  102. });
  103. }
  104. /**
  105. * @param Message $iTipMessage
  106. * @return void
  107. */
  108. public function handleITipMessage(Message $iTipMessage) {
  109. /** @var \OCA\DAV\CalDAV\Schedule\Plugin $schedulingPlugin */
  110. $schedulingPlugin = $this->server->getPlugin('caldav-schedule');
  111. $schedulingPlugin->scheduleLocalDelivery($iTipMessage);
  112. }
  113. public function isExternalAttendee(string $principalUri): bool {
  114. /** @var \Sabre\DAVACL\Plugin $aclPlugin */
  115. $aclPlugin = $this->getServer()->getPlugin('acl');
  116. return $aclPlugin->getPrincipalByUri($principalUri) === null;
  117. }
  118. public function getServer(): \OCA\DAV\Connector\Sabre\Server {
  119. return $this->server;
  120. }
  121. }