]> source.dussan.org Git - nextcloud-server.git/commitdiff
Only check the sharing backends for file/folder items 2077/head
authorJoas Schilling <coding@schilljs.com>
Thu, 10 Nov 2016 13:16:35 +0000 (14:16 +0100)
committerJoas Schilling <coding@schilljs.com>
Thu, 10 Nov 2016 15:46:01 +0000 (16:46 +0100)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/files_sharing/lib/Controller/ShareesAPIController.php
apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php

index 5e01c9bfb09a414fd9d5aecca3d25450a0b54b4b..09912b7758a05be19b42850207437e62e3eb3c55 100644 (file)
@@ -427,12 +427,23 @@ class ShareesAPIController extends OCSController {
 
                $shareTypes = [
                        Share::SHARE_TYPE_USER,
-                       Share::SHARE_TYPE_REMOTE,
-                       Share::SHARE_TYPE_EMAIL
                ];
 
-               if ($this->shareManager->allowGroupSharing()) {
+               if ($itemType === 'file' || $itemType === 'folder') {
+                       if ($this->shareManager->allowGroupSharing()) {
+                               $shareTypes[] = Share::SHARE_TYPE_GROUP;
+                       }
+
+                       if ($this->isRemoteSharingAllowed($itemType)) {
+                               $shareTypes[] = Share::SHARE_TYPE_REMOTE;
+                       }
+
+                       if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
+                               $shareTypes[] = Share::SHARE_TYPE_EMAIL;
+                       }
+               } else {
                        $shareTypes[] = Share::SHARE_TYPE_GROUP;
+                       $shareTypes[] = Share::SHARE_TYPE_EMAIL;
                }
 
                if (isset($_GET['shareType']) && is_array($_GET['shareType'])) {
@@ -443,16 +454,6 @@ class ShareesAPIController extends OCSController {
                        sort($shareTypes);
                }
 
-               if (in_array(Share::SHARE_TYPE_REMOTE, $shareTypes) && !$this->isRemoteSharingAllowed($itemType)) {
-                       // Remove remote shares from type array, because it is not allowed.
-                       $shareTypes = array_diff($shareTypes, [Share::SHARE_TYPE_REMOTE]);
-               }
-
-               if (!$this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
-                       // Remove mail shares from type array, because the share provider is not loaded
-                       $shareTypes = array_diff($shareTypes, [Share::SHARE_TYPE_EMAIL]);
-               }
-
                $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
                $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
                $this->limit = (int) $perPage;
index e8ee55d184546f8c62a0def67be7505f0001c6b8..336dcb70f0e088c4b8eec99b789e06909a82a3a1 100644 (file)
@@ -1221,93 +1221,121 @@ class ShareesAPIControllerTest extends TestCase {
        }
 
        public function dataSearch() {
+               $noRemote = [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_GROUP, Share::SHARE_TYPE_EMAIL];
                $allTypes = [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_GROUP, Share::SHARE_TYPE_REMOTE, Share::SHARE_TYPE_EMAIL];
 
                return [
-                       [[], '', 'yes', true, true, $allTypes, false, true, true],
+                       [[], '', 'yes', true, true, $noRemote, false, true, true],
 
                        // Test itemType
                        [[
                                'search' => '',
-                       ], '', 'yes', true, true, $allTypes, false, true, true],
+                       ], '', 'yes', true, true, $noRemote, false, true, true],
                        [[
                                'search' => 'foobar',
-                       ], '', 'yes', true, true, $allTypes, false, true, true],
+                       ], '', 'yes', true, true, $noRemote, false, true, true],
                        [[
                                'search' => 0,
-                       ], '', 'yes', true, true, $allTypes, false, true, true],
+                       ], '', 'yes', true, true, $noRemote, false, true, true],
 
                        // Test itemType
                        [[
                                'itemType' => '',
-                       ], '', 'yes', true, true, $allTypes, false, true, true],
+                       ], '', 'yes', true, true, $noRemote, false, true, true],
                        [[
                                'itemType' => 'folder',
                        ], '', 'yes', true, true, $allTypes, false, true, true],
                        [[
                                'itemType' => 0,
-                       ], '', 'yes', true, true, $allTypes, false, true, true],
+                       ], '', 'yes', true, true, $noRemote, false, true, true],
 
                        // Test shareType
                        [[
+                               'itemType' => 'call',
+                       ], '', 'yes', true, true, $noRemote, false, true, true],
+                       [[
+                               'itemType' => 'folder',
                        ], '', 'yes', true, true, $allTypes, false, true, true],
                        [[
+                               'itemType' => 'folder',
                                'shareType' => 0,
                        ], '', 'yes', true, false, [0], false, true, true],
                        [[
+                               'itemType' => 'folder',
                                'shareType' => '0',
                        ], '', 'yes', true, false, [0], false, true, true],
                        [[
+                               'itemType' => 'folder',
                                'shareType' => 1,
                        ], '', 'yes', true, false, [1], false, true, true],
                        [[
+                               'itemType' => 'folder',
                                'shareType' => 12,
                        ], '', 'yes', true, false, [], false, true, true],
                        [[
+                               'itemType' => 'folder',
                                'shareType' => 'foobar',
                        ], '', 'yes', true, true, $allTypes, false, true, true],
                        [[
+                               'itemType' => 'folder',
                                'shareType' => [0, 1, 2],
                        ], '', 'yes', false, false, [0, 1], false, true, true],
                        [[
+                               'itemType' => 'folder',
                                'shareType' => [0, 1],
                        ], '', 'yes', false, false, [0, 1], false, true, true],
                        [[
+                               'itemType' => 'folder',
                                'shareType' => $allTypes,
                        ], '', 'yes', true, true, $allTypes, false, true, true],
                        [[
+                               'itemType' => 'folder',
                                'shareType' => $allTypes,
                        ], '', 'yes', false, false, [0, 1], false, true, true],
                        [[
+                               'itemType' => 'folder',
                                'shareType' => $allTypes,
                        ], '', 'yes', true, false, [0, 6], false, true, false],
                        [[
+                               'itemType' => 'folder',
                                'shareType' => $allTypes,
                        ], '', 'yes', false, true, [0, 4], false, true, false],
 
                        // Test pagination
                        [[
+                               'itemType' => 'folder',
                                'page' => 1,
                        ], '', 'yes', true, true, $allTypes, false, true, true],
                        [[
+                               'itemType' => 'folder',
                                'page' => 10,
                        ], '', 'yes', true, true, $allTypes, false, true, true],
 
                        // Test perPage
                        [[
+                               'itemType' => 'folder',
                                'perPage' => 1,
                        ], '', 'yes', true, true, $allTypes, false, true, true],
                        [[
+                               'itemType' => 'folder',
                                'perPage' => 10,
                        ], '', 'yes', true, true, $allTypes, false, true, true],
 
                        // Test $shareWithGroupOnly setting
