PublicLinkCheckPlugin.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\Files\Sharing;
  8. use OCP\Files\FileInfo;
  9. use Sabre\DAV\Exception\NotFound;
  10. use Sabre\DAV\ServerPlugin;
  11. use Sabre\HTTP\RequestInterface;
  12. use Sabre\HTTP\ResponseInterface;
  13. /**
  14. * Verify that the public link share is valid
  15. */
  16. class PublicLinkCheckPlugin extends ServerPlugin {
  17. /**
  18. * @var FileInfo
  19. */
  20. private $fileInfo;
  21. /**
  22. * @param FileInfo $fileInfo
  23. */
  24. public function setFileInfo($fileInfo) {
  25. $this->fileInfo = $fileInfo;
  26. }
  27. /**
  28. * This initializes the plugin.
  29. *
  30. * @param \Sabre\DAV\Server $server Sabre server
  31. *
  32. * @return void
  33. */
  34. public function initialize(\Sabre\DAV\Server $server) {
  35. $server->on('beforeMethod:*', [$this, 'beforeMethod']);
  36. }
  37. public function beforeMethod(RequestInterface $request, ResponseInterface $response) {
  38. // verify that the owner didn't have his share permissions revoked
  39. if ($this->fileInfo && !$this->fileInfo->isShareable()) {
  40. throw new NotFound();
  41. }
  42. }
  43. }