]> source.dussan.org Git - nextcloud-server.git/commitdiff
[Sharing 2.0] Use the rootfolder to get the path of a share
authorRoeland Jago Douma <rullzer@owncloud.com>
Tue, 24 Nov 2015 09:16:02 +0000 (10:16 +0100)
committerRoeland Jago Douma <rullzer@owncloud.com>
Tue, 24 Nov 2015 09:26:36 +0000 (10:26 +0100)
We need to use the rootfolder here since we also other people than the
shareOwner can request a share.

apps/files_sharing/api/ocssharewrapper.php
apps/files_sharing/api/share20ocs.php
apps/files_sharing/tests/api/share20ocstest.php

index 2a2c16da1f3aeb6ad41ed1b132fab513e0a2bdb8..ca04c656c285fe07d279c494fc09d482b90d09ae 100644 (file)
@@ -40,7 +40,7 @@ class OCSShareWrapper {
                        \OC::$server->getGroupManager(),
                        \OC::$server->getUserManager(),
                        \OC::$server->getRequest(),
-                       \OC::$server->getUserFolder(),
+                       \OC::$server->getRootFolder(),
                        \OC::$server->getURLGenerator(),
                        \OC::$server->getUserSession()->getUser());
        }
index 1f27168c705f6e2253abadf5f630a1d0a5d3ccb2..6c25b4a44261b13549fca238c33e7bc8b2c93a2f 100644 (file)
@@ -28,6 +28,7 @@ use OCP\IRequest;
 use OCP\Files\Folder;
 use OCP\IURLGenerator;
 use OCP\IUser;
