summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2014-11-06 19:24:24 +0100
committerRobin Appelman <robin@icewind.nl>2014-11-06 19:24:24 +0100
commit0c230fb57e400efa9e0de7135a7cdbc857fe98d3 (patch)
tree94fea349b74c2c1b020930e8485b515c81552b31
parentefe209784ee1328556b51d69d3d5df870607fc91 (diff)
parent0f3fd89f7db7e636ec3d27da83b5390238165315 (diff)
downloadnextcloud-server-0c230fb57e400efa9e0de7135a7cdbc857fe98d3.tar.gz
nextcloud-server-0c230fb57e400efa9e0de7135a7cdbc857fe98d3.zip
Merge pull request #11945 from owncloud/share-setup-other-user
Setup shared mounts for the correct user when setting up the filesystem
-rw-r--r--apps/files_sharing/lib/sharedmount.php8
-rw-r--r--apps/files_sharing/lib/sharedstorage.php5
-rw-r--r--apps/files_sharing/tests/api.php3
-rw-r--r--apps/files_sharing/tests/sharedmount.php4
-rw-r--r--apps/files_sharing/tests/sharedstorage.php26
-rw-r--r--apps/files_sharing/tests/testcase.php18
-rw-r--r--lib/private/user/dummy.php21
7 files changed, 71 insertions, 14 deletions
diff --git a/apps/files_sharing/lib/sharedmount.php b/apps/files_sharing/lib/sharedmount.php
index 4ad2d4e6b3e..a93ecfb3b1b 100644
--- a/apps/files_sharing/lib/sharedmount.php
+++ b/apps/files_sharing/lib/sharedmount.php
@@ -22,15 +22,15 @@ class SharedMount extends Mount implements MoveableMount {
public function __construct($storage, $mountpoint, $arguments = null, $loader = null) {
// first update the mount point before creating the parent
- $newMountPoint = self::verifyMountPoint($arguments['share']);
- $absMountPoint = '/' . \OCP\User::getUser() . '/files' . $newMountPoint;
+ $newMountPoint = $this->verifyMountPoint($arguments['share'], $arguments['user']);
+ $absMountPoint = '/' . $arguments['user'] . '/files' . $newMountPoint;
parent::__construct($storage, $absMountPoint, $arguments, $loader);
}
/**
* check if the parent folder exists otherwise move the mount point up
*/
- private static function verifyMountPoint(&$share) {
+ private function verifyMountPoint(&$share, $user) {
$mountPoint = basename($share['file_target']);
$parent = dirname($share['file_target']);
@@ -42,7 +42,7 @@ class SharedMount extends Mount implements MoveableMount {
$newMountPoint = \OCA\Files_Sharing\Helper::generateUniqueTarget(
\OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint),
array(),
- new \OC\Files\View('/' . \OCP\User::getUser() . '/files')
+ new \OC\Files\View('/' . $user . '/files')
);
if($newMountPoint !== $share['file_target']) {
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index 5ce15d9a012..19ee6085e47 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -397,7 +397,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
}
public static function setup($options) {
- $shares = \OCP\Share::getItemsSharedWith('file');
+ $shares = \OCP\Share::getItemsSharedWithUser('file', $options['user']);
$manager = Filesystem::getMountManager();
$loader = Filesystem::getLoader();
if (!\OCP\User::isLoggedIn() || \OCP\User::getUser() != $options['user']
@@ -411,7 +411,8 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
$options['user_dir'] . '/' . $share['file_target'],
array(
'share' => $share,
- ),
+ 'user' => $options['user']
+ ),
$loader
);
$manager->addMount($mount);
diff --git a/apps/files_sharing/tests/api.php b/apps/files_sharing/tests/api.php
index 88acbd8e775..453133fee31 100644
--- a/apps/files_sharing/tests/api.php
+++ b/apps/files_sharing/tests/api.php
@@ -35,6 +35,9 @@ class Test_Files_Sharing_Api extends TestCase {
function setUp() {
parent::setUp();
+ \OC::$server->getAppConfig()->setValue('core', 'shareapi_exclude_groups', 'no');
+ \OC::$server->getAppConfig()->setValue('core', 'shareapi_expire_after_n_days', '7');
+
$this->folder = self::TEST_FOLDER_NAME;
$this->subfolder = '/subfolder_share_api_test';
$this->subsubfolder = '/subsubfolder_share_api_test';
diff --git a/apps/files_sharing/tests/sharedmount.php b/apps/files_sharing/tests/sharedmount.php
index e991d381e14..6d155f174ba 100644
--- a/apps/files_sharing/tests/sharedmount.php
+++ b/apps/files_sharing/tests/sharedmount.php
@@ -226,6 +226,10 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
}
class DummyTestClassSharedMount extends \OCA\Files_Sharing\SharedMount {
+ public function __construct($storage, $mountpoint, $arguments = null, $loader = null){
+ // noop
+ }
+
public function stripUserFilesPathDummy($path) {
return $this->stripUserFilesPath($path);
}
diff --git a/apps/files_sharing/tests/sharedstorage.php b/apps/files_sharing/tests/sharedstorage.php
index b106add1300..ab15e8fe3ba 100644
--- a/apps/files_sharing/tests/sharedstorage.php
+++ b/apps/files_sharing/tests/sharedstorage.php
@@ -197,4 +197,30 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
$this->assertTrue($result);
}
+ function testMountSharesOtherUser() {
+ $folderInfo = $this->view->getFileInfo($this->folder);
+ $fileInfo = $this->view->getFileInfo($this->filename);
+ $rootView = new \OC\Files\View('');
+ self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
+
+ // share 2 different files with 2 different users
+ \OCP\Share::shareItem('folder', $folderInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ self::TEST_FILES_SHARING_API_USER2, 31);
+ \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ self::TEST_FILES_SHARING_API_USER3, 31);
+
+ self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
+ $this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder));
+ OC_Hook::emit('OC_Filesystem', 'setup', array('user' => self::TEST_FILES_SHARING_API_USER3, 'user_dir' => \OC_User::getHome(self::TEST_FILES_SHARING_API_USER3)));
+
+ $this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER3 . '/files/' . $this->filename));
+
+ // make sure we didn't double setup shares for user 2 or mounted the shares for user 3 in user's 2 home
+ $this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder .' (2)'));
+ $this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->filename));
+
+ //cleanup
+ self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
+ $this->view->unlink($this->folder);
+ }
}
diff --git a/apps/files_sharing/tests/testcase.php b/apps/files_sharing/tests/testcase.php
index a098feb550d..78277dc907f 100644
--- a/apps/files_sharing/tests/testcase.php
+++ b/apps/files_sharing/tests/testcase.php
@@ -65,13 +65,21 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
\OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup');
// create users
- self::loginHelper(self::TEST_FILES_SHARING_API_USER1, true);
- self::loginHelper(self::TEST_FILES_SHARING_API_USER2, true);
- self::loginHelper(self::TEST_FILES_SHARING_API_USER3, true);
+ $backend = new \OC_User_Dummy();
+ \OC_User::useBackend($backend);
+ $backend->createUser(self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER1);
+ $backend->createUser(self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_USER2);
+ $backend->createUser(self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER3);
// create group
- \OC_Group::createGroup(self::TEST_FILES_SHARING_API_GROUP1);
- \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_GROUP1);
+ $groupBackend = new \OC_Group_Dummy();
+ $groupBackend->createGroup(self::TEST_FILES_SHARING_API_GROUP1);
+ $groupBackend->createGroup('group');
+ $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, self::TEST_FILES_SHARING_API_GROUP1);
+ \OC_Group::useBackend($groupBackend);
}
diff --git a/lib/private/user/dummy.php b/lib/private/user/dummy.php
index dbcbb2a46f7..fd0201734fa 100644
--- a/lib/private/user/dummy.php
+++ b/lib/private/user/dummy.php
@@ -26,9 +26,11 @@
*/
class OC_User_Dummy extends OC_User_Backend {
private $users = array();
+ private $displayNames = array();
/**
* Create a new user
+ *
* @param string $uid The username of the user to create
* @param string $password The password of the new user
* @return bool
@@ -47,6 +49,7 @@ class OC_User_Dummy extends OC_User_Backend {
/**
* delete a user
+ *
* @param string $uid The username of the user to delete
* @return bool
*
@@ -63,6 +66,7 @@ class OC_User_Dummy extends OC_User_Backend {
/**
* Set password
+ *
* @param string $uid The username
* @param string $password The new password
* @return bool
@@ -80,6 +84,7 @@ class OC_User_Dummy extends OC_User_Backend {
/**
* Check if the password is correct
+ *
* @param string $uid The username
* @param string $password The password
* @return string
@@ -97,6 +102,7 @@ class OC_User_Dummy extends OC_User_Backend {
/**
* Get a list of all users
+ *
* @param string $search
* @param int $limit
* @param int $offset
@@ -105,12 +111,12 @@ class OC_User_Dummy extends OC_User_Backend {
* Get a list of all users.
*/
public function getUsers($search = '', $limit = null, $offset = null) {
- if(empty($search)) {
+ if (empty($search)) {
return array_keys($this->users);
}
$result = array();
- foreach(array_keys($this->users) as $user) {
- if(stripos($user, $search) !== false) {
+ foreach (array_keys($this->users) as $user) {
+ if (stripos($user, $search) !== false) {
$result[] = $user;
}
}
@@ -119,6 +125,7 @@ class OC_User_Dummy extends OC_User_Backend {
/**
* check if a user exists
+ *
* @param string $uid the username
* @return boolean
*/
@@ -141,4 +148,12 @@ class OC_User_Dummy extends OC_User_Backend {
public function countUsers() {
return 0;
}
+
+ public function setDisplayName($uid, $displayName) {
+ $this->displayNames[$uid] = $displayName;
+ }
+
+ public function getDisplayName($uid) {
+ return isset($this->displayNames[$uid])? $this->displayNames[$uid]: $uid;
+ }
}