-                       [[], 'no', 'yes',  true, true, $allTypes, false, true, true],
-                       [[], 'yes', 'yes', true, true, $allTypes, true, true, true],
+                       [[
+                               'itemType' => 'folder',
+                       ], 'no', 'yes',  true, true, $allTypes, false, true, true],
+                       [[
+                               'itemType' => 'folder',
+                       ], 'yes', 'yes', true, true, $allTypes, true, true, true],
 
                        // Test $shareeEnumeration setting
-                       [[], 'no', 'yes',  true, true, $allTypes, false, true, true],
-                       [[], 'no', 'no', true, true, $allTypes, false, false, true],
+                       [[
+                               'itemType' => 'folder',
+                       ], 'no', 'yes',  true, true, $allTypes, false, true, true],
+                       [[
+                               'itemType' => 'folder',
+                       ], 'no', 'no', true, true, $allTypes, false, false, true],
                ];
        }
 
@@ -1318,6 +1346,7 @@ class ShareesAPIControllerTest extends TestCase {
         * @param string $apiSetting
         * @param string $enumSetting
         * @param bool $remoteSharingEnabled
+        * @param bool $emailSharingEnabled
         * @param array $shareTypes
         * @param bool $shareWithGroupOnly
         * @param bool $shareeEnumeration
@@ -1341,7 +1370,7 @@ class ShareesAPIControllerTest extends TestCase {
                                ['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', $enumSetting],
                        ]);
 
-               $this->shareManager->expects($this->once())
+               $this->shareManager->expects($itemType === 'file' || $itemType === 'folder' ? $this->once() : $this->never())
                        ->method('allowGroupSharing')
                        ->willReturn($allowGroupSharing);