InvitationResponseServer.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018, Georg Ehrke.
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCA\DAV\CalDAV\InvitationResponse;
  23. use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
  24. use OCA\DAV\Connector\Sabre\CachingTree;
  25. use OCA\DAV\Connector\Sabre\DavAclPlugin;
  26. use OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin;
  27. use OCA\DAV\RootCollection;
  28. use OCP\SabrePluginEvent;
  29. use Sabre\DAV\Auth\Plugin;
  30. use OCA\DAV\AppInfo\PluginManager;
  31. use Sabre\VObject\ITip\Message;
  32. class InvitationResponseServer {
  33. /** @var \OCA\DAV\Connector\Sabre\Server */
  34. public $server;
  35. /**
  36. * InvitationResponseServer constructor.
  37. */
  38. public function __construct() {
  39. $baseUri = \OC::$WEBROOT . '/remote.php/dav/';
  40. $logger = \OC::$server->getLogger();
  41. $dispatcher = \OC::$server->getEventDispatcher();
  42. $root = new RootCollection();
  43. $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
  44. // Add maintenance plugin
  45. $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig()));
  46. // Set URL explicitly due to reverse-proxy situations
  47. $this->server->httpRequest->setUrl($baseUri);
  48. $this->server->setBaseUri($baseUri);
  49. $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
  50. $this->server->addPlugin(new AnonymousOptionsPlugin());
  51. $this->server->addPlugin(new class() extends Plugin {
  52. public function getCurrentPrincipal() {
  53. return 'principals/system/public';
  54. }
  55. });
  56. // allow setup of additional auth backends
  57. $event = new SabrePluginEvent($this->server);
  58. $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
  59. $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger));
  60. $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
  61. $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
  62. // acl
  63. $acl = new DavAclPlugin();
  64. $acl->principalCollectionSet = [
  65. 'principals/users', 'principals/groups'
  66. ];
  67. $acl->defaultUsernamePath = 'principals/users';
  68. $this->server->addPlugin($acl);
  69. // calendar plugins
  70. $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
  71. $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
  72. $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin());
  73. $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
  74. $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
  75. //$this->server->addPlugin(new \OCA\DAV\DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
  76. $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
  77. \OC::$server->getConfig(),
  78. \OC::$server->getURLGenerator()
  79. ));
  80. // wait with registering these until auth is handled and the filesystem is setup
  81. $this->server->on('beforeMethod', function () use ($root) {
  82. // register plugins from apps
  83. $pluginManager = new PluginManager(
  84. \OC::$server,
  85. \OC::$server->getAppManager()
  86. );
  87. foreach ($pluginManager->getAppPlugins() as $appPlugin) {
  88. $this->server->addPlugin($appPlugin);
  89. }
  90. foreach ($pluginManager->getAppCollections() as $appCollection) {
  91. $root->addChild($appCollection);
  92. }
  93. });
  94. }
  95. /**
  96. * @param Message $iTipMessage
  97. * @return void
  98. */
  99. public function handleITipMessage(Message $iTipMessage) {
  100. /** @var \OCA\DAV\CalDAV\Schedule\Plugin $schedulingPlugin */
  101. $schedulingPlugin = $this->server->getPlugin('caldav-schedule');
  102. $schedulingPlugin->scheduleLocalDelivery($iTipMessage);
  103. }
  104. }