OCSShareAPIMiddleware.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\Files_Sharing\Middleware;
  26. use OCA\Files_Sharing\Controller\ShareAPIController;
  27. use OCP\AppFramework\Controller;
  28. use OCP\AppFramework\Http\Response;
  29. use OCP\AppFramework\Middleware;
  30. use OCP\AppFramework\OCS\OCSNotFoundException;
  31. use OCP\IL10N;
  32. use OCP\Share\IManager;
  33. class OCSShareAPIMiddleware extends Middleware {
  34. /** @var IManager */
  35. private $shareManager;
  36. /** @var IL10N */
  37. private $l;
  38. public function __construct(IManager $shareManager,
  39. IL10N $l) {
  40. $this->shareManager = $shareManager;
  41. $this->l = $l;
  42. }
  43. /**
  44. * @param Controller $controller
  45. * @param string $methodName
  46. *
  47. * @throws OCSNotFoundException
  48. */
  49. public function beforeController($controller, $methodName) {
  50. if ($controller instanceof ShareAPIController) {
  51. if (!$this->shareManager->shareApiEnabled()) {
  52. throw new OCSNotFoundException($this->l->t('Share API is disabled'));
  53. }
  54. }
  55. }
  56. /**
  57. * @param Controller $controller
  58. * @param string $methodName
  59. * @param Response $response
  60. * @return Response
  61. */
  62. public function afterController($controller, $methodName, Response $response) {
  63. if ($controller instanceof ShareAPIController) {
  64. /** @var ShareAPIController $controller */
  65. $controller->cleanup();
  66. }
  67. return $response;
  68. }
  69. }