diff --git a/tests/acceptance/bootstrap/CliContext.php b/tests/acceptance/bootstrap/CliContext.php index 8b4be580ba2..f89e0daf947 100644 --- a/tests/acceptance/bootstrap/CliContext.php +++ b/tests/acceptance/bootstrap/CliContext.php @@ -1048,4 +1048,65 @@ class CliContext implements Context { ]; $this->featureContext->setResponse(CliHelper::runCommand($body)); } + + /** + * @When administrator deletes :space space using the CLI + * + * @param string $space + * + * @return void + * @throws GuzzleException + */ + public function theAdministratorDeletesSpaceUsingTheCLI(string $space): void { + $command = "storage-users spaces purge -t=" . strtolower($space) . " -r=0s -v -d=false"; + $body = [ + "command" => $command, + ]; + $this->featureContext->setResponse(CliHelper::runCommand($body)); + } + + /** + * @When administrator deletes :space space of user :user with space-id using the CLI + * + * @param string $spaceName + * @param string $user + * + * @return void + * @throws GuzzleException + */ + public function administratorDeletesSpaceWithSpaceIdUsingTheCli(string $spaceName, string $user): void { + $space = $this->featureContext->spacesContext->getSpaceByName($user, $spaceName); + + if ($spaceName === "Personal") { + $spaceType = "personal"; + } else { + $spaceType = 'project'; + } + + $command = "storage-users spaces purge -t=$spaceType -s=" . $space['id'] . " -r=0s -v -d=false"; + $body = [ + "command" => $command, + ]; + $this->featureContext->setResponse(CliHelper::runCommand($body)); + } + + /** + * @When administrator deletes :space space with :retentionPeriod retention period using the CLI + * + * @param string $space + * @param string $retentionPeriod + * + * @return void + * @throws GuzzleException + */ + public function administratorDeletesSpaceWithRetentionPeriodOfUsingTheCli( + string $space, + string $retentionPeriod, + ): void { + $command = "storage-users spaces purge -t=" . strtolower($space) . " -r=$retentionPeriod -v -d=false"; + $body = [ + "command" => $command, + ]; + $this->featureContext->setResponse(CliHelper::runCommand($body)); + } } diff --git a/tests/acceptance/bootstrap/SpacesContext.php b/tests/acceptance/bootstrap/SpacesContext.php index 46cebf923ce..a1dd3ddec3b 100644 --- a/tests/acceptance/bootstrap/SpacesContext.php +++ b/tests/acceptance/bootstrap/SpacesContext.php @@ -3098,6 +3098,34 @@ class SpacesContext implements Context { ); } + /** + * @Given /^user "([^"]*)" has disabled personal space of user "([^"]*)"$/ + * + * @param string $user + * @param string $spaceOwnerName + * + * @return void + * @throws GuzzleException + */ + public function userHasDisabledPersonalSpaceOfUser( + string $user, + string $spaceOwnerName, + ): void { + $space = $this->getSpaceByName($spaceOwnerName, "Personal"); + $response = GraphHelper::disableSpace( + $this->featureContext->getBaseUrl(), + $user, + $this->featureContext->getPasswordForUser($user), + $space["id"], + ); + $expectedHTTPStatus = "204"; + $this->featureContext->theHTTPStatusCodeShouldBe( + $expectedHTTPStatus, + "Expected response status code should be $expectedHTTPStatus", + $response, + ); + } + /** * @param string $user * @param string $spaceName diff --git a/tests/acceptance/features/cliCommands/deletePersonalSpace.feature b/tests/acceptance/features/cliCommands/deletePersonalSpace.feature new file mode 100644 index 00000000000..3f83012de1f --- /dev/null +++ b/tests/acceptance/features/cliCommands/deletePersonalSpace.feature @@ -0,0 +1,64 @@ +@env-config +Feature: delete space using cli + As an administrator + I want to delete spaces of users using cli + So that I can manage them + + Background: + Given user "Alice" has been created with default attributes + + + Scenario: administrator deletes personal space of users + Given user "Admin" has disabled personal space of user "Alice" + When administrator deletes "Personal" space using the CLI + Then the command should be successful + And the command output should contain "Purge completed. Purged 1 spaces" + + + Scenario: administrator deletes project spaces of users + Given the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "project1" with the default quota using the Graph API + And user "Alice" has created a space "project2" with the default quota using the Graph API + And user "Alice" has disabled a space "project1" + And user "Alice" has disabled a space "project2" + When administrator deletes "Project" space using the CLI + Then the command should be successful + And the command output should contain "Purge completed. Purged 2 spaces" + + + Scenario: administrator deletes personal space of users using space-id (Personal) + Given user "Admin" has disabled personal space of user "Alice" + When administrator deletes "Personal" space of user "Alice" with space-id using the CLI + Then the command should be successful + And the command output should contain "Purge completed. Purged 1 spaces" + + + Scenario: administrator deletes project space of users using space-id (Project) + Given the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "project" with the default quota using the Graph API + And user "Alice" has disabled a space "project" + When administrator deletes "project" space of user "Alice" with space-id using the CLI + Then the command should be successful + And the command output should contain "Purge completed. Purged 1 spaces" + + + Scenario: administrator deletes spaces beyond the retention-period + Given using spaces DAV path + And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "project" with the default quota using the Graph API + And user "Alice" has disabled a space "project" + And the administrator has waited for "5s" seconds + And user "Alice" has created a space "project1" with the default quota using the Graph API + And user "Alice" has disabled a space "project1" + When administrator deletes "Project" space with "2s" retention period using the CLI + Then the command should be successful + And the command output should contain "Purge completed. Purged 1 spaces" + + + Scenario: administrator tries to delete enabled spaces + Given the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "project" with the default quota using the Graph API + When administrator deletes "project" space of user "Alice" with space-id using the CLI + Then the command should be successful + And the command output should contain "Purge completed. Purged 0 spaces" +