1
0

OCSShareAPIMiddleware.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. public function __construct(
  16. private IManager $shareManager,
  17. private IL10N $l,
  18. ) {
  19. }
  20. /**
  21. * @param Controller $controller
  22. * @param string $methodName
  23. *
  24. * @throws OCSNotFoundException
  25. */
  26. public function beforeController($controller, $methodName) {
  27. if ($controller instanceof ShareAPIController) {
  28. if (!$this->shareManager->shareApiEnabled()) {
  29. throw new OCSNotFoundException($this->l->t('Share API is disabled'));
  30. }
  31. }
  32. }
  33. /**
  34. * @param Controller $controller
  35. * @param string $methodName
  36. * @param Response $response
  37. * @return Response
  38. */
  39. public function afterController($controller, $methodName, Response $response) {
  40. if ($controller instanceof ShareAPIController) {
  41. /** @var ShareAPIController $controller */
  42. $controller->cleanup();
  43. }
  44. return $response;
  45. }
  46. }