Merge pull request #2462 from nextcloud/stable10-1513
[stable10] Return ETag and OC-ETag in case of a move (#25683)
This commit is contained in:
commit
1b0155cef2
|
@ -32,6 +32,9 @@ use \Sabre\HTTP\ResponseInterface;
|
|||
* or mangle Etag headers.
|
||||
*/
|
||||
class CopyEtagHeaderPlugin extends \Sabre\DAV\ServerPlugin {
|
||||
|
||||
/** @var \Sabre\DAV\Server */
|
||||
private $server;
|
||||
/**
|
||||
* This initializes the plugin.
|
||||
*
|
||||
|
@ -40,7 +43,10 @@ class CopyEtagHeaderPlugin extends \Sabre\DAV\ServerPlugin {
|
|||
* @return void
|
||||
*/
|
||||
public function initialize(\Sabre\DAV\Server $server) {
|
||||
$server->on('afterMethod', array($this, 'afterMethod'));
|
||||
$this->server = $server;
|
||||
|
||||
$server->on('afterMethod', [$this, 'afterMethod']);
|
||||
$server->on('afterMove', [$this, 'afterMove']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,4 +61,22 @@ class CopyEtagHeaderPlugin extends \Sabre\DAV\ServerPlugin {
|
|||
$response->setHeader('OC-ETag', $eTag);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after a node is moved.
|
||||
*
|
||||
* This allows the backend to move all the associated properties.
|
||||
*
|
||||
* @param string $source
|
||||
* @param string $destination
|
||||
* @return void
|
||||
*/
|
||||
function afterMove($source, $destination) {
|
||||
$node = $this->server->tree->getNodeForPath($destination);
|
||||
if ($node instanceof File) {
|
||||
$eTag = $node->getETag();
|
||||
$this->server->httpResponse->setHeader('OC-ETag', $eTag);
|
||||
$this->server->httpResponse->setHeader('ETag', $eTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,13 +30,18 @@ namespace OCA\DAV;
|
|||
|
||||
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
|
||||
use OCA\DAV\CardDAV\ImageExportPlugin;
|
||||
use OCA\DAV\Comments\CommentsPlugin;
|
||||
use OCA\DAV\Connector\Sabre\Auth;
|
||||
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
|
||||
use OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin;
|
||||
use OCA\DAV\Connector\Sabre\DavAclPlugin;
|
||||
use OCA\DAV\Connector\Sabre\DummyGetResponsePlugin;
|
||||
use OCA\DAV\Connector\Sabre\FakeLockerPlugin;
|
||||
use OCA\DAV\Connector\Sabre\FilesPlugin;
|
||||
use OCA\DAV\Connector\Sabre\QuotaPlugin;
|
||||
use OCA\DAV\Files\BrowserErrorPagePlugin;
|
||||
use OCA\DAV\Files\CustomPropertiesBackend;
|
||||
use OCA\DAV\SystemTag\SystemTagPlugin;
|
||||
use OCP\IRequest;
|
||||
use OCP\SabrePluginEvent;
|
||||
use Sabre\CardDAV\VCFExportPlugin;
|
||||
|
@ -121,25 +126,27 @@ class Server {
|
|||
$this->server->addPlugin(new ImageExportPlugin(\OC::$server->getLogger()));
|
||||
|
||||
// system tags plugins
|
||||
$this->server->addPlugin(new \OCA\DAV\SystemTag\SystemTagPlugin(
|
||||
$this->server->addPlugin(new SystemTagPlugin(
|
||||
\OC::$server->getSystemTagManager(),
|
||||
\OC::$server->getGroupManager(),
|
||||
\OC::$server->getUserSession()
|
||||
));
|
||||
|
||||
// comments plugin
|
||||
$this->server->addPlugin(new \OCA\DAV\Comments\CommentsPlugin(
|
||||
$this->server->addPlugin(new CommentsPlugin(
|
||||
\OC::$server->getCommentsManager(),
|
||||
\OC::$server->getUserSession()
|
||||
));
|
||||
|
||||
$this->server->addPlugin(new CopyEtagHeaderPlugin());
|
||||
|
||||
// Some WebDAV clients do require Class 2 WebDAV support (locking), since
|
||||
// we do not provide locking we emulate it using a fake locking plugin.
|
||||
if($request->isUserAgent([
|
||||
'/WebDAVFS/',
|
||||
'/Microsoft Office OneNote 2013/',
|
||||
])) {
|
||||
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin());
|
||||
$this->server->addPlugin(new FakeLockerPlugin());
|
||||
}
|
||||
|
||||
if (BrowserErrorPagePlugin::isBrowserRequest($request)) {
|
||||
|
@ -174,8 +181,8 @@ class Server {
|
|||
)
|
||||
);
|
||||
$this->server->addPlugin(
|
||||
new \OCA\DAV\Connector\Sabre\QuotaPlugin($view));
|
||||
|
||||
new QuotaPlugin($view)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -23,23 +23,28 @@
|
|||
*/
|
||||
namespace OCA\DAV\Tests\unit\Connector\Sabre;
|
||||
|
||||
use OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin;
|
||||
use Sabre\DAV\Server;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
class CopyEtagHeaderPluginTest extends \Test\TestCase {
|
||||
class CopyEtagHeaderPluginTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin
|
||||
*/
|
||||
/** @var CopyEtagHeaderPlugin */
|
||||
private $plugin;
|
||||
|
||||
/** @var Server */
|
||||
private $server;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->server = new \Sabre\DAV\Server();
|
||||
$this->plugin = new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin();
|
||||
$this->plugin = new CopyEtagHeaderPlugin();
|
||||
$this->plugin->initialize($this->server);
|
||||
}
|
||||
|
||||
|
@ -61,4 +66,26 @@ class CopyEtagHeaderPluginTest extends \Test\TestCase {
|
|||
|
||||
$this->assertNull($response->getHeader('OC-Etag'));
|
||||
}
|
||||
|
||||
public function testAfterMove() {
|
||||
$node = $this->getMockBuilder('OCA\DAV\Connector\Sabre\File')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$node->expects($this->once())
|
||||
->method('getETag')
|
||||
->willReturn('123456');
|
||||
$tree = $this->getMockBuilder('Sabre\DAV\Tree')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$tree->expects($this->once())
|
||||
->method('getNodeForPath')
|
||||
->with('test.txt')
|
||||
->willReturn($node);
|
||||
|
||||
$this->server->tree = $tree;
|
||||
$this->plugin->afterMove('', 'test.txt');
|
||||
|
||||
$this->assertEquals('123456', $this->server->httpResponse->getHeader('OC-Etag'));
|
||||
$this->assertEquals('123456', $this->server->httpResponse->getHeader('Etag'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue