OCSShareAPIMiddleware.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Files_Sharing\Middleware;
  7. use OCA\Files_Sharing\Controller\ShareAPIController;
  8. use OCP\AppFramework\Controller;
  9. use OCP\AppFramework\Http\Response;
  10. use OCP\AppFramework\Middleware;
  11. use OCP\AppFramework\OCS\OCSNotFoundException;
  12. use OCP\IL10N;
  13. use OCP\Share\IManager;
  14. class OCSShareAPIMiddleware extends Middleware {
  15. /** @var IManager */
  16. private $shareManager;
  17. /** @var IL10N */
  18. private $l;
  19. public function __construct(IManager $shareManager,
  20. IL10N $l) {
  21. $this->shareManager = $shareManager;
  22. $this->l = $l;
  23. }
  24. /**
  25. * @param Controller $controller
  26. * @param string $methodName
  27. *
  28. * @throws OCSNotFoundException
  29. */
  30. public function beforeController($controller, $methodName) {
  31. if ($controller instanceof ShareAPIController) {
  32. if (!$this->shareManager->shareApiEnabled()) {
  33. throw new OCSNotFoundException($this->l->t('Share API is disabled'));
  34. }
  35. }
  36. }
  37. /**
  38. * @param Controller $controller
  39. * @param string $methodName
  40. * @param Response $response
  41. * @return Response
  42. */
  43. public function afterController($controller, $methodName, Response $response) {
  44. if ($controller instanceof ShareAPIController) {
  45. /** @var ShareAPIController $controller */
  46. $controller->cleanup();
  47. }
  48. return $response;
  49. }
  50. }