+use OCP\Files\IRootFolder;
 
 class Share20OCS {
 
@@ -43,8 +44,8 @@ class Share20OCS {
        /** @var IRequest */
        private $request;
 
-       /** @var Folder */
-       private $userFolder;
+       /** @var IRootFolder */
+       private $rootFolder;
 
        /** @var IUrlGenerator */
        private $urlGenerator;
@@ -57,7 +58,7 @@ class Share20OCS {
                        IGroupManager $groupManager,
                        IUserManager $userManager,
                        IRequest $request,
-                       Folder $userFolder,
+                       IRootFolder $rootFolder,
                        IURLGenerator $urlGenerator,
                        IUser $currentUser
        ) {
@@ -65,7 +66,7 @@ class Share20OCS {
                $this->userManager = $userManager;
                $this->groupManager = $groupManager;
                $this->request = $request;
-               $this->userFolder = $userFolder;
+               $this->rootFolder = $rootFolder;
                $this->urlGenerator = $urlGenerator;
                $this->currentUser = $currentUser;
        }
@@ -90,7 +91,7 @@ class Share20OCS {
                ];
 
                $path = $share->getPath();
-               $result['path'] = $this->userFolder->getRelativePath($path->getPath());
+               $result['path'] = $this->rootFolder->getUserFolder($share->getShareOwner()->getUID())->getRelativePath($path->getPath());
                if ($path instanceOf \OCP\Files\Folder) {
                        $result['item_type'] = 'folder';
                } else {
index fb37824b33708149fafda5eb029aee8743377fbe..b7c56fe17f6a51c2123bbd4de9f38de2a152618b 100644 (file)
@@ -25,9 +25,9 @@ use OCA\Files_Sharing\API\Share20OCS;
 use OCP\IGroupManager;
 use OCP\IUserManager;
 use OCP\IRequest;
-use OCP\Files\Folder;
 use OCP\IURLGenerator;
 use OCP\IUser;
+use OCP\Files\IRootFolder;
 
 class Share20OCSTest extends \Test\TestCase {
 
@@ -43,8 +43,8 @@ class Share20OCSTest extends \Test\TestCase {
        /** @var IRequest */
        private $request;
 
-       /** @var Folder */
-       private $userFolder;
+       /** @var IRootFolder */
+       private $rootFolder;
 
        /** @var IURLGenerator */
        private $urlGenerator;
@@ -62,7 +62,7 @@ class Share20OCSTest extends \Test\TestCase {
                $this->groupManager = $this->getMock('OCP\IGroupManager');
                $this->userManager = $this->getMock('OCP\IUserManager');
                $this->request = $this->getMock('OCP\IRequest');
-               $this->userFolder = $this->getMock('OCP\Files\Folder');
+               $this->rootFolder = $this->getMock('OCP\Files\IRootFolder');
                $this->urlGenerator = $this->getMock('OCP\IURLGenerator');
                $this->currentUser = $this->getMock('OCP\IUser');
 
@@ -71,7 +71,7 @@ class Share20OCSTest extends \Test\TestCase {
                                $this->groupManager,
                                $this->userManager,
                                $this->request,
-                               $this->userFolder,
+                               $this->rootFolder,
                                $this->urlGenerator,
                                $this->currentUser
                );
@@ -135,7 +135,7 @@ class Share20OCSTest extends \Test\TestCase {
                $this->assertEquals($expected, $this->ocs->getShare(42));
        }
 
-       public function createShare($id, $shareType, $sharedWith, $sharedBy, $path, $permissions,
+       public function createShare($id, $shareType, $sharedWith, $sharedBy, $shareOwner, $path, $permissions,
                                                                $shareTime, $expiration, $parent, $target, $mail_send, $token=null,
                                                                $password=null) {
                $share = $this->getMock('OC\Share20\IShare');
@@ -143,6 +143,7 @@ class Share20OCSTest extends \Test\TestCase {
                $share->method('getShareType')->willReturn($shareType);
                $share->method('getSharedWith')->willReturn($sharedWith);
                $share->method('getSharedBy')->willReturn($sharedBy);
+               $share->method('getShareOwner')->willReturn($shareOwner);
                $share->method('getPath')->willReturn($path);
                $share->method('getPermissions')->willReturn($permissions);
                $share->method('getShareTime')->willReturn($shareTime);
@@ -189,17 +190,20 @@ class Share20OCSTest extends \Test\TestCase {
                $folder->method('getParent')->willReturn($parentFolder);
 
                // File shared with user
-               $share = $this->createShare(100, 
-                                                                       \OCP\Share::SHARE_TYPE_USER,
-                                                                       $user,
-                                                                       $owner,
-                                                                       $file,
-                                                                       4,
-                                                                       5,
-                                                                       null,
-                                                                       6,
-                                                                       'target',
-                                                                       0);
+               $share = $this->createShare(
+                       100,
+                       \OCP\Share::SHARE_TYPE_USER,
+                       $user,
+                       $owner,
+                       $owner,
+                       $file,
+                       4,
+                       5,
+                       null,
+                       6,
+                       'target',
+                       0
+               );
                $expected = [
                        'id' => 100,
                        'share_type' => \OCP\Share::SHARE_TYPE_USER,
@@ -225,17 +229,20 @@ class Share20OCSTest extends \Test\TestCase {
                $data[] = [$share, $expected];
 
                // Folder shared with group
-               $share = $this->createShare(101, 
-                                                                       \OCP\Share::SHARE_TYPE_GROUP,
-                                                                       $group,
-                                                                       $owner,
-                                                                       $folder,
-                                                                       4,
-                                                                       5,
-                                                                       null,
-                                                                       6,
-                                                                       'target',
-                                                                       0);
+               $share = $this->createShare(
+                       101,
+                       \OCP\Share::SHARE_TYPE_GROUP,
+                       $group,
+                       $owner,
+                       $owner,
+                       $folder,
+                       4,
+                       5,
+                       null,
+                       6,
+                       'target',
+                       0
+               );
                $expected = [
                        'id' => 101,
                        'share_type' => \OCP\Share::SHARE_TYPE_GROUP,
@@ -262,19 +269,22 @@ class Share20OCSTest extends \Test\TestCase {
 
                // File shared by link with Expire
                $expire = \DateTime::createFromFormat('Y-m-d h:i:s', '2000-01-02 01:02:03');
-               $share = $this->createShare(101, 
-                                                                       \OCP\Share::SHARE_TYPE_LINK,
-                                                                       null,
-                                                                       $owner,
-                                                                       $folder,
-                                                                       4,
-                                                                       5,
-                                                                       $expire,
-                                                                       6,
-                                                                       'target',
-                                                                       0,
-                                                                       'token',
-                                                                       'password');
+               $share = $this->createShare(
+                       101,
+                       \OCP\Share::SHARE_TYPE_LINK,
+                       null,
+                       $owner,
+                       $owner,
+                       $folder,
+                       4,
+                       5,
+                       $expire,
+                       6,
+                       'target',
+                       0,
+                       'token',
+                       'password'
+               );
                $expected = [
                        'id' => 101,
                        'share_type' => \OCP\Share::SHARE_TYPE_LINK,
@@ -313,7 +323,7 @@ class Share20OCSTest extends \Test\TestCase {
                                        $this->groupManager,
                                        $this->userManager,
                                        $this->request,
-                                       $this->userFolder,
+                                       $this->rootFolder,
                                        $this->urlGenerator,
                                        $this->currentUser
                                ])->setMethods(['canAccessShare'])
@@ -327,10 +337,15 @@ class Share20OCSTest extends \Test\TestCase {
                        ->with($share->getId())
                        ->willReturn($share);
 
-               $this->userFolder
+               $userFolder = $this->getMock('OCP\Files\Folder');
+               $userFolder
                        ->method('getRelativePath')
                        ->will($this->returnArgument(0));
 
+               $this->rootFolder->method('getUserFolder')
+                       ->with($share->getShareOwner()->getUID())
+                       ->willReturn($userFolder);
+
                $this->urlGenerator
                        ->method('linkToRouteAbsolute')
                        ->willReturn('url');