diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-06-24 17:04:27 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-06-25 12:11:56 +0200 |
commit | a0b85fc5e4a56ff553f224083cbdf87cd05ec55a (patch) | |
tree | b44fc4364013d26f2f477ab822ebfb5fd6c7891f /apps/files_sharing | |
parent | 89f26915152e5aaf357b2aa633d5bea954e4bcc2 (diff) | |
download | nextcloud-server-a0b85fc5e4a56ff553f224083cbdf87cd05ec55a.tar.gz nextcloud-server-a0b85fc5e4a56ff553f224083cbdf87cd05ec55a.zip |
make sure that during share and unshare the etags get propagated correctly
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/appinfo/app.php | 4 | ||||
-rw-r--r-- | apps/files_sharing/lib/updater.php | 62 | ||||
-rw-r--r-- | apps/files_sharing/tests/updater.php | 106 |
3 files changed, 172 insertions, 0 deletions
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index a4a0a57c675..412ca66b82e 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -28,6 +28,10 @@ OCP\Util::addScript('files_sharing', 'external'); \OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Shared_Updater', 'renameHook'); \OC_Hook::connect('OC_Appconfig', 'post_set_value', '\OCA\Files\Share\Maintainer', 'configChangeHook'); +\OCP\Util::connectHook('OCP\Share', 'post_shared', '\OC\Files\Cache\Shared_Updater', 'postShareHook'); +\OCP\Util::connectHook('OCP\Share', 'post_unshare', '\OC\Files\Cache\Shared_Updater', 'postUnshareHook'); +\OCP\Util::connectHook('OCP\Share', 'post_unshareFromSelf', '\OC\Files\Cache\Shared_Updater', 'postUnshareFromSelfHook'); + OC_FileProxy::register(new OCA\Files\Share\Proxy()); \OCA\Files\App::getNavigationManager()->add( diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index 5cb2b638e5a..e114c3ba0ac 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -133,6 +133,68 @@ class Shared_Updater { } /** + * update etags if a file was shared + * @param array $params + */ + static public function postShareHook($params) { + + if ($params['itemType'] === 'folder' || $params['itemType'] === 'file') { + + $shareWith = $params['shareWith']; + $shareType = $params['shareType']; + + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { + self::correctUsersFolder($shareWith, '/'); + } elseif ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { + foreach (\OC_Group::usersInGroup($shareWith) as $user) { + self::correctUsersFolder($user, '/'); + } + } + } + } + + /** + * update etags if a file was unshared + * + * @param array $params + */ + static public function postUnshareHook($params) { + + if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { + + $deletedShares = isset($params['deletedShares']) ? $params['deletedShares'] : array(); + + foreach ($deletedShares as $share) { + if ($share['shareType'] === \OCP\Share::SHARE_TYPE_GROUP) { + foreach (\OC_Group::usersInGroup($share['shareWith']) as $user) { + self::correctUsersFolder($user, dirname($share['fileTarget'])); + } + } else { + self::correctUsersFolder($share['shareWith'], dirname($share['fileTarget'])); + } + } + } + } + + /** + * update etags if file was unshared from self + * @param array $params + */ + static public function postUnshareFromSelfHook($params) { + if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { + foreach ($params['unsharedItems'] as $item) { + if ($item['shareType'] === \OCP\Share::SHARE_TYPE_GROUP) { + foreach (\OC_Group::usersInGroup($item['shareWith']) as $user) { + self::correctUsersFolder($user, dirname($item['fileTarget'])); + } + } else { + self::correctUsersFolder($item['shareWith'], dirname($item['fileTarget'])); + } + } + } + } + + /** * clean up oc_share table from files which are no longer exists * * This fixes issues from updates from files_sharing < 0.3.5.6 (ownCloud 4.5) diff --git a/apps/files_sharing/tests/updater.php b/apps/files_sharing/tests/updater.php index 8183e7067a4..c0099b4ded1 100644 --- a/apps/files_sharing/tests/updater.php +++ b/apps/files_sharing/tests/updater.php @@ -104,6 +104,112 @@ class Test_Files_Sharing_Updater extends Test_Files_Sharing_Base { if ($status === false) { \OC_App::disable('files_trashbin'); } + // cleanup + $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); + $result = \OCP\Share::unshare('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2); + $this->assertTrue($result); + } + + /** + * if a file gets shared the etag for the recipients root should change + */ + function testShareFile() { + $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); + + $beforeShare = \OC\Files\Filesystem::getFileInfo(''); + $etagBeforeShare = $beforeShare->getEtag(); + + $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); + $fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder); + $result = \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31); + $this->assertTrue($result); + + $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); + + $afterShare = \OC\Files\Filesystem::getFileInfo(''); + $etagAfterShare = $afterShare->getEtag(); + + $this->assertTrue(is_string($etagBeforeShare)); + $this->assertTrue(is_string($etagAfterShare)); + $this->assertTrue($etagBeforeShare !== $etagAfterShare); + + // cleanup + $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); + $result = \OCP\Share::unshare('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2); + $this->assertTrue($result); + } + + /** + * if a file gets unshared by the owner the etag for the recipients root should change + */ + function testUnshareFile() { + + $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); + $fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder); + $result = \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31); + $this->assertTrue($result); + + $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); + + $beforeUnshare = \OC\Files\Filesystem::getFileInfo(''); + $etagBeforeUnshare = $beforeUnshare->getEtag(); + + $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); + $result = \OCP\Share::unshare('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2); + $this->assertTrue($result); + + $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); + + $afterUnshare = \OC\Files\Filesystem::getFileInfo(''); + $etagAfterUnshare = $afterUnshare->getEtag(); + + $this->assertTrue(is_string($etagBeforeUnshare)); + $this->assertTrue(is_string($etagAfterUnshare)); + $this->assertTrue($etagBeforeUnshare !== $etagAfterUnshare); + + } + + /** + * if a file gets unshared from self the etag for the recipients root should change + */ + function testUnshareFromSelfFile() { + $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); + $fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder); + $result = \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31); + $this->assertTrue($result); + + $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); + + $result = \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3, 31); + + $beforeUnshareUser2 = \OC\Files\Filesystem::getFileInfo(''); + $etagBeforeUnshareUser2 = $beforeUnshareUser2->getEtag(); + + $this->loginHelper(self::TEST_FILES_SHARING_API_USER3); + + $beforeUnshareUser3 = \OC\Files\Filesystem::getFileInfo(''); + $etagBeforeUnshareUser3 = $beforeUnshareUser3->getEtag(); + + $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); + + $result = \OC\Files\Filesystem::unlink($this->folder); + $this->assertTrue($result); + + $afterUnshareUser2 = \OC\Files\Filesystem::getFileInfo(''); + $etagAfterUnshareUser2 = $afterUnshareUser2->getEtag(); + + $this->loginHelper(self::TEST_FILES_SHARING_API_USER3); + + $afterUnshareUser3 = \OC\Files\Filesystem::getFileInfo(''); + $etagAfterUnshareUser3 = $afterUnshareUser3->getEtag(); + + $this->assertTrue(is_string($etagBeforeUnshareUser2)); + $this->assertTrue(is_string($etagBeforeUnshareUser3)); + $this->assertTrue(is_string($etagAfterUnshareUser2)); + $this->assertTrue(is_string($etagAfterUnshareUser3)); + $this->assertTrue($etagBeforeUnshareUser2 !== $etagAfterUnshareUser2); + $this->assertTrue($etagBeforeUnshareUser3 !== $etagAfterUnshareUser3); + } } |