Skip to content

Commit

Permalink
user deletes own access of the space
Browse files Browse the repository at this point in the history
  • Loading branch information
ScharfViktor committed Apr 26, 2024
1 parent f7fb0bc commit 4f746e8
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<status-code>"
And the user "Carol" <shouldOrNot> 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" removes 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" using root endpoint of the Graph API
When user "Brian" removes 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"
42 changes: 34 additions & 8 deletions tests/acceptance/features/bootstrap/SharingNgContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ public function removeAccessToSpaceItem(
* @param string $sharer
* @param string $shareType (user|group|link)
* @param string $space
* @param string|null $recipient
* @param string $recipient
*
* @return ResponseInterface
* @throws GuzzleException
Expand All @@ -531,13 +531,17 @@ public function removeAccessToSpace(
string $sharer,
string $shareType,
string $space,
?string $recipient = null
?string $recipient
): 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(),
Expand Down Expand Up @@ -593,7 +597,7 @@ public function userRemovesAccessOfUserOrGroupFromSpaceUsingPermissionsEndpointO
string $space
): void {
$this->featureContext->setResponse(
$this->removeAccessToSpaceItem($sharer, $recipientType, $space)
$this->removeAccessToSpaceItem($sharer, $recipientType, $space, null, $recipient)
);
}

Expand Down Expand Up @@ -637,7 +641,7 @@ public function userRemovesAccessOfUserOrGroupFromSpaceUsingGraphAPI(
string $space
): void {
$this->featureContext->setResponse(
$this->removeAccessToSpace($sharer, $recipientType, $space)
$this->removeAccessToSpace($sharer, $recipientType, $space, $recipient)
);
}

Expand All @@ -656,10 +660,32 @@ public function userRemovesLinkFromSpaceUsingRootEndpointOfGraphAPI(
string $space
):void {
$this->featureContext->setResponse(
$this->removeAccessToSpace($sharer, 'link', $space)
$this->removeAccessToSpace($sharer, 'link', $space, null)
);
}

/**
* @When /^user "([^"]*)" has removed the access of (user|group) "([^"]*)" from space "([^"]*)" using root endpoint of the Graph API$/
*
* @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 userHasRemovedAccessOfUserOrGroupFromSpaceUsingGraphAPI(
string $sharer,
string $recipientType,
string $recipient,
string $space
): void {
$this->userRemovesAccessOfUserOrGroupFromSpaceUsingGraphAPI($sharer, $recipientType, $recipient, $space);
$this->featureContext->theHTTPStatusCodeShouldBe(204);
}

/**
* @Then /^for user "([^"]*)" the space Shares should (not|)\s?contain these (files|entries):$/
*
Expand Down

0 comments on commit 4f746e8

Please sign in to comment.