You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.7 KiB

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