From 836fcc5433193a86bf84c44293e5cab4b372aba3 Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Mon, 29 Apr 2024 11:59:08 +0200 Subject: [PATCH] user deletes own access of the space (#8986) --- .../apiSharingNg/removeAccessToDrive.feature | 26 ++++++++++++- .../features/bootstrap/SharingNgContext.php | 37 ++++++++++++++++--- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/tests/acceptance/features/apiSharingNg/removeAccessToDrive.feature b/tests/acceptance/features/apiSharingNg/removeAccessToDrive.feature index 339a672030..deb8cea2df 100644 --- a/tests/acceptance/features/apiSharingNg/removeAccessToDrive.feature +++ b/tests/acceptance/features/apiSharingNg/removeAccessToDrive.feature @@ -128,8 +128,32 @@ Feature: Remove access to a drive When user "Brian" removes the access of user "Carol" from space "NewSpace" using permissions endpoint of the Graph API Then the HTTP status code should be "" And the user "Carol" have a space called "NewSpace" - Examples: + Examples: | permissions-role | status-code | shouldOrNot | | Space Viewer | 403 | should | | Space Editor | 403 | should | | Manager | 204 | should not | + + + Scenario: user cannot remove himself from the project space if he is the last manager + Given the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "NewSpace" with the default quota using the Graph API + When user "Alice" tries to remove the access of user "Alice" from space "NewSpace" using root endpoint of the Graph API + Then the HTTP status code should be "403" + And the user "Alice" should have a space called "NewSpace" + + + Scenario: user of a group cannot remove own group from project space if it is the last manager + Given the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And group "group1" has been created + And user "Brian" has been added to group "group1" + And user "Alice" has created a space "NewSpace" with the default quota using the Graph API + And user "Alice" has sent the following share invitation: + | space | NewSpace | + | sharee | group1 | + | shareType | group | + | permissionsRole | Manager | + And user "Alice" has removed the access of user "Alice" from space "NewSpace" + When user "Brian" tries to remove the access of group "group1" from space "NewSpace" using root endpoint of the Graph API + Then the HTTP status code should be "403" + And the user "Brian" should have a space called "NewSpace" diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index c5670080f4..7e1e7f7288 100644 --- a/tests/acceptance/features/bootstrap/SharingNgContext.php +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -537,9 +537,13 @@ class SharingNgContext implements Context { ): ResponseInterface { $spaceId = ($this->spacesContext->getSpaceByName($sharer, $space))["id"]; - $permId = ($shareType === 'link') - ? $this->featureContext->shareNgGetLastCreatedLinkShareID() - : $this->featureContext->shareNgGetLastCreatedUserGroupShareID(); + $permId = match ($shareType) { + 'link' => $this->featureContext->shareNgGetLastCreatedLinkShareID(), + 'user' => 'u:' . $this->featureContext->getAttributeOfCreatedUser($recipient, 'id'), + 'group' => 'g:' . $this->featureContext->getAttributeOfCreatedGroup($recipient, 'id'), + default => throw new Exception("shareType '$shareType' does not match user|group|link "), + }; + return GraphHelper::removeAccessToSpace( $this->featureContext->getBaseUrl(), @@ -595,7 +599,7 @@ class SharingNgContext implements Context { string $space ): void { $this->featureContext->setResponse( - $this->removeAccessToSpaceItem($sharer, $recipientType, $space) + $this->removeAccessToSpaceItem($sharer, $recipientType, $space, null, $recipient) ); } @@ -622,6 +626,7 @@ class SharingNgContext implements Context { /** * @When /^user "([^"]*)" removes the access of (user|group) "([^"]*)" from space "([^"]*)" using root endpoint of the Graph API$/ + * @When /^user "([^"]*)" tries to remove the access of (user|group) "([^"]*)" from space "([^"]*)" using root endpoint of the Graph API$/ * * @param string $sharer * @param string $recipientType (user|group) @@ -639,7 +644,7 @@ class SharingNgContext implements Context { string $space ): void { $this->featureContext->setResponse( - $this->removeAccessToSpace($sharer, $recipientType, $space) + $this->removeAccessToSpace($sharer, $recipientType, $space, $recipient) ); } @@ -662,6 +667,28 @@ class SharingNgContext implements Context { ); } + /** + * @Given /^user "([^"]*)" has removed the access of (user|group) "([^"]*)" from space "([^"]*)"$/ + * + * @param string $sharer + * @param string $recipientType (user|group) + * @param string $recipient can be both user or group + * @param string $space + * + * @return void + * @throws JsonException + * @throws GuzzleException + */ + public function userHasRemovedAccessOfUserOrGroupFromSpace( + string $sharer, + string $recipientType, + string $recipient, + string $space + ): void { + $response = $this->removeAccessToSpace($sharer, $recipientType, $space, $recipient); + $this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response); + } + /** * @Then /^for user "([^"]*)" the space Shares should (not|)\s?contain these (files|entries):$/ *