From eb06ac2224c0dffaa1aa443fe90c9e085520e159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Thu, 8 Oct 2020 15:07:21 +0200 Subject: [PATCH 1/7] Allow getting the share list filtered by share type via API --- apps/files_sharing/js/sharedfilelist.js | 7 ++ .../lib/Controller/Share20OcsController.php | 54 ++++++++++++--- .../Controller/Share20OcsControllerTest.php | 69 ++++++++++++++++--- .../tests/js/sharedfilelistSpec.js | 10 +-- changelog/unreleased/38000 | 11 +++ 5 files changed, 128 insertions(+), 23 deletions(-) create mode 100644 changelog/unreleased/38000 diff --git a/apps/files_sharing/js/sharedfilelist.js b/apps/files_sharing/js/sharedfilelist.js index a7faa64644ed..a389a50a8bc4 100644 --- a/apps/files_sharing/js/sharedfilelist.js +++ b/apps/files_sharing/js/sharedfilelist.js @@ -229,6 +229,13 @@ if (this._sharedWithUser) { requestData.shared_with_me = true; requestData.state = 'all'; + requestData.share_types = [ + OC.Share.SHARE_TYPE_USER, + OC.Share.SHARE_TYPE_GROUP, + OC.Share.SHARE_TYPE_REMOTE + ].join(','); + } else if (this._linksOnly) { + requestData.share_types = [OC.Share.SHARE_TYPE_LINK].join(','); } requestData.include_tags = true; var shares = $.ajax({ diff --git a/apps/files_sharing/lib/Controller/Share20OcsController.php b/apps/files_sharing/lib/Controller/Share20OcsController.php index d8c96a9a06d5..a13f64e564a7 100644 --- a/apps/files_sharing/lib/Controller/Share20OcsController.php +++ b/apps/files_sharing/lib/Controller/Share20OcsController.php @@ -631,6 +631,10 @@ private function getSharesInDir($folder) { /** * The getShares function. + * For the share type filter, if it isn't provided or is an empty string, + * all the share types will be returned, otherwise just the requested ones. + * Invalid share types will be ignored. If only invalid share types are requested, + * the function will return an empty list. * * @NoCSRFRequired * @NoAdminRequired @@ -640,6 +644,7 @@ private function getSharesInDir($folder) { * - Get shares with the current user (?shared_with_me=true) * - Get shares for a specific path (?path=...) * - Get all shares in a folder (?subfiles=true&path=..) + * - Filter by share type (?share_types=0,1,3,6) * * @return Result * @throws LockedException @@ -655,6 +660,31 @@ public function getShares() { $path = $this->request->getParam('path', null); $includeTags = $this->request->getParam('include_tags', false); + $shareTypes = $this->request->getParam('share_types', ''); + if ($shareTypes === '') { + $shareTypes = [ + Share::SHARE_TYPE_USER, + Share::SHARE_TYPE_GROUP, + Share::SHARE_TYPE_LINK, + Share::SHARE_TYPE_REMOTE, + ]; + } else { + $shareTypes = \explode(',', $shareTypes); + } + + $requestedShareTypes = [ + Share::SHARE_TYPE_USER => false, + Share::SHARE_TYPE_GROUP => false, + Share::SHARE_TYPE_LINK => false, + Share::SHARE_TYPE_REMOTE => false, + ]; + foreach ($shareTypes as $shareType) { + if (isset($requestedShareTypes[$shareType])) { + $requestedShareTypes[$shareType] = true; + } + } + // requestedShareTypes now contains as keys the share type that has been requested + // (with "true" value), without duplicate elements, and only valid share types if ($path !== null) { $userFolder = $this->rootFolder->getUserFolder($this->userSession->getUser()->getUID()); @@ -698,15 +728,23 @@ public function getShares() { $reshares = false; } - // Get all shares - $userShares = $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); - $groupShares = $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); - $linkShares = $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); - $shares = \array_merge($userShares, $groupShares, $linkShares); + $shares = []; + foreach ($requestedShareTypes as $shareType => $requested) { + if (!$requested) { + continue; + } - if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { - $federatedShares = $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0); - $shares = \array_merge($shares, $federatedShares); + if ($shareType !== Share::SHARE_TYPE_REMOTE) { + $shares = \array_merge( + $shares, + $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), $shareType, $path, $reshares, -1, 0) + ); + } elseif ($shareType === Share::SHARE_TYPE_REMOTE && $this->shareManager->outgoingServer2ServerSharesAllowed()) { + $shares = \array_merge( + $shares, + $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), $shareType, $path, $reshares, -1, 0) + ); + } } $formatted = []; diff --git a/apps/files_sharing/tests/Controller/Share20OcsControllerTest.php b/apps/files_sharing/tests/Controller/Share20OcsControllerTest.php index 7616ef40ec07..c5f90eb1bf47 100644 --- a/apps/files_sharing/tests/Controller/Share20OcsControllerTest.php +++ b/apps/files_sharing/tests/Controller/Share20OcsControllerTest.php @@ -2850,19 +2850,50 @@ public function providesGetSharesAll() { [ null, false, + false, + [], ], [ '/requested/path', true, + false, + [], + ], + [ + '/requested/path', + false, + false, + [], ], [ '/requested/path', + true, + true, + [], + ], + [ + null, false, + false, + [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_REMOTE], ], [ '/requested/path', true, - true + false, + [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_REMOTE], + ], + [ + '/requested/path', + false, + false, + [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_REMOTE], + ], + [ + '/requested/path', + true, + true, + [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_REMOTE], ], ]; } @@ -2870,7 +2901,7 @@ public function providesGetSharesAll() { /** * @dataProvider providesGetSharesAll */ - public function testGetSharesAll($requestedPath, $requestedReshares, $fedAllowed = false) { + public function testGetSharesAll($requestedPath, $requestedReshares, $fedAllowed, $shareTypes) { $userShare = $this->newShare(); $groupShare = $this->newShare(); $linkShare = $this->newShare(); @@ -2910,6 +2941,7 @@ public function testGetSharesAll($requestedPath, $requestedReshares, $fedAllowed ->will($this->returnValueMap([ ['path', null, $requestedPath], ['reshares', null, $requestedReshares ? 'true' : 'false'], + ['share_types', '', \implode(',', $shareTypes)], ])); $this->shareManager->method('outgoingServer2ServerSharesAllowed')->willReturn($fedAllowed); @@ -2918,16 +2950,33 @@ public function testGetSharesAll($requestedPath, $requestedReshares, $fedAllowed $ocs->expects($this->any())->method('formatShare')->will($this->returnArgument(0)); $result = $ocs->getShares(); - if ($fedAllowed) { - $this->assertCount(4, $result->getData()); - $this->assertContains($federatedShare, $result->getData(), 'result contains federated share'); - } else { - $this->assertCount(3, $result->getData()); + if (\count($shareTypes) === 0) { + $shareTypes = [ + \OCP\Share::SHARE_TYPE_USER, + \OCP\Share::SHARE_TYPE_GROUP, + \OCP\Share::SHARE_TYPE_LINK, + \OCP\Share::SHARE_TYPE_REMOTE, + ]; } - $this->assertContains($userShare, $result->getData(), 'result contains user share'); - $this->assertContains($groupShare, $result->getData(), 'result contains group share'); - $this->assertContains($linkShare, $result->getData(), 'result contains link share'); + foreach ($shareTypes as $shareType) { + switch ($shareType) { + case \OCP\Share::SHARE_TYPE_USER: + $this->assertContains($userShare, $result->getData(), 'result contains user share'); + break; + case \OCP\Share::SHARE_TYPE_GROUP: + $this->assertContains($groupShare, $result->getData(), 'result contains group share'); + break; + case \OCP\Share::SHARE_TYPE_LINK: + $this->assertContains($linkShare, $result->getData(), 'result contains link share'); + break; + case \OCP\Share::SHARE_TYPE_REMOTE: + if ($fedAllowed) { + $this->assertContains($federatedShare, $result->getData(), 'result contains federated share'); + } + break; + } + } } public function providesGetSharesSharedWithMe() { diff --git a/apps/files_sharing/tests/js/sharedfilelistSpec.js b/apps/files_sharing/tests/js/sharedfilelistSpec.js index c2546b7c8551..babb6c90c07f 100644 --- a/apps/files_sharing/tests/js/sharedfilelistSpec.js +++ b/apps/files_sharing/tests/js/sharedfilelistSpec.js @@ -140,7 +140,7 @@ describe('OCA.Sharing.FileList tests', function() { expect(fakeServer.requests.length).toEqual(2); expect(fakeServer.requests[0].url).toEqual( OC.linkToOCS('apps/files_sharing/api/v1') + - 'shares?format=json&shared_with_me=true&state=all&include_tags=true' + 'shares?format=json&shared_with_me=true&state=all&share_types=0%2C1%2C6&include_tags=true' ); expect(fakeServer.requests[1].url).toEqual( @@ -222,7 +222,7 @@ describe('OCA.Sharing.FileList tests', function() { expect(fakeServer.requests.length).toEqual(2); expect(fakeServer.requests[0].url).toEqual( OC.linkToOCS('apps/files_sharing/api/v1') + - 'shares?format=json&shared_with_me=true&state=all&include_tags=true' + 'shares?format=json&shared_with_me=true&state=all&share_types=0%2C1%2C6&include_tags=true' ); expect(fakeServer.requests[1].url).toEqual( OC.linkToOCS('apps/files_sharing/api/v1') + @@ -308,7 +308,7 @@ describe('OCA.Sharing.FileList tests', function() { expect(fakeServer.requests.length).toEqual(2); expect(fakeServer.requests[0].url).toEqual( OC.linkToOCS('apps/files_sharing/api/v1') + - 'shares?format=json&shared_with_me=true&state=all&include_tags=true' + 'shares?format=json&shared_with_me=true&state=all&share_types=0%2C1%2C6&include_tags=true' ); expect(fakeServer.requests[1].url).toEqual( OC.linkToOCS('apps/files_sharing/api/v1') + @@ -679,7 +679,7 @@ describe('OCA.Sharing.FileList tests', function() { request = fakeServer.requests[0]; expect(request.url).toEqual( OC.linkToOCS('apps/files_sharing/api/v1') + - 'shares?format=json&include_tags=true' + 'shares?format=json&share_types=3&include_tags=true' ); fakeServer.requests[0].respond( @@ -732,7 +732,7 @@ describe('OCA.Sharing.FileList tests', function() { request = fakeServer.requests[0]; expect(request.url).toEqual( OC.linkToOCS('apps/files_sharing/api/v1') + - 'shares?format=json&include_tags=true' + 'shares?format=json&share_types=3&include_tags=true' ); fakeServer.requests[0].respond( diff --git a/changelog/unreleased/38000 b/changelog/unreleased/38000 new file mode 100644 index 000000000000..42655d5dd827 --- /dev/null +++ b/changelog/unreleased/38000 @@ -0,0 +1,11 @@ +Enhancement: Allow getting the share list filtered by share type via API + +Previously, the share API returned all the shares. There were some filters, +but you weren't able to filter by share type. You couldn't get only your +link shares. + +Now the API allows filtering by share type, along with the filters previously +available. The web UI is using this filtering now. + +https://github.com/owncloud/core/pull/38000 + From 9922785d06f9e202e152aee6a3d2b5c8a7a0c46f Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Tue, 20 Oct 2020 12:31:30 +0545 Subject: [PATCH 2/7] Acceptance tests for gettingSharesSharedFiltered --- .../gettingSharesSharedFiltered.feature | 93 +++++++++++++++++++ .../acceptance/features/bootstrap/Sharing.php | 29 ++++++ 2 files changed, 122 insertions(+) create mode 100644 tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFiltered.feature diff --git a/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFiltered.feature b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFiltered.feature new file mode 100644 index 000000000000..7fae060c0c00 --- /dev/null +++ b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFiltered.feature @@ -0,0 +1,93 @@ +@api @files_sharing-app-required @notToImplementOnOCIS +Feature: sharing + As a user + I want to be able to know the shares that I have made of a particular type (user, group etc) + So that I can reduce the amount of data that has to be transferred to be just the data that I need + + Background: + Given these users have been created with default attributes and without skeleton files: + | username | + | Alice | + | Brian | + And group "grp1" has been created + And user "Brian" has been added to group "grp1" + And user "Alice" has created folder "/folderToShareWithUser" + And user "Alice" has created folder "/folderToShareWithGroup" + And user "Alice" has created folder "/folderToShareWithPublic" + And user "Alice" has uploaded file with content "file to share with user" to "/fileToShareWithUser.txt" + And user "Alice" has uploaded file with content "file to share with group" to "/fileToShareWithGroup.txt" + And user "Alice" has uploaded file with content "file to share with public" to "/fileToShareWithPublic.txt" + And user "Alice" has shared folder "/folderToShareWithUser" with user "Brian" + And user "Alice" has shared folder "/folderToShareWithGroup" with group "grp1" + And user "Alice" has created a public link share with settings + | path | /folderToShareWithPublic | + | permissions | read | + And user "Alice" has shared file "/fileToShareWithUser.txt" with user "Brian" + And user "Alice" has shared file "/fileToShareWithGroup.txt" with group "grp1" + And user "Alice" has created a public link share with settings + | path | /fileToShareWithPublic.txt | + | permissions | read | + + Scenario Outline: getting shares shared to users + Given using OCS API version "" + When user "Alice" gets the user shares shared by him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And folder "folderToShareWithUser" should be included in the response + And file "fileToShareWithUser.txt" should be included in the response + But folder "folderToShareWithGroup" should not be included in the response + And folder "fileToShareWithGroup.txt" should not be included in the response + And folder "folderToShareWithPublic" should not be included in the response + And folder "fileToShareWithPublic.txt" should not be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting shares shared to groups + Given using OCS API version "" + When user "Alice" gets the group shares shared by him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And folder "folderToShareWithGroup" should be included in the response + And folder "fileToShareWithGroup.txt" should be included in the response + But folder "folderToShareWithUser" should not be included in the response + And file "fileToShareWithUser.txt" should not be included in the response + And folder "folderToShareWithPublic" should not be included in the response + And folder "fileToShareWithPublic.txt" should not be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting shares shared to public links + Given using OCS API version "" + When user "Alice" gets the public link shares shared by him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And folder "folderToShareWithPublic" should be included in the response + And folder "fileToShareWithPublic.txt" should be included in the response + But folder "folderToShareWithUser" should not be included in the response + And file "fileToShareWithUser.txt" should not be included in the response + And folder "folderToShareWithGroup" should not be included in the response + And folder "fileToShareWithGroup.txt" should not be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting shares shared to users and groups + Given using OCS API version "" + When user "Alice" gets the user and group shares shared by him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And folder "folderToShareWithUser" should be included in the response + And file "fileToShareWithUser.txt" should be included in the response + And folder "folderToShareWithGroup" should be included in the response + And folder "fileToShareWithGroup.txt" should be included in the response + But folder "folderToShareWithPublic" should not be included in the response + And folder "fileToShareWithPublic.txt" should not be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index 57efa05a89a6..308787b14aed 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -1758,6 +1758,35 @@ public function theAdministratorGetsAllSharesSharedByHimUsingTheSharingApi() { $this->userGetsAllSharesSharedByHimUsingTheSharingApi($this->getAdminUsername()); } + /** + * @When /^user "([^"]*)" gets the (user|group|user and group|public link) shares shared by him using the sharing API$/ + * + * @param string $user + * @param string $shareType + * + * @return void + */ + public function userGetsFilteredSharesSharedByHimUsingTheSharingApi($user, $shareType) { + $user = $this->getActualUsername($user); + if ($shareType === 'public link') { + $shareType = 'public_link'; + } + if ($shareType === 'user and group') { + $rawShareTypes = SharingHelper::SHARE_TYPES['user'] . "," . SharingHelper::SHARE_TYPES['group']; + } else { + $rawShareTypes = SharingHelper::SHARE_TYPES[$shareType]; + } + $this->response = OcsApiHelper::sendRequest( + $this->getBaseUrl(), + $user, + $this->getPasswordForUser($user), + "GET", + $this->getSharesEndpointPath("?share_types=" . $rawShareTypes), + [], + $this->ocsApiVersion + ); + } + /** * @When user :user gets all the shares from the file :path using the sharing API * From 24b7201c1809771832ae4036c4807fb7bdd24482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Tue, 20 Oct 2020 11:34:25 +0200 Subject: [PATCH 3/7] Add filtering along with the share_with_me and subfiles options --- .../lib/Controller/Share20OcsController.php | 55 ++++++--- .../Controller/Share20OcsControllerTest.php | 104 ++++++++++++++++-- 2 files changed, 135 insertions(+), 24 deletions(-) diff --git a/apps/files_sharing/lib/Controller/Share20OcsController.php b/apps/files_sharing/lib/Controller/Share20OcsController.php index a13f64e564a7..281b587180bf 100644 --- a/apps/files_sharing/lib/Controller/Share20OcsController.php +++ b/apps/files_sharing/lib/Controller/Share20OcsController.php @@ -553,13 +553,27 @@ public function createShare() { * @param File|Folder $node * @param boolean $includeTags include tags in response * @param int|null $stateFilter state filter or empty for all, defaults to 0 (accepted) + * @param array $requestedShareTypes a key-value array with the requested share types to + * be returned. The keys of the array are the share types to be returned, and the values + * whether the share type will be returned or not. + * [Share::SHARE_TYPE_USER => true, Share::SHARE_TYPE_GROUP => false] * @return Result */ - private function getSharedWithMe($node = null, $includeTags, $stateFilter = 0) { - $userShares = $this->shareManager->getSharedWith($this->userSession->getUser()->getUID(), Share::SHARE_TYPE_USER, $node, -1, 0); - $groupShares = $this->shareManager->getSharedWith($this->userSession->getUser()->getUID(), Share::SHARE_TYPE_GROUP, $node, -1, 0); - - $shares = \array_merge($userShares, $groupShares); + private function getSharedWithMe($node = null, $includeTags, $requestedShareTypes, $stateFilter = 0) { + // sharedWithMe is limited to user and group shares for compatibility. + $shares = []; + if (isset($requestedShareTypes[Share::SHARE_TYPE_USER]) && $requestedShareTypes[Share::SHARE_TYPE_USER]) { + $shares = \array_merge( + $shares, + $this->shareManager->getSharedWith($this->userSession->getUser()->getUID(), Share::SHARE_TYPE_USER, $node, -1, 0) + ); + } + if (isset($requestedShareTypes[Share::SHARE_TYPE_GROUP]) && $requestedShareTypes[Share::SHARE_TYPE_GROUP]) { + $shares = \array_merge( + $shares, + $this->shareManager->getSharedWith($this->userSession->getUser()->getUID(), Share::SHARE_TYPE_GROUP, $node, -1, 0) + ); + } $shares = \array_filter($shares, function (IShare $share) { return $share->getShareOwner() !== $this->userSession->getUser()->getUID(); @@ -597,10 +611,14 @@ private function getSharedWithMe($node = null, $includeTags, $stateFilter = 0) { /** * @param Folder $folder + * @param array $requestedShareTypes a key-value array with the requested share types to + * be returned. The keys of the array are the share types to be returned, and the values + * whether the share type will be returned or not. + * [Share::SHARE_TYPE_USER => true, Share::SHARE_TYPE_GROUP => false] * @return Result * @throws NotFoundException */ - private function getSharesInDir($folder) { + private function getSharesInDir($folder, $requestedShareTypes) { if (!($folder instanceof Folder)) { return new Result(null, 400, $this->l->t('Not a directory')); } @@ -609,11 +627,22 @@ private function getSharesInDir($folder) { /** @var IShare[] $shares */ $shares = []; foreach ($nodes as $node) { - $shares = \array_merge($shares, $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), Share::SHARE_TYPE_USER, $node, false, -1, 0)); - $shares = \array_merge($shares, $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); - $shares = \array_merge($shares, $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), Share::SHARE_TYPE_LINK, $node, false, -1, 0)); - if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { - $shares = \array_merge($shares, $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), Share::SHARE_TYPE_REMOTE, $node, false, -1, 0)); + foreach ($requestedShareTypes as $shareType => $requested) { + if (!$requested) { + continue; + } + + if ($shareType !== Share::SHARE_TYPE_REMOTE) { + $shares = \array_merge( + $shares, + $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), $shareType, $node, false, -1, 0) + ); + } elseif ($shareType === Share::SHARE_TYPE_REMOTE && $this->shareManager->outgoingServer2ServerSharesAllowed()) { + $shares = \array_merge( + $shares, + $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), $shareType, $node, false, -1, 0) + ); + } } } @@ -707,7 +736,7 @@ public function getShares() { } else { $stateFilter = (int)$stateFilter; } - $result = $this->getSharedWithMe($path, $includeTags, $stateFilter); + $result = $this->getSharedWithMe($path, $includeTags, $requestedShareTypes, $stateFilter); if ($path !== null) { $path->unlock(ILockingProvider::LOCK_SHARED); } @@ -715,7 +744,7 @@ public function getShares() { } if ($subfiles === 'true') { - $result = $this->getSharesInDir($path); + $result = $this->getSharesInDir($path, $requestedShareTypes); if ($path !== null) { $path->unlock(ILockingProvider::LOCK_SHARED); } diff --git a/apps/files_sharing/tests/Controller/Share20OcsControllerTest.php b/apps/files_sharing/tests/Controller/Share20OcsControllerTest.php index c5f90eb1bf47..5afbb7969c94 100644 --- a/apps/files_sharing/tests/Controller/Share20OcsControllerTest.php +++ b/apps/files_sharing/tests/Controller/Share20OcsControllerTest.php @@ -2977,6 +2977,11 @@ public function testGetSharesAll($requestedPath, $requestedReshares, $fedAllowed break; } } + if ($fedAllowed && \in_array(\OCP\Share::SHARE_TYPE_REMOTE, $shareTypes, true)) { + $this->assertCount(\count($shareTypes), $result->getData()); + } else { + $this->assertCount(\count($shareTypes) - 1, $result->getData()); + } } public function providesGetSharesSharedWithMe() { @@ -2984,22 +2989,77 @@ public function providesGetSharesSharedWithMe() { [ null, 'all', + [], + ], + [ + '/requested/path', + 'all', + [], + ], + [ + '/requested/path', + \OCP\Share::STATE_PENDING, + [], + ], + [ + '/requested/path', + \OCP\Share::STATE_ACCEPTED, + [], + ], + [ + '/requested/path', + '', + [], + ], + [ + null, + 'all', + [\OCP\Share::SHARE_TYPE_USER], ], [ '/requested/path', 'all', + [\OCP\Share::SHARE_TYPE_USER], ], [ '/requested/path', \OCP\Share::STATE_PENDING, + [\OCP\Share::SHARE_TYPE_USER], ], [ '/requested/path', \OCP\Share::STATE_ACCEPTED, + [\OCP\Share::SHARE_TYPE_USER], ], [ '/requested/path', '', + [\OCP\Share::SHARE_TYPE_USER], + ], + [ + null, + 'all', + [\OCP\Share::SHARE_TYPE_GROUP], + ], + [ + '/requested/path', + 'all', + [\OCP\Share::SHARE_TYPE_GROUP], + ], + [ + '/requested/path', + \OCP\Share::STATE_PENDING, + [\OCP\Share::SHARE_TYPE_GROUP], + ], + [ + '/requested/path', + \OCP\Share::STATE_ACCEPTED, + [\OCP\Share::SHARE_TYPE_GROUP], + ], + [ + '/requested/path', + '', + [\OCP\Share::SHARE_TYPE_GROUP], ], ]; } @@ -3007,7 +3067,7 @@ public function providesGetSharesSharedWithMe() { /** * @dataProvider providesGetSharesSharedWithMe */ - public function testGetSharesSharedWithMe($requestedPath, $stateFilter) { + public function testGetSharesSharedWithMe($requestedPath, $stateFilter, $shareTypes) { $testStateFilter = $stateFilter; if ($testStateFilter === '' || $testStateFilter === 'all') { $testStateFilter = \OCP\Share::STATE_ACCEPTED; @@ -3081,22 +3141,43 @@ public function testGetSharesSharedWithMe($requestedPath, $stateFilter) { ['path', null, $requestedPath], ['state', \OCP\Share::STATE_ACCEPTED, $stateFilter], ['shared_with_me', null, 'true'], + ['share_types', '', \implode(',', $shareTypes)], ])); $ocs = $this->mockFormatShare(); $ocs->expects($this->any())->method('formatShare')->will($this->returnArgument(0)); $result = $ocs->getShares(); - $this->assertContains($userShare, $result->getData(), 'result contains user share'); - $this->assertContains($groupShare, $result->getData(), 'result contains group share'); - $this->assertNotContains($groupShareNonOwner, $result->getData(), 'result does not contain share from same owner'); - $this->assertNotContains($userShareNoAccess, $result->getData(), 'result does not contain inaccessible share'); - if ($stateFilter === 'all') { - $this->assertCount(3, $result->getData()); - $this->assertContains($userShareDifferentState, $result->getData(), 'result contains shares from all states'); - } else { - $this->assertCount(2, $result->getData()); - $this->assertNotContains($userShareDifferentState, $result->getData(), 'result contains only share from requested state'); + if (empty($shareTypes)) { + $shareTypes = [ + \OCP\Share::SHARE_TYPE_USER, + \OCP\Share::SHARE_TYPE_GROUP, + ]; + } + + if (\in_array(\OCP\Share::SHARE_TYPE_USER, $shareTypes, true)) { + $this->assertContains($userShare, $result->getData(), 'result contains user share'); + $this->assertNotContains($userShareNoAccess, $result->getData(), 'result does not contain inaccessible share'); + if ($stateFilter === 'all') { + if (\in_array(\OCP\Share::SHARE_TYPE_GROUP, $shareTypes, true)) { + $this->assertCount(3, $result->getData()); + } else { + $this->assertCount(2, $result->getData()); + } + $this->assertContains($userShareDifferentState, $result->getData(), 'result contains shares from all states'); + } else { + if (\in_array(\OCP\Share::SHARE_TYPE_GROUP, $shareTypes, true)) { + $this->assertCount(2, $result->getData()); + } else { + $this->assertCount(1, $result->getData()); + } + $this->assertNotContains($userShareDifferentState, $result->getData(), 'result contains only share from requested state'); + } + } + + if (\in_array(\OCP\Share::SHARE_TYPE_GROUP, $shareTypes, true)) { + $this->assertContains($groupShare, $result->getData(), 'result contains group share'); + $this->assertNotContains($groupShareNonOwner, $result->getData(), 'result does not contain share from same owner'); } } @@ -3158,6 +3239,7 @@ public function testGetSharesSharedWithMeAndBlockGroup() { ['path', null, $requestedPath], ['state', \OCP\Share::STATE_ACCEPTED, $stateFilter], ['shared_with_me', null, 'true'], + ['share_types', '', ''], ])); $ocs = $this->mockFormatShare(); From 285df9bdf508f48c461fce6dd269feaabef1ec09 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Tue, 20 Oct 2020 14:16:06 +0545 Subject: [PATCH 4/7] Add to and refactor filtered shares tests --- .../gettingSharesSharedFiltered.feature | 18 +--- .../gettingSharesSharedFilteredEmpty.feature | 72 +++++++++++++++ .../gettingSharesSharedFiltered.feature | 89 +++++++++++++++++++ .../gettingSharesSharedFilteredEmpty.feature | 80 +++++++++++++++++ .../acceptance/features/bootstrap/Sharing.php | 53 +++++++++++ 5 files changed, 298 insertions(+), 14 deletions(-) create mode 100644 tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFilteredEmpty.feature create mode 100644 tests/acceptance/features/apiShareOperationsToShares/gettingSharesSharedFiltered.feature create mode 100644 tests/acceptance/features/apiShareOperationsToShares/gettingSharesSharedFilteredEmpty.feature diff --git a/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFiltered.feature b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFiltered.feature index 7fae060c0c00..70496e0b4d45 100644 --- a/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFiltered.feature +++ b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFiltered.feature @@ -33,12 +33,9 @@ Feature: sharing When user "Alice" gets the user shares shared by him using the sharing API Then the OCS status code should be "" And the HTTP status code should be "200" + And exactly 2 files or folders should be included in the response And folder "folderToShareWithUser" should be included in the response And file "fileToShareWithUser.txt" should be included in the response - But folder "folderToShareWithGroup" should not be included in the response - And folder "fileToShareWithGroup.txt" should not be included in the response - And folder "folderToShareWithPublic" should not be included in the response - And folder "fileToShareWithPublic.txt" should not be included in the response Examples: | ocs_api_version | ocs_status_code | | 1 | 100 | @@ -49,12 +46,9 @@ Feature: sharing When user "Alice" gets the group shares shared by him using the sharing API Then the OCS status code should be "" And the HTTP status code should be "200" + And exactly 2 files or folders should be included in the response And folder "folderToShareWithGroup" should be included in the response And folder "fileToShareWithGroup.txt" should be included in the response - But folder "folderToShareWithUser" should not be included in the response - And file "fileToShareWithUser.txt" should not be included in the response - And folder "folderToShareWithPublic" should not be included in the response - And folder "fileToShareWithPublic.txt" should not be included in the response Examples: | ocs_api_version | ocs_status_code | | 1 | 100 | @@ -65,12 +59,9 @@ Feature: sharing When user "Alice" gets the public link shares shared by him using the sharing API Then the OCS status code should be "" And the HTTP status code should be "200" + And exactly 2 files or folders should be included in the response And folder "folderToShareWithPublic" should be included in the response And folder "fileToShareWithPublic.txt" should be included in the response - But folder "folderToShareWithUser" should not be included in the response - And file "fileToShareWithUser.txt" should not be included in the response - And folder "folderToShareWithGroup" should not be included in the response - And folder "fileToShareWithGroup.txt" should not be included in the response Examples: | ocs_api_version | ocs_status_code | | 1 | 100 | @@ -81,12 +72,11 @@ Feature: sharing When user "Alice" gets the user and group shares shared by him using the sharing API Then the OCS status code should be "" And the HTTP status code should be "200" + And exactly 4 files or folders should be included in the response And folder "folderToShareWithUser" should be included in the response And file "fileToShareWithUser.txt" should be included in the response And folder "folderToShareWithGroup" should be included in the response And folder "fileToShareWithGroup.txt" should be included in the response - But folder "folderToShareWithPublic" should not be included in the response - And folder "fileToShareWithPublic.txt" should not be included in the response Examples: | ocs_api_version | ocs_status_code | | 1 | 100 | diff --git a/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFilteredEmpty.feature b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFilteredEmpty.feature new file mode 100644 index 000000000000..2a970e01984b --- /dev/null +++ b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFilteredEmpty.feature @@ -0,0 +1,72 @@ +@api @files_sharing-app-required @notToImplementOnOCIS +Feature: sharing + As a user + I want to be able to know the shares that I have made of a particular type (user, group etc) + So that I can reduce the amount of data that has to be transferred to be just the data that I need + + Background: + Given these users have been created with default attributes and without skeleton files: + | username | + | Alice | + | Brian | + And group "grp1" has been created + And user "Brian" has been added to group "grp1" + And user "Alice" has created folder "/folderToShareWithUser" + And user "Alice" has created folder "/folderToShareWithGroup" + And user "Alice" has created folder "/folderToShareWithPublic" + And user "Alice" has uploaded file with content "file to share with user" to "/fileToShareWithUser.txt" + And user "Alice" has uploaded file with content "file to share with group" to "/fileToShareWithGroup.txt" + And user "Alice" has uploaded file with content "file to share with public" to "/fileToShareWithPublic.txt" + + Scenario Outline: getting shares shared to users when there are none + Given using OCS API version "" + And user "Alice" has shared folder "/folderToShareWithGroup" with group "grp1" + And user "Alice" has created a public link share with settings + | path | /folderToShareWithPublic | + | permissions | read | + And user "Alice" has shared file "/fileToShareWithGroup.txt" with group "grp1" + And user "Alice" has created a public link share with settings + | path | /fileToShareWithPublic.txt | + | permissions | read | + When user "Alice" gets the user shares shared by him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And no files or folders should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting shares shared to groups when there are none + Given using OCS API version "" + And user "Alice" has shared folder "/folderToShareWithUser" with user "Brian" + And user "Alice" has created a public link share with settings + | path | /folderToShareWithPublic | + | permissions | read | + And user "Alice" has shared file "/fileToShareWithUser.txt" with user "Brian" + And user "Alice" has created a public link share with settings + | path | /fileToShareWithPublic.txt | + | permissions | read | + When user "Alice" gets the group shares shared by him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And no files or folders should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting shares shared to public links when there are none + Given using OCS API version "" + And user "Alice" has shared folder "/folderToShareWithUser" with user "Brian" + And user "Alice" has shared folder "/folderToShareWithGroup" with group "grp1" + And user "Alice" has shared file "/fileToShareWithUser.txt" with user "Brian" + And user "Alice" has shared file "/fileToShareWithGroup.txt" with group "grp1" + When user "Alice" gets the public link shares shared by him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And no files or folders should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | diff --git a/tests/acceptance/features/apiShareOperationsToShares/gettingSharesSharedFiltered.feature b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesSharedFiltered.feature new file mode 100644 index 000000000000..8f72c2127f8d --- /dev/null +++ b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesSharedFiltered.feature @@ -0,0 +1,89 @@ +@api @files_sharing-app-required +Feature: sharing + As a user + I want to be able to know the shares that I have made of a particular type (user, group etc) + So that I can reduce the amount of data that has to be transferred to be just the data that I need + + Background: + Given the administrator has set the default folder for received shares to "Shares" + And auto-accept shares has been disabled + And these users have been created with default attributes and without skeleton files: + | username | + | Alice | + | Brian | + And group "grp1" has been created + And user "Brian" has been added to group "grp1" + And user "Alice" has created folder "/folderToShareWithUser" + And user "Alice" has created folder "/folderToShareWithGroup" + And user "Alice" has created folder "/folderToShareWithPublic" + And user "Alice" has uploaded file with content "file to share with user" to "/fileToShareWithUser.txt" + And user "Alice" has uploaded file with content "file to share with group" to "/fileToShareWithGroup.txt" + And user "Alice" has uploaded file with content "file to share with public" to "/fileToShareWithPublic.txt" + And user "Alice" has shared folder "/folderToShareWithUser" with user "Brian" + And user "Brian" has accepted share "/folderToShareWithUser" offered by user "Alice" + And user "Alice" has shared folder "/folderToShareWithGroup" with group "grp1" + And user "Brian" has accepted share "/folderToShareWithGroup" offered by user "Alice" + And user "Alice" has created a public link share with settings + | path | /folderToShareWithPublic | + | permissions | read | + And user "Alice" has shared file "/fileToShareWithUser.txt" with user "Brian" + And user "Brian" has accepted share "/fileToShareWithUser.txt" offered by user "Alice" + And user "Alice" has shared file "/fileToShareWithGroup.txt" with group "grp1" + And user "Brian" has accepted share "/fileToShareWithGroup.txt" offered by user "Alice" + And user "Alice" has created a public link share with settings + | path | /fileToShareWithPublic.txt | + | permissions | read | + + Scenario Outline: getting shares shared to users + Given using OCS API version "" + When user "Alice" gets the user shares shared by him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And exactly 2 files or folders should be included in the response + And folder "/Shares/folderToShareWithUser" should be included in the response + And file "/Shares/fileToShareWithUser.txt" should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting shares shared to groups + Given using OCS API version "" + When user "Alice" gets the group shares shared by him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And exactly 2 files or folders should be included in the response + And folder "/Shares/folderToShareWithGroup" should be included in the response + And folder "/Shares/fileToShareWithGroup.txt" should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting shares shared to public links + Given using OCS API version "" + When user "Alice" gets the public link shares shared by him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And exactly 2 files or folders should be included in the response + And folder "/Shares/folderToShareWithPublic" should be included in the response + And folder "/Shares/fileToShareWithPublic.txt" should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting shares shared to users and groups + Given using OCS API version "" + When user "Alice" gets the user and group shares shared by him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And exactly 4 files or folders should be included in the response + And folder "/Shares/folderToShareWithUser" should be included in the response + And file "/Shares/fileToShareWithUser.txt" should be included in the response + And folder "/Shares/folderToShareWithGroup" should be included in the response + And folder "/Shares/fileToShareWithGroup.txt" should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | diff --git a/tests/acceptance/features/apiShareOperationsToShares/gettingSharesSharedFilteredEmpty.feature b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesSharedFilteredEmpty.feature new file mode 100644 index 000000000000..47ec514a4eb4 --- /dev/null +++ b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesSharedFilteredEmpty.feature @@ -0,0 +1,80 @@ +@api @files_sharing-app-required +Feature: sharing + As a user + I want to be able to know the shares that I have made of a particular type (user, group etc) + So that I can reduce the amount of data that has to be transferred to be just the data that I need + + Background: + Given these users have been created with default attributes and without skeleton files: + | username | + | Alice | + | Brian | + And group "grp1" has been created + And user "Brian" has been added to group "grp1" + And user "Alice" has created folder "/folderToShareWithUser" + And user "Alice" has created folder "/folderToShareWithGroup" + And user "Alice" has created folder "/folderToShareWithPublic" + And user "Alice" has uploaded file with content "file to share with user" to "/fileToShareWithUser.txt" + And user "Alice" has uploaded file with content "file to share with group" to "/fileToShareWithGroup.txt" + And user "Alice" has uploaded file with content "file to share with public" to "/fileToShareWithPublic.txt" + + Scenario Outline: getting shares shared to users when there are none + Given using OCS API version "" + And user "Alice" has shared folder "/folderToShareWithGroup" with group "grp1" + And user "Brian" has accepted share "/folderToShareWithGroup" offered by user "Alice" + And user "Alice" has created a public link share with settings + | path | /folderToShareWithPublic | + | permissions | read | + And user "Alice" has shared file "/fileToShareWithGroup.txt" with group "grp1" + And user "Brian" has accepted share "/fileToShareWithGroup.txt" offered by user "Alice" + And user "Alice" has created a public link share with settings + | path | /fileToShareWithPublic.txt | + | permissions | read | + When user "Alice" gets the user shares shared by him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And no files or folders should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting shares shared to groups when there are none + Given using OCS API version "" + And user "Alice" has shared folder "/folderToShareWithUser" with user "Brian" + And user "Brian" has accepted share "/folderToShareWithUser" offered by user "Alice" + And user "Alice" has created a public link share with settings + | path | /folderToShareWithPublic | + | permissions | read | + And user "Alice" has shared file "/fileToShareWithUser.txt" with user "Brian" + And user "Brian" has accepted share "/fileToShareWithUser.txt" offered by user "Alice" + And user "Alice" has created a public link share with settings + | path | /fileToShareWithPublic.txt | + | permissions | read | + When user "Alice" gets the group shares shared by him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And no files or folders should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting shares shared to public links when there are none + Given using OCS API version "" + And user "Alice" has shared folder "/folderToShareWithUser" with user "Brian" + And user "Brian" has accepted share "/folderToShareWithUser" offered by user "Alice" + And user "Alice" has shared folder "/folderToShareWithGroup" with group "grp1" + And user "Brian" has accepted share "/folderToShareWithGroup" offered by user "Alice" + And user "Alice" has shared file "/fileToShareWithUser.txt" with user "Brian" + And user "Brian" has accepted share "/fileToShareWithUser.txt" offered by user "Alice" + And user "Alice" has shared file "/fileToShareWithGroup.txt" with group "grp1" + And user "Brian" has accepted share "/fileToShareWithGroup.txt" offered by user "Alice" + When user "Alice" gets the public link shares shared by him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And no files or folders should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index 308787b14aed..49412c38d4ae 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -1044,6 +1044,31 @@ public function isFieldInResponse($field, $contentExpected, $expectSuccess = tru return false; } + /** + * @Then no files or folders should be included in the response + * + * @return void + */ + public function checkNoFilesFoldersInResponse() { + $data = $this->getResponseXml(null, __METHOD__)->data[0]; + Assert::assertIsObject($data, __METHOD__ . " data not found in response XML"); + Assert::assertCount(0, $data); + } + + /** + * @Then exactly :count file/files or folder/folders should be included in the response + * + * @param string $count + * + * @return void + */ + public function checkCountFilesFoldersInResponse($count) { + $count = (int) $count; + $data = $this->getResponseXml(null, __METHOD__)->data[0]; + Assert::assertIsObject($data, __METHOD__ . " data not found in response XML"); + Assert::assertCount($count, $data); + } + /** * @Then /^(?:file|folder|entry) "([^"]*)" should be included in the response$/ * @@ -1709,6 +1734,34 @@ public function userGetsAllTheSharesSharedWithHimUsingTheSharingApi($user) { ); } + /** + * @When /^user "([^"]*)" gets the (user|group|user and group|public link) shares shared with him using the sharing API$/ + * + * @param string $user + * @param string $shareType + * + * @return void + */ + public function userGetsFilteredSharesSharedWithHimUsingTheSharingApi($user, $shareType) { + $user = $this->getActualUsername($user); + if ($shareType === 'public link') { + $shareType = 'public_link'; + } + if ($shareType === 'user and group') { + $rawShareTypes = SharingHelper::SHARE_TYPES['user'] . "," . SharingHelper::SHARE_TYPES['group']; + } else { + $rawShareTypes = SharingHelper::SHARE_TYPES[$shareType]; + } + $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( + $user, + 'GET', + $this->getSharesEndpointPath( + "?shared_with_me=true&share_types=" . $rawShareTypes + ), + null + ); + } + /** * @When /^user "([^"]*)" gets all the shares shared with him that are received as (?:file|folder|entry) "([^"]*)" using the provisioning API$/ * From 9d6ae5a630836eed9e4105dd5fd03a84a2c248d0 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Tue, 20 Oct 2020 17:10:47 +0545 Subject: [PATCH 5/7] API acceptance tests for filtered list of shares shared-with-me --- .../gettingSharesReceivedFiltered.feature | 55 +++++++++++ ...gettingSharesReceivedFilteredEmpty.feature | 81 +++++++++++++++++ .../gettingSharesReceivedFiltered.feature | 61 +++++++++++++ ...gettingSharesReceivedFilteredEmpty.feature | 91 +++++++++++++++++++ 4 files changed, 288 insertions(+) create mode 100644 tests/acceptance/features/apiShareOperationsToRoot/gettingSharesReceivedFiltered.feature create mode 100644 tests/acceptance/features/apiShareOperationsToRoot/gettingSharesReceivedFilteredEmpty.feature create mode 100644 tests/acceptance/features/apiShareOperationsToShares/gettingSharesReceivedFiltered.feature create mode 100644 tests/acceptance/features/apiShareOperationsToShares/gettingSharesReceivedFilteredEmpty.feature diff --git a/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesReceivedFiltered.feature b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesReceivedFiltered.feature new file mode 100644 index 000000000000..930a0ee95473 --- /dev/null +++ b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesReceivedFiltered.feature @@ -0,0 +1,55 @@ +@api @files_sharing-app-required @notToImplementOnOCIS +Feature: sharing + As a user + I want to be able to know the shares that I have received of a particular type (user, group etc) + So that I can reduce the amount of data that has to be transferred to be just the data that I need + + Background: + Given these users have been created with default attributes and without skeleton files: + | username | + | Alice | + | Brian | + And group "grp1" has been created + And user "Brian" has been added to group "grp1" + And user "Alice" has created folder "/folderToShareWithUser" + And user "Alice" has created folder "/folderToShareWithGroup" + And user "Alice" has created folder "/folderToShareWithPublic" + And user "Alice" has uploaded file with content "file to share with user" to "/fileToShareWithUser.txt" + And user "Alice" has uploaded file with content "file to share with group" to "/fileToShareWithGroup.txt" + And user "Alice" has uploaded file with content "file to share with public" to "/fileToShareWithPublic.txt" + And user "Alice" has shared folder "/folderToShareWithUser" with user "Brian" + And user "Alice" has shared folder "/folderToShareWithGroup" with group "grp1" + And user "Alice" has created a public link share with settings + | path | /folderToShareWithPublic | + | permissions | read | + And user "Alice" has shared file "/fileToShareWithUser.txt" with user "Brian" + And user "Alice" has shared file "/fileToShareWithGroup.txt" with group "grp1" + And user "Alice" has created a public link share with settings + | path | /fileToShareWithPublic.txt | + | permissions | read | + + Scenario Outline: getting shares received from users + Given using OCS API version "" + When user "Brian" gets the user shares shared with him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And exactly 2 files or folders should be included in the response + And folder "folderToShareWithUser" should be included in the response + And file "fileToShareWithUser.txt" should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting shares received from groups + Given using OCS API version "" + When user "Brian" gets the group shares shared with him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And exactly 2 files or folders should be included in the response + And folder "folderToShareWithGroup" should be included in the response + And folder "fileToShareWithGroup.txt" should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | diff --git a/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesReceivedFilteredEmpty.feature b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesReceivedFilteredEmpty.feature new file mode 100644 index 000000000000..6779c5cd0818 --- /dev/null +++ b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesReceivedFilteredEmpty.feature @@ -0,0 +1,81 @@ +@api @files_sharing-app-required @notToImplementOnOCIS +Feature: sharing + As a user + I want to be able to know the shares that I have received of a particular type (user, group etc) + So that I can reduce the amount of data that has to be transferred to be just the data that I need + + Background: + Given these users have been created with default attributes and without skeleton files: + | username | + | Alice | + | Brian | + And group "grp1" has been created + And user "Brian" has been added to group "grp1" + And user "Alice" has created folder "/folderToShareWithUser" + And user "Alice" has created folder "/folderToShareWithGroup" + And user "Alice" has created folder "/folderToShareWithPublic" + And user "Alice" has uploaded file with content "file to share with user" to "/fileToShareWithUser.txt" + And user "Alice" has uploaded file with content "file to share with group" to "/fileToShareWithGroup.txt" + And user "Alice" has uploaded file with content "file to share with public" to "/fileToShareWithPublic.txt" + + Scenario Outline: getting shares received from users when there are none + Given using OCS API version "" + And user "Alice" has shared folder "/folderToShareWithGroup" with group "grp1" + And user "Alice" has created a public link share with settings + | path | /folderToShareWithPublic | + | permissions | read | + And user "Alice" has shared file "/fileToShareWithGroup.txt" with group "grp1" + And user "Alice" has created a public link share with settings + | path | /fileToShareWithPublic.txt | + | permissions | read | + When user "Brian" gets the user shares shared with him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And no files or folders should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting shares received from groups when there are none + Given using OCS API version "" + And user "Alice" has shared folder "/folderToShareWithUser" with user "Brian" + And user "Alice" has created a public link share with settings + | path | /folderToShareWithPublic | + | permissions | read | + And user "Alice" has shared file "/fileToShareWithUser.txt" with user "Brian" + And user "Alice" has created a public link share with settings + | path | /fileToShareWithPublic.txt | + | permissions | read | + When user "Brian" gets the group shares shared with him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And no files or folders should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting shares received from public links when there are none + # Note: public links are purposely created in this scenario + # users do not receive public links, so asking for a list of public links + # that are "shared with me" should always return an empty list. + Given using OCS API version "" + And user "Alice" has shared folder "/folderToShareWithUser" with user "Brian" + And user "Alice" has shared folder "/folderToShareWithGroup" with group "grp1" + And user "Alice" has created a public link share with settings + | path | /folderToShareWithPublic | + | permissions | read | + And user "Alice" has shared file "/fileToShareWithUser.txt" with user "Brian" + And user "Alice" has shared file "/fileToShareWithGroup.txt" with group "grp1" + And user "Alice" has created a public link share with settings + | path | /fileToShareWithPublic.txt | + | permissions | read | + When user "Brian" gets the public link shares shared with him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And no files or folders should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | diff --git a/tests/acceptance/features/apiShareOperationsToShares/gettingSharesReceivedFiltered.feature b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesReceivedFiltered.feature new file mode 100644 index 000000000000..5a42573f1658 --- /dev/null +++ b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesReceivedFiltered.feature @@ -0,0 +1,61 @@ +@api @files_sharing-app-required +Feature: sharing + As a user + I want to be able to know the shares that I have received of a particular type (user, group etc) + So that I can reduce the amount of data that has to be transferred to be just the data that I need + + Background: + Given the administrator has set the default folder for received shares to "Shares" + And auto-accept shares has been disabled + And these users have been created with default attributes and without skeleton files: + | username | + | Alice | + | Brian | + And group "grp1" has been created + And user "Brian" has been added to group "grp1" + And user "Alice" has created folder "/folderToShareWithUser" + And user "Alice" has created folder "/folderToShareWithGroup" + And user "Alice" has created folder "/folderToShareWithPublic" + And user "Alice" has uploaded file with content "file to share with user" to "/fileToShareWithUser.txt" + And user "Alice" has uploaded file with content "file to share with group" to "/fileToShareWithGroup.txt" + And user "Alice" has uploaded file with content "file to share with public" to "/fileToShareWithPublic.txt" + And user "Alice" has shared folder "/folderToShareWithUser" with user "Brian" + And user "Brian" has accepted share "/folderToShareWithUser" offered by user "Alice" + And user "Alice" has shared folder "/folderToShareWithGroup" with group "grp1" + And user "Brian" has accepted share "/folderToShareWithGroup" offered by user "Alice" + And user "Alice" has created a public link share with settings + | path | /folderToShareWithPublic | + | permissions | read | + And user "Alice" has shared file "/fileToShareWithUser.txt" with user "Brian" + And user "Brian" has accepted share "/fileToShareWithUser.txt" offered by user "Alice" + And user "Alice" has shared file "/fileToShareWithGroup.txt" with group "grp1" + And user "Brian" has accepted share "/fileToShareWithGroup.txt" offered by user "Alice" + And user "Alice" has created a public link share with settings + | path | /fileToShareWithPublic.txt | + | permissions | read | + + Scenario Outline: getting shares received from users + Given using OCS API version "" + When user "Brian" gets the user shares shared with him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And exactly 2 files or folders should be included in the response + And folder "/Shares/folderToShareWithUser" should be included in the response + And file "/Shares/fileToShareWithUser.txt" should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting shares received from groups + Given using OCS API version "" + When user "Brian" gets the group shares shared with him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And exactly 2 files or folders should be included in the response + And folder "/Shares/folderToShareWithGroup" should be included in the response + And folder "/Shares/fileToShareWithGroup.txt" should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | diff --git a/tests/acceptance/features/apiShareOperationsToShares/gettingSharesReceivedFilteredEmpty.feature b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesReceivedFilteredEmpty.feature new file mode 100644 index 000000000000..b1ca14a96aa0 --- /dev/null +++ b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesReceivedFilteredEmpty.feature @@ -0,0 +1,91 @@ +@api @files_sharing-app-required +Feature: sharing + As a user + I want to be able to know the shares that I have received of a particular type (user, group etc) + So that I can reduce the amount of data that has to be transferred to be just the data that I need + + Background: + Given the administrator has set the default folder for received shares to "Shares" + And auto-accept shares has been disabled + And these users have been created with default attributes and without skeleton files: + | username | + | Alice | + | Brian | + And group "grp1" has been created + And user "Brian" has been added to group "grp1" + And user "Alice" has created folder "/folderToShareWithUser" + And user "Alice" has created folder "/folderToShareWithGroup" + And user "Alice" has created folder "/folderToShareWithPublic" + And user "Alice" has uploaded file with content "file to share with user" to "/fileToShareWithUser.txt" + And user "Alice" has uploaded file with content "file to share with group" to "/fileToShareWithGroup.txt" + And user "Alice" has uploaded file with content "file to share with public" to "/fileToShareWithPublic.txt" + + Scenario Outline: getting shares received from users when there are none + Given using OCS API version "" + And user "Alice" has shared folder "/folderToShareWithGroup" with group "grp1" + And user "Brian" has accepted share "/folderToShareWithGroup" offered by user "Alice" + And user "Alice" has created a public link share with settings + | path | /folderToShareWithPublic | + | permissions | read | + And user "Alice" has shared file "/fileToShareWithGroup.txt" with group "grp1" + And user "Brian" has accepted share "/fileToShareWithGroup.txt" offered by user "Alice" + And user "Alice" has created a public link share with settings + | path | /fileToShareWithPublic.txt | + | permissions | read | + When user "Brian" gets the user shares shared with him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And no files or folders should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting shares received from groups when there are none + Given using OCS API version "" + And user "Alice" has shared folder "/folderToShareWithUser" with user "Brian" + And user "Brian" has accepted share "/folderToShareWithUser" offered by user "Alice" + And user "Alice" has created a public link share with settings + | path | /folderToShareWithPublic | + | permissions | read | + And user "Alice" has shared file "/fileToShareWithUser.txt" with user "Brian" + And user "Brian" has accepted share "/fileToShareWithUser.txt" offered by user "Alice" + And user "Alice" has created a public link share with settings + | path | /fileToShareWithPublic.txt | + | permissions | read | + When user "Brian" gets the group shares shared with him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And no files or folders should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting shares received from public links when there are none + # Note: public links are purposely created in this scenario + # users do not receive public links, so asking for a list of public links + # that are "shared with me" should always return an empty list. + Given using OCS API version "" + And user "Alice" has shared folder "/folderToShareWithUser" with user "Brian" + And user "Brian" has accepted share "/folderToShareWithUser" offered by user "Alice" + And user "Alice" has shared folder "/folderToShareWithGroup" with group "grp1" + And user "Brian" has accepted share "/folderToShareWithGroup" offered by user "Alice" + And user "Alice" has created a public link share with settings + | path | /folderToShareWithPublic | + | permissions | read | + And user "Alice" has shared file "/fileToShareWithUser.txt" with user "Brian" + And user "Brian" has accepted share "/fileToShareWithUser.txt" offered by user "Alice" + And user "Alice" has shared file "/fileToShareWithGroup.txt" with group "grp1" + And user "Brian" has accepted share "/fileToShareWithGroup.txt" offered by user "Alice" + And user "Alice" has created a public link share with settings + | path | /fileToShareWithPublic.txt | + | permissions | read | + When user "Brian" gets the public link shares shared with him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And no files or folders should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | From b319f0b771242dba7274dd500974452f485d2b29 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Tue, 20 Oct 2020 20:42:23 +0545 Subject: [PATCH 6/7] Add API acceptance tests for filtering pending shares by share type --- .../gettingSharesReceivedFiltered.feature | 2 +- ...gettingSharesReceivedFilteredEmpty.feature | 2 +- .../gettingSharesSharedFiltered.feature | 2 +- .../gettingSharesSharedFilteredEmpty.feature | 2 +- .../gettingSharesPendingFiltered.feature | 57 +++++++++++++++++++ .../gettingSharesReceivedFiltered.feature | 2 +- ...gettingSharesReceivedFilteredEmpty.feature | 2 +- .../gettingSharesSharedFiltered.feature | 2 +- .../gettingSharesSharedFilteredEmpty.feature | 2 +- .../acceptance/features/bootstrap/Sharing.php | 14 +++-- 10 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 tests/acceptance/features/apiShareOperationsToShares/gettingSharesPendingFiltered.feature diff --git a/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesReceivedFiltered.feature b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesReceivedFiltered.feature index 930a0ee95473..b4eb2280b75c 100644 --- a/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesReceivedFiltered.feature +++ b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesReceivedFiltered.feature @@ -1,5 +1,5 @@ @api @files_sharing-app-required @notToImplementOnOCIS -Feature: sharing +Feature: get the received shares filtered by type (user, group etc) As a user I want to be able to know the shares that I have received of a particular type (user, group etc) So that I can reduce the amount of data that has to be transferred to be just the data that I need diff --git a/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesReceivedFilteredEmpty.feature b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesReceivedFilteredEmpty.feature index 6779c5cd0818..7338d3738dc4 100644 --- a/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesReceivedFilteredEmpty.feature +++ b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesReceivedFilteredEmpty.feature @@ -1,5 +1,5 @@ @api @files_sharing-app-required @notToImplementOnOCIS -Feature: sharing +Feature: get the received shares filtered by type (user, group etc) As a user I want to be able to know the shares that I have received of a particular type (user, group etc) So that I can reduce the amount of data that has to be transferred to be just the data that I need diff --git a/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFiltered.feature b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFiltered.feature index 70496e0b4d45..07161df62384 100644 --- a/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFiltered.feature +++ b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFiltered.feature @@ -1,5 +1,5 @@ @api @files_sharing-app-required @notToImplementOnOCIS -Feature: sharing +Feature: get shares filtered by type (user, group etc) As a user I want to be able to know the shares that I have made of a particular type (user, group etc) So that I can reduce the amount of data that has to be transferred to be just the data that I need diff --git a/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFilteredEmpty.feature b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFilteredEmpty.feature index 2a970e01984b..88e04f7a897e 100644 --- a/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFilteredEmpty.feature +++ b/tests/acceptance/features/apiShareOperationsToRoot/gettingSharesSharedFilteredEmpty.feature @@ -1,5 +1,5 @@ @api @files_sharing-app-required @notToImplementOnOCIS -Feature: sharing +Feature: get shares filtered by type (user, group etc) As a user I want to be able to know the shares that I have made of a particular type (user, group etc) So that I can reduce the amount of data that has to be transferred to be just the data that I need diff --git a/tests/acceptance/features/apiShareOperationsToShares/gettingSharesPendingFiltered.feature b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesPendingFiltered.feature new file mode 100644 index 000000000000..a8571d79d1b2 --- /dev/null +++ b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesPendingFiltered.feature @@ -0,0 +1,57 @@ +@api @files_sharing-app-required +Feature: get the pending shares filtered by type (user, group etc) + As a user + I want to be able to know the pending shares that I have received of a particular type (user, group etc) + So that I can reduce the amount of data that has to be transferred to be just the data that I need + + Background: + Given the administrator has set the default folder for received shares to "Shares" + And auto-accept shares has been disabled + And these users have been created with default attributes and without skeleton files: + | username | + | Alice | + | Brian | + And group "grp1" has been created + And user "Brian" has been added to group "grp1" + And user "Alice" has created folder "/folderToShareWithUser" + And user "Alice" has created folder "/folderToShareWithGroup" + And user "Alice" has created folder "/folderToShareWithPublic" + And user "Alice" has uploaded file with content "file to share with user" to "/fileToShareWithUser.txt" + And user "Alice" has uploaded file with content "file to share with group" to "/fileToShareWithGroup.txt" + And user "Alice" has uploaded file with content "file to share with public" to "/fileToShareWithPublic.txt" + And user "Alice" has shared folder "/folderToShareWithUser" with user "Brian" + And user "Alice" has shared folder "/folderToShareWithGroup" with group "grp1" + And user "Alice" has created a public link share with settings + | path | /folderToShareWithPublic | + | permissions | read | + And user "Alice" has shared file "/fileToShareWithUser.txt" with user "Brian" + And user "Brian" has accepted share "/fileToShareWithUser.txt" offered by user "Alice" + And user "Alice" has shared file "/fileToShareWithGroup.txt" with group "grp1" + And user "Brian" has accepted share "/fileToShareWithGroup.txt" offered by user "Alice" + And user "Alice" has created a public link share with settings + | path | /fileToShareWithPublic.txt | + | permissions | read | + + Scenario Outline: getting pending shares received from users + Given using OCS API version "" + When user "Brian" gets the pending user shares shared with him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And exactly 1 file or folder should be included in the response + And folder "/Shares/folderToShareWithUser" should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | + + Scenario Outline: getting pending shares received from groups + Given using OCS API version "" + When user "Brian" gets the pending group shares shared with him using the sharing API + Then the OCS status code should be "" + And the HTTP status code should be "200" + And exactly 1 file or folder should be included in the response + And folder "/Shares/folderToShareWithGroup" should be included in the response + Examples: + | ocs_api_version | ocs_status_code | + | 1 | 100 | + | 2 | 200 | diff --git a/tests/acceptance/features/apiShareOperationsToShares/gettingSharesReceivedFiltered.feature b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesReceivedFiltered.feature index 5a42573f1658..7bfd37825a59 100644 --- a/tests/acceptance/features/apiShareOperationsToShares/gettingSharesReceivedFiltered.feature +++ b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesReceivedFiltered.feature @@ -1,5 +1,5 @@ @api @files_sharing-app-required -Feature: sharing +Feature: get the received shares filtered by type (user, group etc) As a user I want to be able to know the shares that I have received of a particular type (user, group etc) So that I can reduce the amount of data that has to be transferred to be just the data that I need diff --git a/tests/acceptance/features/apiShareOperationsToShares/gettingSharesReceivedFilteredEmpty.feature b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesReceivedFilteredEmpty.feature index b1ca14a96aa0..49c202c6e567 100644 --- a/tests/acceptance/features/apiShareOperationsToShares/gettingSharesReceivedFilteredEmpty.feature +++ b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesReceivedFilteredEmpty.feature @@ -1,5 +1,5 @@ @api @files_sharing-app-required -Feature: sharing +Feature: get the received shares filtered by type (user, group etc) As a user I want to be able to know the shares that I have received of a particular type (user, group etc) So that I can reduce the amount of data that has to be transferred to be just the data that I need diff --git a/tests/acceptance/features/apiShareOperationsToShares/gettingSharesSharedFiltered.feature b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesSharedFiltered.feature index 8f72c2127f8d..afcd112dee2a 100644 --- a/tests/acceptance/features/apiShareOperationsToShares/gettingSharesSharedFiltered.feature +++ b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesSharedFiltered.feature @@ -1,5 +1,5 @@ @api @files_sharing-app-required -Feature: sharing +Feature: get shares filtered by type (user, group etc) As a user I want to be able to know the shares that I have made of a particular type (user, group etc) So that I can reduce the amount of data that has to be transferred to be just the data that I need diff --git a/tests/acceptance/features/apiShareOperationsToShares/gettingSharesSharedFilteredEmpty.feature b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesSharedFilteredEmpty.feature index 47ec514a4eb4..249c10d39d6a 100644 --- a/tests/acceptance/features/apiShareOperationsToShares/gettingSharesSharedFilteredEmpty.feature +++ b/tests/acceptance/features/apiShareOperationsToShares/gettingSharesSharedFilteredEmpty.feature @@ -1,5 +1,5 @@ @api @files_sharing-app-required -Feature: sharing +Feature: get shares filtered by type (user, group etc) As a user I want to be able to know the shares that I have made of a particular type (user, group etc) So that I can reduce the amount of data that has to be transferred to be just the data that I need diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index 49412c38d4ae..a03d68b92ce0 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -1066,7 +1066,7 @@ public function checkCountFilesFoldersInResponse($count) { $count = (int) $count; $data = $this->getResponseXml(null, __METHOD__)->data[0]; Assert::assertIsObject($data, __METHOD__ . " data not found in response XML"); - Assert::assertCount($count, $data); + Assert::assertCount($count, $data, __METHOD__ . " the response does not contain $count entries"); } /** @@ -1735,15 +1735,21 @@ public function userGetsAllTheSharesSharedWithHimUsingTheSharingApi($user) { } /** - * @When /^user "([^"]*)" gets the (user|group|user and group|public link) shares shared with him using the sharing API$/ + * @When /^user "([^"]*)" gets the (|pending)\s?(user|group|user and group|public link) shares shared with him using the sharing API$/ * * @param string $user + * @param string $pending * @param string $shareType * * @return void */ - public function userGetsFilteredSharesSharedWithHimUsingTheSharingApi($user, $shareType) { + public function userGetsFilteredSharesSharedWithHimUsingTheSharingApi($user, $pending, $shareType) { $user = $this->getActualUsername($user); + if ($pending === "pending") { + $pendingClause = "&state=" . SharingHelper::SHARE_STATES['pending']; + } else { + $pendingClause = ""; + } if ($shareType === 'public link') { $shareType = 'public_link'; } @@ -1756,7 +1762,7 @@ public function userGetsFilteredSharesSharedWithHimUsingTheSharingApi($user, $sh $user, 'GET', $this->getSharesEndpointPath( - "?shared_with_me=true&share_types=" . $rawShareTypes + "?shared_with_me=true" . $pendingClause . "&share_types=" . $rawShareTypes ), null ); From 95fc0aaaa10d0a796a3bf7e23bd12f94a81dc27e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Wed, 28 Oct 2020 16:29:46 +0100 Subject: [PATCH 7/7] Simplify code --- .../lib/Controller/Share20OcsController.php | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/apps/files_sharing/lib/Controller/Share20OcsController.php b/apps/files_sharing/lib/Controller/Share20OcsController.php index 281b587180bf..b88296712f11 100644 --- a/apps/files_sharing/lib/Controller/Share20OcsController.php +++ b/apps/files_sharing/lib/Controller/Share20OcsController.php @@ -632,17 +632,13 @@ private function getSharesInDir($folder, $requestedShareTypes) { continue; } - if ($shareType !== Share::SHARE_TYPE_REMOTE) { - $shares = \array_merge( - $shares, - $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), $shareType, $node, false, -1, 0) - ); - } elseif ($shareType === Share::SHARE_TYPE_REMOTE && $this->shareManager->outgoingServer2ServerSharesAllowed()) { - $shares = \array_merge( - $shares, - $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), $shareType, $node, false, -1, 0) - ); - } + // if outgoingServer2ServerSharesAllowed is false, remote shares shouldn't be + // returned. This must be checked in the caller method, so the remote share type + // shouldn't be present if outgoing remotes shares aren't allowed. + $shares = \array_merge( + $shares, + $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), $shareType, $node, false, -1, 0) + ); } } @@ -707,6 +703,11 @@ public function getShares() { Share::SHARE_TYPE_LINK => false, Share::SHARE_TYPE_REMOTE => false, ]; + + if ($this->shareManager->outgoingServer2ServerSharesAllowed() === false) { + // if outgoing remote shares aren't allowed, the remote share type can't be chosen + unset($requestedShareTypes[Share::SHARE_TYPE_REMOTE]); + } foreach ($shareTypes as $shareType) { if (isset($requestedShareTypes[$shareType])) { $requestedShareTypes[$shareType] = true; @@ -763,17 +764,10 @@ public function getShares() { continue; } - if ($shareType !== Share::SHARE_TYPE_REMOTE) { - $shares = \array_merge( - $shares, - $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), $shareType, $path, $reshares, -1, 0) - ); - } elseif ($shareType === Share::SHARE_TYPE_REMOTE && $this->shareManager->outgoingServer2ServerSharesAllowed()) { - $shares = \array_merge( - $shares, - $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), $shareType, $path, $reshares, -1, 0) - ); - } + $shares = \array_merge( + $shares, + $this->shareManager->getSharesBy($this->userSession->getUser()->getUID(), $shareType, $path, $reshares, -1, 0) + ); } $formatted = [];