Only enable files_drop plugin when we actuall do files_drop

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2016-10-24 21:44:12 +02:00
parent 0abcc630a5
commit c8a13f644e
No known key found for this signature in database
GPG Key ID: 1E152838F164D13B
2 changed files with 21 additions and 4 deletions

View File

@ -88,6 +88,11 @@ $server = $serverFactory->createServer($baseuri, $requestUri, $authBackend, func
$fileInfo = $ownerView->getFileInfo($path); $fileInfo = $ownerView->getFileInfo($path);
$linkCheckPlugin->setFileInfo($fileInfo); $linkCheckPlugin->setFileInfo($fileInfo);
// If not readble (files_drop) enable the filesdrop plugin
if (!$isReadable) {
$filesDropPlugin->enable();
}
$view = new \OC\Files\View($ownerView->getAbsolutePath($path)); $view = new \OC\Files\View($ownerView->getAbsolutePath($path));
$filesDropPlugin->setView($view); $filesDropPlugin->setView($view);

View File

@ -32,11 +32,12 @@ use Sabre\HTTP\ResponseInterface;
*/ */
class FilesDropPlugin extends ServerPlugin { class FilesDropPlugin extends ServerPlugin {
/** /** @var View */
* @var View
*/
private $view; private $view;
/** @var bool */
private $enabled = false;
/** /**
* @param View $view * @param View $view
*/ */
@ -44,6 +45,11 @@ class FilesDropPlugin extends ServerPlugin {
$this->view = $view; $this->view = $view;
} }
public function enable() {
$this->enabled = true;
}
/** /**
* This initializes the plugin. * This initializes the plugin.
* *
@ -52,10 +58,16 @@ class FilesDropPlugin extends ServerPlugin {
* @return void * @return void
*/ */
public function initialize(\Sabre\DAV\Server $server) { public function initialize(\Sabre\DAV\Server $server) {
$server->on('beforeMethod', [$this, 'beforeMethod']); $server->on('beforeMethod:PUT', [$this, 'beforeMethod']);
$this->enabled = false;
} }
public function beforeMethod(RequestInterface $request, ResponseInterface $response){ public function beforeMethod(RequestInterface $request, ResponseInterface $response){
if (!$this->enabled) {
return;
}
$path = $request->getPath(); $path = $request->getPath();
if ($this->view->file_exists($path)) { if ($this->view->file_exists($path)) {