diff --git a/apps/files_sharing/appinfo/application.php b/apps/files_sharing/appinfo/application.php
index 9dc0e0618b54..252bba17a380 100644
--- a/apps/files_sharing/appinfo/application.php
+++ b/apps/files_sharing/appinfo/application.php
@@ -136,7 +136,9 @@ function() use ($c) {
$server = $c->query('ServerContainer');
return new PropagationManager(
$server->getUserSession(),
- $server->getConfig()
+ $server->getConfig(),
+ $server->getGroupManager(),
+ $server->getUserManager()
);
});
diff --git a/apps/files_sharing/lib/mountprovider.php b/apps/files_sharing/lib/mountprovider.php
index 458e7f2619bd..d1ec254a70f3 100644
--- a/apps/files_sharing/lib/mountprovider.php
+++ b/apps/files_sharing/lib/mountprovider.php
@@ -60,7 +60,7 @@ public function __construct(IConfig $config, PropagationManager $propagationMana
*/
public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) {
$shares = \OCP\Share::getItemsSharedWithUser('file', $user->getUID());
- $propagator = $this->propagationManager->getSharePropagator($user->getUID());
+ $propagator = $this->propagationManager->getSharePropagator($user);
$propagator->propagateDirtyMountPoints($shares);
$shares = array_filter($shares, function ($share) {
return $share['permissions'] > 0;
diff --git a/apps/files_sharing/lib/propagation/propagationmanager.php b/apps/files_sharing/lib/propagation/propagationmanager.php
index 6ed70e93f848..0f24d667f560 100644
--- a/apps/files_sharing/lib/propagation/propagationmanager.php
+++ b/apps/files_sharing/lib/propagation/propagationmanager.php
@@ -24,6 +24,9 @@
use OC\Files\Filesystem;
use OC\Files\View;
use OCP\IConfig;
+use OCP\IGroupManager;
+use OCP\IUser;
+use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Util;
@@ -56,9 +59,21 @@ class PropagationManager {
*/
private $sharePropagators = [];
- public function __construct(IUserSession $userSession, IConfig $config) {
+ /**
+ * @var IGroupManager
+ */
+ private $groupManager;
+
+ /**
+ * @var IUserManager
+ */
+ private $userManager;
+
+ public function __construct(IUserSession $userSession, IConfig $config, IGroupManager $groupManager, IUserManager $userManager) {
$this->userSession = $userSession;
$this->config = $config;
+ $this->groupManager = $groupManager;
+ $this->userManager = $userManager;
}
/**
@@ -97,15 +112,18 @@ public function propagateSharesToUser($shares, $user) {
}
/**
- * @param string $user
+ * @param IUser|string $user
* @return \OCA\Files_Sharing\Propagation\RecipientPropagator
*/
public function getSharePropagator($user) {
- if (isset($this->sharePropagators[$user])) {
- return $this->sharePropagators[$user];
+ if (!$user instanceof IUser) {
+ $user = $this->userManager->get($user);
+ }
+ if (isset($this->sharePropagators[$user->getUID()])) {
+ return $this->sharePropagators[$user->getUID()];
}
- $this->sharePropagators[$user] = new RecipientPropagator($user, $this->getChangePropagator($user), $this->config, $this);
- return $this->sharePropagators[$user];
+ $this->sharePropagators[$user->getUID()] = new RecipientPropagator($user, $this->getChangePropagator($user->getUID()), $this->config, $this, $this->groupManager);
+ return $this->sharePropagators[$user->getUID()];
}
/**
@@ -130,7 +148,7 @@ public function globalSetup() {
if (!$user) {
return;
}
- $recipientPropagator = $this->getSharePropagator($user->getUID());
+ $recipientPropagator = $this->getSharePropagator($user);
$watcher = new ChangeWatcher(Filesystem::getView(), $recipientPropagator);
// for marking shares owned by the active user as dirty when a file inside them changes
diff --git a/apps/files_sharing/lib/propagation/recipientpropagator.php b/apps/files_sharing/lib/propagation/recipientpropagator.php
index 8e064e2ee545..e71208fd6cd2 100644
--- a/apps/files_sharing/lib/propagation/recipientpropagator.php
+++ b/apps/files_sharing/lib/propagation/recipientpropagator.php
@@ -25,6 +25,8 @@
use OC\Files\Cache\ChangePropagator;
use OC\Files\View;
use OC\Share\Share;
+use OCP\IGroupManager;
+use OCP\IUser;
/**
* Propagate etags for share recipients
@@ -51,18 +53,31 @@ class RecipientPropagator {
private $manager;
/**
- * @param string $userId current user, must match the propagator's
+ * @var IGroupManager
+ */
+ private $groupManager;
+
+ /**
+ * @var IUser
+ */
+ private $user;
+
+ /**
+ * @param IUser $user current user, must match the propagator's
* user
* @param \OC\Files\Cache\ChangePropagator $changePropagator change propagator
* initialized with a view for $user
* @param \OCP\IConfig $config
* @param PropagationManager $manager
+ * @param IGroupManager $groupManager
*/
- public function __construct($userId, $changePropagator, $config, PropagationManager $manager) {
- $this->userId = $userId;
+ public function __construct(IUser $user, $changePropagator, $config, PropagationManager $manager, IGroupManager $groupManager) {
+ $this->userId = $user->getUID();
+ $this->user = $user;
$this->changePropagator = $changePropagator;
$this->config = $config;
$this->manager = $manager;
+ $this->groupManager = $groupManager;
}
/**
@@ -139,7 +154,7 @@ public function propagateById($id) {
$this->markDirty($share, microtime(true));
// propagate up the share tree
- if ($share['share_with'] === $this->userId) {
+ if ($this->isRecipientOfShare($share)) {
$user = $share['uid_owner'];
$view = new View('/' . $user . '/files');
$path = $view->getPath($share['file_source']);
@@ -150,4 +165,21 @@ public function propagateById($id) {
unset($this->propagatingIds[$id]);
}
+
+ /**
+ * Check if the user for this recipient propagator is the recipient of a share
+ *
+ * @param array $share
+ * @return bool
+ */
+ private function isRecipientOfShare($share) {
+ if ($share['share_with'] === $this->userId && $share['share_type'] == \OCP\Share::SHARE_TYPE_USER) { // == since 'share_type' is a string
+ return true;
+ }
+ if ($share['share_type'] == \OCP\Share::SHARE_TYPE_GROUP) {
+ $groups = $this->groupManager->getUserGroupIds($this->user);
+ return in_array($share['share_with'], $groups);
+ }
+ return false;
+ }
}
diff --git a/apps/files_sharing/tests/etagpropagation.php b/apps/files_sharing/tests/etagpropagation.php
index 2490fef03e19..c72bf7a9f674 100644
--- a/apps/files_sharing/tests/etagpropagation.php
+++ b/apps/files_sharing/tests/etagpropagation.php
@@ -25,32 +25,14 @@
use OC\Files\Filesystem;
use OC\Files\View;
-class EtagPropagation extends TestCase {
- /**
- * @var \OC\Files\View
- */
- private $rootView;
- protected $fileIds = []; // [$user=>[$path=>$id]]
- protected $fileEtags = []; // [$id=>$etag]
-
- public static function setUpBeforeClass() {
- parent::setUpBeforeClass();
- \OCA\Files_Sharing\Helper::registerHooks();
- }
-
- protected function setUp() {
- parent::setUp();
- $this->setUpShares();
- }
-
- protected function tearDown() {
- \OC_Hook::clear('OC_Filesystem', 'post_write');
- \OC_Hook::clear('OC_Filesystem', 'post_delete');
- \OC_Hook::clear('OC_Filesystem', 'post_rename');
- \OC_Hook::clear('OCP\Share', 'post_update_permissions');
- parent::tearDown();
- }
-
+/**
+ * Class EtagPropagation
+ *
+ * @group DB
+ *
+ * @package OCA\Files_sharing\Tests
+ */
+class EtagPropagation extends PropagationTestCase {
/**
* "user1" is the admin who shares a folder "sub1/sub2/folder" with "user2" and "user3"
* "user2" receives the folder and puts it in "sub1/sub2/folder"
@@ -58,7 +40,7 @@ protected function tearDown() {
* "user2" reshares the subdir "sub1/sub2/folder/inside" with "user4"
* "user4" puts the received "inside" folder into "sub1/sub2/inside" (this is to check if it propagates across multiple subfolders)
*/
- private function setUpShares() {
+ protected function setUpShares() {
$this->fileIds[self::TEST_FILES_SHARING_API_USER1] = [];
$this->fileIds[self::TEST_FILES_SHARING_API_USER2] = [];
$this->fileIds[self::TEST_FILES_SHARING_API_USER3] = [];
@@ -127,58 +109,6 @@ private function setUpShares() {
}
}
- /**
- * @param string[] $users
- * @param string $subPath
- */
- private function assertEtagsChanged($users, $subPath = '') {
- $oldUser = \OC::$server->getUserSession()->getUser();
- foreach ($users as $user) {
- $this->loginAsUser($user);
- $id = $this->fileIds[$user][$subPath];
- $path = $this->rootView->getPath($id);
- $etag = $this->rootView->getFileInfo($path)->getEtag();
- $this->assertNotEquals($this->fileEtags[$id], $etag, 'Failed asserting that the etag for "' . $subPath . '" of user ' . $user . ' has changed');
- $this->fileEtags[$id] = $etag;
- }
- $this->loginAsUser($oldUser->getUID());
- }
-
- /**
- * @param string[] $users
- * @param string $subPath
- */
- private function assertEtagsNotChanged($users, $subPath = '') {
- $oldUser = \OC::$server->getUserSession()->getUser();
- foreach ($users as $user) {
- $this->loginAsUser($user);
- $id = $this->fileIds[$user][$subPath];
- $path = $this->rootView->getPath($id);
- $etag = $this->rootView->getFileInfo($path)->getEtag();
- $this->assertEquals($this->fileEtags[$id], $etag, 'Failed asserting that the etag for "' . $subPath . '" of user ' . $user . ' has not changed');
- $this->fileEtags[$id] = $etag;
- }
- $this->loginAsUser($oldUser->getUID());
- }
-
- /**
- * Assert that the etags for the root, /sub1 and /sub1/sub2 have changed
- *
- * @param string[] $users
- */
- private function assertEtagsForFoldersChanged($users) {
- $this->assertEtagsChanged($users);
-
- $this->assertEtagsChanged($users, 'sub1');
- $this->assertEtagsChanged($users, 'sub1/sub2');
- }
-
- private function assertAllUnchaged() {
- $users = [self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
- self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4];
- $this->assertEtagsNotChanged($users);
- }
-
public function testOwnerWritesToShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
Filesystem::file_put_contents('/sub1/sub2/folder/asd.txt', 'bar');
@@ -186,7 +116,7 @@ public function testOwnerWritesToShare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testOwnerWritesToSingleFileShare() {
@@ -195,7 +125,7 @@ public function testOwnerWritesToSingleFileShare() {
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER4, self::TEST_FILES_SHARING_API_USER3]);
$this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testOwnerWritesToShareWithReshare() {
@@ -204,7 +134,7 @@ public function testOwnerWritesToShareWithReshare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testOwnerRenameInShare() {
@@ -214,7 +144,7 @@ public function testOwnerRenameInShare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testOwnerRenameInReShare() {
@@ -223,7 +153,7 @@ public function testOwnerRenameInReShare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testOwnerRenameIntoReShare() {
@@ -232,7 +162,7 @@ public function testOwnerRenameIntoReShare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testOwnerRenameOutOfReShare() {
@@ -241,7 +171,7 @@ public function testOwnerRenameOutOfReShare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testOwnerDeleteInShare() {
@@ -251,7 +181,7 @@ public function testOwnerDeleteInShare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testOwnerDeleteInReShare() {
@@ -260,7 +190,7 @@ public function testOwnerDeleteInReShare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testOwnerUnshares() {
@@ -283,7 +213,7 @@ public function testOwnerUnshares() {
self::TEST_FILES_SHARING_API_USER4,
]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testRecipientUnsharesFromSelf() {
@@ -298,7 +228,7 @@ public function testRecipientUnsharesFromSelf() {
self::TEST_FILES_SHARING_API_USER4,
]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testRecipientWritesToShare() {
@@ -308,7 +238,7 @@ public function testRecipientWritesToShare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testRecipientWritesToReshare() {
@@ -317,7 +247,7 @@ public function testRecipientWritesToReshare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testRecipientWritesToOtherRecipientsReshare() {
@@ -326,7 +256,7 @@ public function testRecipientWritesToOtherRecipientsReshare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testRecipientRenameInShare() {
@@ -336,7 +266,7 @@ public function testRecipientRenameInShare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testRecipientRenameInReShare() {
@@ -345,7 +275,7 @@ public function testRecipientRenameInReShare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testRecipientRenameResharedFolder() {
@@ -356,7 +286,7 @@ public function testRecipientRenameResharedFolder() {
$this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER2], 'sub1');
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testRecipientDeleteInShare() {
@@ -366,7 +296,7 @@ public function testRecipientDeleteInShare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testRecipientDeleteInReShare() {
@@ -375,7 +305,7 @@ public function testRecipientDeleteInReShare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testReshareRecipientWritesToReshare() {
@@ -384,7 +314,7 @@ public function testReshareRecipientWritesToReshare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testReshareRecipientRenameInReShare() {
@@ -393,7 +323,7 @@ public function testReshareRecipientRenameInReShare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testReshareRecipientDeleteInReShare() {
@@ -402,7 +332,7 @@ public function testReshareRecipientDeleteInReShare() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testRecipientUploadInDirectReshare() {
@@ -411,7 +341,7 @@ public function testRecipientUploadInDirectReshare() {
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER3]);
$this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_USER4]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
public function testEtagChangeOnPermissionsChange() {
@@ -424,6 +354,6 @@ public function testEtagChangeOnPermissionsChange() {
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_USER4]);
- $this->assertAllUnchaged();
+ $this->assertAllUnchanged();
}
}
diff --git a/apps/files_sharing/tests/groupetagpropagation.php b/apps/files_sharing/tests/groupetagpropagation.php
new file mode 100644
index 000000000000..804d064eadb8
--- /dev/null
+++ b/apps/files_sharing/tests/groupetagpropagation.php
@@ -0,0 +1,104 @@
+
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see
+ *
+ */
+
+namespace OCA\Files_sharing\Tests;
+
+use OC\Files\Filesystem;
+use OC\Files\View;
+
+/**
+ * @group DB
+ *
+ * @package OCA\Files_sharing\Tests
+ */
+class GroupEtagPropagation extends PropagationTestCase {
+ /**
+ * "user1" creates /test, /test/sub and shares with group1
+ * "user2" (in group1) reshares /test with group2 and reshared /test/sub with group3
+ * "user3" (in group 2)
+ * "user4" (in group 3)
+ */
+ protected function setUpShares() {
+ $this->fileIds[self::TEST_FILES_SHARING_API_USER1] = [];
+ $this->fileIds[self::TEST_FILES_SHARING_API_USER2] = [];
+ $this->fileIds[self::TEST_FILES_SHARING_API_USER3] = [];
+ $this->fileIds[self::TEST_FILES_SHARING_API_USER4] = [];
+
+ $this->rootView = new View('');
+ $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
+ $view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
+ $view1->mkdir('/test/sub');
+ $folderInfo = $view1->getFileInfo('/test');
+ \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group1', 31);
+ $this->fileIds[self::TEST_FILES_SHARING_API_USER1][''] = $view1->getFileInfo('')->getId();
+ $this->fileIds[self::TEST_FILES_SHARING_API_USER1]['test'] = $view1->getFileInfo('test')->getId();
+ $this->fileIds[self::TEST_FILES_SHARING_API_USER1]['test/sub'] = $view1->getFileInfo('test/sub')->getId();
+
+ $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
+ $view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
+ $folderInfo = $view2->getFileInfo('/test');
+ $subFolderInfo = $view2->getFileInfo('/test/sub');
+ \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group2', 31);
+ \OCP\Share::shareItem('folder', $subFolderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group3', 31);
+ $this->fileIds[self::TEST_FILES_SHARING_API_USER2][''] = $view2->getFileInfo('')->getId();
+ $this->fileIds[self::TEST_FILES_SHARING_API_USER2]['test'] = $view2->getFileInfo('test')->getId();
+ $this->fileIds[self::TEST_FILES_SHARING_API_USER2]['test/sub'] = $view2->getFileInfo('test/sub')->getId();
+
+ $this->loginAsUser(self::TEST_FILES_SHARING_API_USER3);
+ $view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
+ $this->fileIds[self::TEST_FILES_SHARING_API_USER3][''] = $view3->getFileInfo('')->getId();
+ $this->fileIds[self::TEST_FILES_SHARING_API_USER3]['test'] = $view3->getFileInfo('test')->getId();
+ $this->fileIds[self::TEST_FILES_SHARING_API_USER3]['test/sub'] = $view3->getFileInfo('test/sub')->getId();
+
+ $this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
+ $view4 = new View('/' . self::TEST_FILES_SHARING_API_USER4 . '/files');
+ $this->fileIds[self::TEST_FILES_SHARING_API_USER4][''] = $view4->getFileInfo('')->getId();
+ $this->fileIds[self::TEST_FILES_SHARING_API_USER4]['sub'] = $view4->getFileInfo('sub')->getId();
+
+ foreach ($this->fileIds as $user => $ids) {
+ $this->loginAsUser($user);
+ foreach ($ids as $id) {
+ $path = $this->rootView->getPath($id);
+ $this->fileEtags[$id] = $this->rootView->getFileInfo($path)->getEtag();
+ }
+ }
+ }
+
+ public function testGroupReShareRecipientWrites() {
+ $this->loginAsUser(self::TEST_FILES_SHARING_API_USER3);
+
+ Filesystem::file_put_contents('/test/sub/file.txt', 'asd');
+
+ $this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
+
+ $this->assertAllUnchanged();
+ }
+
+ public function testGroupReShareSubFolderRecipientWrites() {
+ $this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
+
+ Filesystem::file_put_contents('/sub/file.txt', 'asd');
+
+ $this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
+
+ $this->assertAllUnchanged();
+ }
+}
diff --git a/apps/files_sharing/tests/propagationtestcase.php b/apps/files_sharing/tests/propagationtestcase.php
new file mode 100644
index 000000000000..f397c1fb7a0a
--- /dev/null
+++ b/apps/files_sharing/tests/propagationtestcase.php
@@ -0,0 +1,103 @@
+
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see
+ *
+ */
+
+namespace OCA\Files_sharing\Tests;
+
+abstract class PropagationTestCase extends TestCase {
+ /**
+ * @var \OC\Files\View
+ */
+ protected $rootView;
+ protected $fileIds = []; // [$user=>[$path=>$id]]
+ protected $fileEtags = []; // [$id=>$etag]
+
+ public static function setUpBeforeClass() {
+ parent::setUpBeforeClass();
+ \OCA\Files_Sharing\Helper::registerHooks();
+ }
+
+ protected function setUp() {
+ parent::setUp();
+ $this->setUpShares();
+ }
+
+ protected function tearDown() {
+ \OC_Hook::clear('OC_Filesystem', 'post_write');
+ \OC_Hook::clear('OC_Filesystem', 'post_delete');
+ \OC_Hook::clear('OC_Filesystem', 'post_rename');
+ \OC_Hook::clear('OCP\Share', 'post_update_permissions');
+ parent::tearDown();
+ }
+
+ abstract protected function setUpShares();
+
+ /**
+ * @param string[] $users
+ * @param string $subPath
+ */
+ protected function assertEtagsChanged($users, $subPath = '') {
+ $oldUser = \OC::$server->getUserSession()->getUser();
+ foreach ($users as $user) {
+ $this->loginAsUser($user);
+ $id = $this->fileIds[$user][$subPath];
+ $path = $this->rootView->getPath($id);
+ $etag = $this->rootView->getFileInfo($path)->getEtag();
+ $this->assertNotEquals($this->fileEtags[$id], $etag, 'Failed asserting that the etag for "' . $subPath . '" of user ' . $user . ' has changed');
+ $this->fileEtags[$id] = $etag;
+ }
+ $this->loginAsUser($oldUser->getUID());
+ }
+
+ /**
+ * @param string[] $users
+ * @param string $subPath
+ */
+ protected function assertEtagsNotChanged($users, $subPath = '') {
+ $oldUser = \OC::$server->getUserSession()->getUser();
+ foreach ($users as $user) {
+ $this->loginAsUser($user);
+ $id = $this->fileIds[$user][$subPath];
+ $path = $this->rootView->getPath($id);
+ $etag = $this->rootView->getFileInfo($path)->getEtag();
+ $this->assertEquals($this->fileEtags[$id], $etag, 'Failed asserting that the etag for "' . $subPath . '" of user ' . $user . ' has not changed');
+ $this->fileEtags[$id] = $etag;
+ }
+ $this->loginAsUser($oldUser->getUID());
+ }
+
+ /**
+ * Assert that the etags for the root, /sub1 and /sub1/sub2 have changed
+ *
+ * @param string[] $users
+ */
+ protected function assertEtagsForFoldersChanged($users) {
+ $this->assertEtagsChanged($users);
+
+ $this->assertEtagsChanged($users, 'sub1');
+ $this->assertEtagsChanged($users, 'sub1/sub2');
+ }
+
+ protected function assertAllUnchanged() {
+ $users = [self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
+ self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4];
+ $this->assertEtagsNotChanged($users);
+ }
+}
diff --git a/apps/files_sharing/tests/testcase.php b/apps/files_sharing/tests/testcase.php
index c91734a5b03c..863280d802fb 100644
--- a/apps/files_sharing/tests/testcase.php
+++ b/apps/files_sharing/tests/testcase.php
@@ -83,9 +83,15 @@ public static function setUpBeforeClass() {
$groupBackend = new \OC_Group_Dummy();
$groupBackend->createGroup(self::TEST_FILES_SHARING_API_GROUP1);
$groupBackend->createGroup('group');
+ $groupBackend->createGroup('group1');
+ $groupBackend->createGroup('group2');
+ $groupBackend->createGroup('group3');
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER1, 'group');
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER2, 'group');
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER3, 'group');
+ $groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER2, 'group1');
+ $groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER3, 'group2');
+ $groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER4, 'group3');
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_GROUP1);
\OC_Group::useBackend($groupBackend);