PublicLinkCheckPlugin.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\DAV\Files\Sharing;
  25. use OCP\Files\FileInfo;
  26. use Sabre\DAV\Exception\NotFound;
  27. use Sabre\DAV\ServerPlugin;
  28. use Sabre\HTTP\RequestInterface;
  29. use Sabre\HTTP\ResponseInterface;
  30. /**
  31. * Verify that the public link share is valid
  32. */
  33. class PublicLinkCheckPlugin extends ServerPlugin {
  34. /**
  35. * @var FileInfo
  36. */
  37. private $fileInfo;
  38. /**
  39. * @param FileInfo $fileInfo
  40. */
  41. public function setFileInfo($fileInfo) {
  42. $this->fileInfo = $fileInfo;
  43. }
  44. /**
  45. * This initializes the plugin.
  46. *
  47. * @param \Sabre\DAV\Server $server Sabre server
  48. *
  49. * @return void
  50. */
  51. public function initialize(\Sabre\DAV\Server $server) {
  52. $server->on('beforeMethod:*', [$this, 'beforeMethod']);
  53. }
  54. public function beforeMethod(RequestInterface $request, ResponseInterface $response) {
  55. // verify that the owner didn't have his share permissions revoked
  56. if ($this->fileInfo && !$this->fileInfo->isShareable()) {
  57. throw new NotFound();
  58. }
  59. }
  60. }