summaryrefslogtreecommitdiffstats
path: root/apps/files_versions
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2015-05-15 15:02:26 +0200
committerJoas Schilling <nickvergessen@gmx.de>2015-05-15 15:02:26 +0200
commit03e26a0fbea3c96593ee7c533b9b303664e4d4f5 (patch)
tree8b2854a1e2b6b0874216a7cd2096f5c4629c7a15 /apps/files_versions
parent02912aef5839099c5d98e83dccd14095ff9db9e1 (diff)
parenteab55aa959d0bd167b6a2a51483cb1f24d471df0 (diff)
downloadnextcloud-server-03e26a0fbea3c96593ee7c533b9b303664e4d4f5.tar.gz
nextcloud-server-03e26a0fbea3c96593ee7c533b9b303664e4d4f5.zip
Merge pull request #16337 from owncloud/versions-expireforowner
Use owner when expiring versions, not the logged in user
Diffstat (limited to 'apps/files_versions')
-rw-r--r--apps/files_versions/lib/storage.php19
-rw-r--r--apps/files_versions/tests/versions.php90
2 files changed, 97 insertions, 12 deletions
diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php
index 45f96ee776b..98e486690b6 100644
--- a/apps/files_versions/lib/storage.php
+++ b/apps/files_versions/lib/storage.php
@@ -158,7 +158,7 @@ class Storage {
// 1.5 times as large as the current version -> 2.5
$neededSpace = $files_view->filesize($filename) * 2.5;
- self::scheduleExpire($filename, $versionsSize, $neededSpace);
+ self::scheduleExpire($uid, $filename, $versionsSize, $neededSpace);
// store a new version of a file
$mtime = $users_view->filemtime('files/' . $filename);
@@ -276,7 +276,7 @@ class Storage {
// if we moved versions directly for a file, schedule expiration check for that file
if (!$rootView->is_dir('/' . $targetOwner . '/files/' . $targetPath)) {
- self::scheduleExpire($targetPath);
+ self::scheduleExpire($targetOwner, $targetPath);
}
}
@@ -309,7 +309,7 @@ class Storage {
// rollback
if (self::copyFileContents($users_view, 'files_versions' . $filename . '.v' . $revision, 'files' . $filename)) {
$files_view->touch($file, $revision);
- Storage::scheduleExpire($file);
+ Storage::scheduleExpire($uid, $file);
return true;
} else if ($versionCreated) {
self::deleteVersion($users_view, $version);
@@ -532,12 +532,15 @@ class Storage {
}
/**
- * @param string $fileName
- * @param int|null $versionsSize
- * @param int $neededSpace
+ * Schedule versions expiration for the given file
+ *
+ * @param string $uid owner of the file
+ * @param string $fileName file/folder for which to schedule expiration
+ * @param int|null $versionsSize current versions size
+ * @param int $neededSpace requested versions size
*/
- private static function scheduleExpire($fileName, $versionsSize = null, $neededSpace = 0) {
- $command = new Expire(\OC::$server->getUserSession()->getUser()->getUID(), $fileName, $versionsSize, $neededSpace);
+ private static function scheduleExpire($uid, $fileName, $versionsSize = null, $neededSpace = 0) {
+ $command = new Expire($uid, $fileName, $versionsSize, $neededSpace);
\OC::$server->getCommandBus()->push($command);
}
diff --git a/apps/files_versions/tests/versions.php b/apps/files_versions/tests/versions.php
index 2d3e2b66e06..97afcf715cb 100644
--- a/apps/files_versions/tests/versions.php
+++ b/apps/files_versions/tests/versions.php
@@ -45,10 +45,6 @@ class Test_Files_Versioning extends \Test\TestCase {
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
- // clear share hooks
- \OC_Hook::clear('OCP\\Share');
- \OC::registerShareHooks();
- \OCA\Files_Versions\Hooks::connectHooks();
$application = new \OCA\Files_Sharing\AppInfo\Application();
$application->registerMountProviders();
$application->setupPropagation();
@@ -69,6 +65,11 @@ class Test_Files_Versioning extends \Test\TestCase {
protected function setUp() {
parent::setUp();
+ // clear hooks
+ \OC_Hook::clear();
+ \OC::registerShareHooks();
+ \OCA\Files_Versions\Hooks::connectHooks();
+
self::loginHelper(self::TEST_VERSIONS_USER);
$this->rootView = new \OC\Files\View();
if (!$this->rootView->file_exists(self::USERS_VERSIONS_ROOT)) {
@@ -82,6 +83,8 @@ class Test_Files_Versioning extends \Test\TestCase {
$this->rootView->deleteAll(self::TEST_VERSIONS_USER . '/files_versions/');
$this->rootView->deleteAll(self::TEST_VERSIONS_USER2 . '/files_versions/');
+ \OC_Hook::clear();
+
parent::tearDown();
}
@@ -648,6 +651,85 @@ class Test_Files_Versioning extends \Test\TestCase {
}
/**
+ * Test whether versions are created when overwriting as owner
+ */
+ public function testStoreVersionAsOwner() {
+ $this->loginAsUser(self::TEST_VERSIONS_USER);
+
+ $this->createAndCheckVersions(
+ \OC\Files\Filesystem::getView(),
+ 'test.txt'
+ );
+ }
+
+ /**
+ * Test whether versions are created when overwriting as share recipient
+ */
+ public function testStoreVersionAsRecipient() {
+ $this->loginAsUser(self::TEST_VERSIONS_USER);
+
+ \OC\Files\Filesystem::mkdir('folder');
+ \OC\Files\Filesystem::file_put_contents('folder/test.txt', 'test file');
+ $fileInfo = \OC\Files\Filesystem::getFileInfo('folder');
+
+ \OCP\Share::shareItem(
+ 'folder',
+ $fileInfo['fileid'],
+ \OCP\Share::SHARE_TYPE_USER,
+ self::TEST_VERSIONS_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
+
+ $this->loginAsUser(self::TEST_VERSIONS_USER2);
+
+ $this->createAndCheckVersions(
+ \OC\Files\Filesystem::getView(),
+ 'folder/test.txt'
+ );
+ }
+
+ /**
+ * Test whether versions are created when overwriting anonymously.
+ *
+ * When uploading through a public link or publicwebdav, no user
+ * is logged in. File modification must still be able to find
+ * the owner and create versions.
+ */
+ public function testStoreVersionAsAnonymous() {
+ $this->logout();
+
+ // note: public link upload does this,
+ // needed to make the hooks fire
+ \OC_Util::setupFS(self::TEST_VERSIONS_USER);
+
+ $userView = new \OC\Files\View('/' . self::TEST_VERSIONS_USER . '/files');
+ $this->createAndCheckVersions(
+ $userView,
+ 'test.txt'
+ );
+ }
+
+ private function createAndCheckVersions($view, $path) {
+ $view->file_put_contents($path, 'test file');
+ $view->file_put_contents($path, 'version 1');
+ $view->file_put_contents($path, 'version 2');
+
+ $this->loginAsUser(self::TEST_VERSIONS_USER);
+
+ // need to scan for the versions
+ list($rootStorage,) = $this->rootView->resolvePath(self::TEST_VERSIONS_USER . '/files_versions');
+ $rootStorage->getScanner()->scan('files_versions');
+
+ $versions = \OCA\Files_Versions\Storage::getVersions(
+ self::TEST_VERSIONS_USER, '/' . $path
+ );
+
+ // note: we cannot predict how many versions are created due to
+ // test run timing
+ $this->assertGreaterThan(0, count($versions));
+ }
+
+ /**
* @param string $user
* @param bool $create
* @param bool $password