diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2016-07-20 10:11:01 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-08-05 14:17:31 +0200 |
commit | 3a31b2875bc37114ac97f00e6cb6ea7b3ee53f60 (patch) | |
tree | f713d3bf9dffa0734f42ed5dbd70eb907b99fc81 /apps/files_sharing/lib/Middleware | |
parent | 8b160077f1a2ea7851dab8ad3b2b55bac0ae5766 (diff) | |
download | nextcloud-server-3a31b2875bc37114ac97f00e6cb6ea7b3ee53f60.tar.gz nextcloud-server-3a31b2875bc37114ac97f00e6cb6ea7b3ee53f60.zip |
Add OCSShareAPIMiddleware
* This will cleanup the locks after each request
* Move check for enabled share api to the middleware
Diffstat (limited to 'apps/files_sharing/lib/Middleware')
-rw-r--r-- | apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php b/apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php new file mode 100644 index 00000000000..b42cf6b00ad --- /dev/null +++ b/apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php @@ -0,0 +1,53 @@ +<?php + +namespace OCA\Files_Sharing\Middleware; + +use OCA\Files_Sharing\API\Share20OCS; +use OCP\AppFramework\Http\Response; +use OCP\AppFramework\Middleware; +use OCP\AppFramework\OCS\OCSNotFoundException; +use OCP\IL10N; +use OCP\Share\IManager; + +class OCSShareAPIMiddleware extends Middleware { + /** @var IManager */ + private $shareManager; + /** @var IL10N */ + private $l; + + public function __construct(IManager $shareManager, + IL10N $l) { + $this->shareManager = $shareManager; + $this->l = $l; + } + + /** + * @param \OCP\AppFramework\Controller $controller + * @param string $methodName + * + * @throws OCSNotFoundException + */ + public function beforeController($controller, $methodName) { + if ($controller instanceof Share20OCS) { + /** @var Share20OCS $controller */ + if (!$this->shareManager->shareApiEnabled()) { + throw new OCSNotFoundException($this->l->t('Share API is disabled')); + } + } + } + + /** + * @param \OCP\AppFramework\Controller $controller + * @param string $methodName + * @param Response $response + * @return Response + */ + public function afterController($controller, $methodName, Response $response) { + if ($controller instanceof Share20OCS) { + /** @var Share20OCS $controller */ + $controller->cleanup(); + } + + return $response; + } +} |