From 737cadac209b3911eb877fda0a93d4dabf0d562b Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi Date: Thu, 11 Jan 2024 11:33:59 +0545 Subject: [PATCH] Add tests for remove permissions link share Signed-off-by: Swikriti Tripathi --- ...ected-failures-localAPI-on-OCIS-storage.md | 2 + .../apiSharingNg/deletePermissions.feature | 36 ++++++++ .../features/bootstrap/SharingNgContext.php | 88 +++++++++++++++---- 3 files changed, 109 insertions(+), 17 deletions(-) diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index ae6d64f0574..e10e0697dce 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -265,5 +265,7 @@ The expected failures in this file are from features in the owncloud/ocis repo. - [apiSharingNg/linkShare.feature:447](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSharingNg/linkShare.feature#L447) - [apiSharingNg/linkShare.feature:448](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSharingNg/linkShare.feature#L448) - [apiSharingNg/linkShare.feature:449](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSharingNg/linkShare.feature#L449) +- [apiSharingNg/deletePermissions.feature:147](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSharingNg/deletePermissions.feature#L147) +- [apiSharingNg/deletePermissions.feature:162](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSharingNg/deletePermissions.feature#L162) - Note: always have an empty line at the end of this file. The bash script that processes this file requires that the last line has a newline on the end. diff --git a/tests/acceptance/features/apiSharingNg/deletePermissions.feature b/tests/acceptance/features/apiSharingNg/deletePermissions.feature index 9cd1a3c4cf3..ec819ea9a81 100644 --- a/tests/acceptance/features/apiSharingNg/deletePermissions.feature +++ b/tests/acceptance/features/apiSharingNg/deletePermissions.feature @@ -125,3 +125,39 @@ Feature: Remove access to a drive item | Co Owner | folder | FolderToShare | | Uploader | folder | FolderToShare | | Manager | folder | FolderToShare | + + + Scenario Outline: user removes access to a folder in link share + Given user "Alice" has created folder "FolderToShare" + And user "Alice" has created the following link share: + | resourceType | folder | + | resource | FolderToShare | + | space | Personal | + | permissionsRole | | + | password | %public% | + When user "Alice" removes the share permission of link from folder "FolderToShare" of space "Personal" using the Graph API + Then the HTTP status code should be "204" + Examples: + | role | + | view | + | edit | + | upload | + | createOnly | + | blocksDownload | + + + Scenario Outline: user removes access to a folder in link share + Given user "Alice" has uploaded file "filesForUpload/textfile.txt" to "textfile.txt" + And user "Alice" has created the following link share: + | resourceType | file | + | resource | textfile.txt | + | space | Personal | + | permissionsRole | | + | password | %public% | + When user "Alice" removes the share permission of link from file "textfile.txt" of space "Personal" using the Graph API + Then the HTTP status code should be "204" + Examples: + | permissionsRole | + | view | + | edit | + | blocksDownload | diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index 045b7c70a0c..6f47b3b39ee 100644 --- a/tests/acceptance/features/bootstrap/SharingNgContext.php +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -328,7 +328,51 @@ public function userSetsOrUpdatesFollowingPasswordForLastLinkShareUsingTheGraphA $this->featureContext->setResponse($response); } - /** + /** + * @param string $sharer + * @param string $shareType (user|group) + * @param string $resourceType + * @param string $resource + * @param string $space + * @param string|null $sharee can be both user or group + * + * @return ResponseInterface + * @throws GuzzleException + * @throws JsonException + */ + public function removeSharePermissionOfAResource( + string $sharer, + string $shareType, + string $resourceType, + string $resource, + string $space, + ?string $sharee = null, + ): ResponseInterface + { + $spaceId = ($this->spacesContext->getSpaceByName($sharer, $space))["id"]; + $itemId = ($resourceType === 'folder') + ? $this->spacesContext->getResourceId($sharer, $space, $resource) + : $this->spacesContext->getFileId($sharer, $space, $resource); + $permId = null; + if($shareType === 'link') { + $permId = $this->featureContext->shareNgGetLastCreatedLinkShareID(); + } else { + $permId = $this->featureContext->shareNgGetLastCreatedUserGroupShareID(); + } + return + GraphHelper::deleteSharePermission( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $sharer, + $this->featureContext->getPasswordForUser($sharer), + $spaceId, + $itemId, + $permId + ); + } + + + /** * @When /^user "([^"]*)" removes the share permission of (user|group) "([^"]*)" from (file|folder) "([^"]*)" of space "([^"]*)" using the Graph API$/ * * @param string $sharer @@ -350,21 +394,31 @@ public function userRemovesSharePermissionOfUserFromResourceOfSpaceUsingGraphAPI string $resource, string $space ): void { - $spaceId = ($this->spacesContext->getSpaceByName($sharer, $space))["id"]; - $itemId = ($resourceType === 'folder') - ? $this->spacesContext->getResourceId($sharer, $space, $resource) - : $this->spacesContext->getFileId($sharer, $space, $resource); - $permId = $this->featureContext->shareNgGetLastCreatedUserGroupShareID(); - $this->featureContext->setResponse( - GraphHelper::deleteSharePermission( - $this->featureContext->getBaseUrl(), - $this->featureContext->getStepLineRef(), - $sharer, - $this->featureContext->getPasswordForUser($sharer), - $spaceId, - $itemId, - $permId - ) - ); + $this->featureContext->setResponse( + $this->removeSharePermissionOfAResource($sharer,$shareType,$resourceType,$resource,$space) + ); } + + /** + * @When /^user "([^"]*)" removes the share permission of link from (file|folder) "([^"]*)" of space "([^"]*)" using the Graph API$/ + * + * @param string $sharer + * @param string $resourceType + * @param string $resource + * @param string $space + * + * @return void + * @throws JsonException + * @throws GuzzleException + */ + public function removeSharePermissionOfAResourceInLinkShareUsingGraphAPI( + string $sharer, + string $resourceType, + string $resource, + string $space + ):void { + $this->featureContext->setResponse( + $this->removeSharePermissionOfAResource($sharer,'link',$resourceType,$resource,$space) + ); + } }