Skip to content

Commit

Permalink
Copy from space project to personal
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarGi committed Jul 11, 2022
1 parent 6f6abb6 commit 02c87cb
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 62 deletions.
26 changes: 21 additions & 5 deletions tests/acceptance/features/apiSpaces/copySpaces.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: copy file
| Alice |
| Brian |

Scenario Outline: Copying a file within a same project with role manager and editor
Scenario Outline: Copying a file within a same space project with role manager and editor
Given the administrator has given "Alice" the role "Space Admin" using the settings api
And user "Alice" has created a space "Project" with the default quota using the GraphApi
And user "Alice" has created a folder "newfolder" in space "Project"
Expand All @@ -25,7 +25,7 @@ Feature: copy file
| editor |


Scenario: Copying a file within a same project with role viewer
Scenario: Copying a file within a same space project with role viewer
Given the administrator has given "Alice" the role "Space Admin" using the settings api
And user "Alice" has created a space "Project" with the default quota using the GraphApi
And user "Alice" has created a folder "newfolder" in space "Project"
Expand All @@ -35,7 +35,7 @@ Feature: copy file
And the HTTP status code should be "403"


Scenario Outline: User copy a file from a project with different role to a project with manager role
Scenario Outline: User copy a file from a space project with different role to a space project with manager role
Given the administrator has given "Brian" the role "Space Admin" using the settings api
And user "Brian" has created a space "Project1" with the default quota using the GraphApi
And user "Brian" has created a space "Project2" with the default quota using the GraphApi
Expand All @@ -52,7 +52,7 @@ Feature: copy file
| viewer |


Scenario Outline: User copy a file from a project with different role to a project with editor role
Scenario Outline: User copy a file from a space project with different role to a space project with editor role
Given the administrator has given "Brian" the role "Space Admin" using the settings api
And user "Brian" has created a space "Project1" with the default quota using the GraphApi
And user "Brian" has created a space "Project2" with the default quota using the GraphApi
Expand All @@ -68,7 +68,7 @@ Feature: copy file
| editor |
| viewer |

Scenario Outline: User copy a file from a project with different role to a project with editor role
Scenario Outline: User copy a file from a space project with different role to a space project with editor role
Given the administrator has given "Brian" the role "Space Admin" using the settings api
And user "Brian" has created a space "Project1" with the default quota using the GraphApi
And user "Brian" has created a space "Project2" with the default quota using the GraphApi
Expand All @@ -81,3 +81,19 @@ Feature: copy file
| role |
| manager |
| editor |


Scenario Outline: User copy a file from space project to personal with different role
Given the administrator has given "Brian" the role "Space Admin" using the settings api
And user "Brian" has created a space "Project" with the default quota using the GraphApi
And user "Brian" has uploaded a file inside space "Project" with content "Project content" to "project.txt"
And user "Brian" has shared a space "Project" to user "Alice" with role "<role>"
When user "Alice" copies file "project.txt" from space "Project" to "project.txt" inside personal using the WebDAV API
And the HTTP status code should be "201"
And as "Alice" file "/project.txt" should exist
And the content of file "project.txt" for user "Alice" should be "Project content"
Examples:
| role |
| manager |
| editor |
| viewer |
154 changes: 97 additions & 57 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1725,83 +1725,123 @@ public function userCopiesFileUsingTheAPI(
string $spaceName
):void {
$space = $this->getSpaceByName($user, $spaceName);
$headers['Destination'] = $this->destinationHeaderValue(
$headers['Destination'] = $this->destinationHeaderValueWithSpaceName(
$user,
$fileDestination,
$spaceName
);

$fullUrl = $this->baseUrl . "/dav/spaces/" . $space['id'] . '/' . $fileSource;
$this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);

}

/**
* @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" in space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $fileSource
* @param string $fromSpaceName
* @param string $fileDestination
* @param string $toSpaceName
*
* @return void
*/
public function userCopiesFileFromAndToSpaceBetweenProjects(
string $user,
string $fileSource,
string $fromSpaceName,
string $fileDestination,
string $toSpaceName
):void {
$space = $this->getSpaceByName($user, $fromSpaceName);
$headers['Destination'] = $this->destinationHeaderValue(
$user,
$fileDestination,
$toSpaceName
);
$fullUrl = $this->baseUrl . "/dav/spaces/" . $space['id'] . '/' . $fileSource;
$this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);

}
$this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);
}

/**
* @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" in space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $fileSource
* @param string $fromSpaceName
* @param string $fileDestination
* @param string $toSpaceName
*
* @return void
*/
public function userCopiesFileFromAndToSpaceBetweenProjects(
string $user,
string $fileSource,
string $fromSpaceName,
string $fileDestination,
string $toSpaceName
):void {
$space = $this->getSpaceByName($user, $fromSpaceName);
$headers['Destination'] = $this->destinationHeaderValueWithSpaceName(
$user,
$fileDestination,
$toSpaceName
);
$fullUrl = $this->baseUrl . "/dav/spaces/" . $space['id'] . '/' . $fileSource;
$this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);
}

/**
* @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" inside personal using the WebDAV API$/
*
* @param string $user
* @param string $fileSource
* @param string $spaceName
* @param string $fileDestination
*
* @return void
*/
public function userCopiesFileFromProjectToPersonal(
string $user,
string $fileSource,
string $spaceName,
string $fileDestination
):void {
$space = $this->getSpaceByName($user, $spaceName);
$headers['Destination'] = $this->destinationHeaderValueWithUserPersonalSpaceID(
$user,
$fileDestination,
);
$fullUrl = $this->baseUrl . "/dav/spaces/" . $space['id'] . '/' . $fileSource;
$this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);
}

/**
* returns a url for destination with spacename
*
* @param string $user
* @param string $fileDestination
* @param string $spaceName
*
* @return string
* @throws GuzzleException
*/
public function destinationHeaderValue(string $user, string $fileDestination, string $spaceName):string {
public function destinationHeaderValueWithSpaceName(string $user, string $fileDestination, string $spaceName):string {
$space = $this->getSpaceByName($user, $spaceName);
$fullUrl = $this->baseUrl . "/dav/spaces/" . $space['id'];
return \rtrim($fullUrl, '/') . '/' . \ltrim($fileDestination, '/');
}

/**
* COPY request for files|folders
*
* @param string $user
* @param string $fullUrl
* @param string $headers
*
* @return void
* @throws GuzzleException
*/
public function copyFilesAndFoldersRequest(string $user, string $fullUrl, array $headers):void {
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$fullUrl,
"",
'COPY',
$user,
$this->featureContext->getPasswordForUser($user),
$headers,
""
)
);
}
/**
* returns a url for destination with personal space id
*
* @param string $user
* @param string $fileDestination
*
* @return string
* @throws GuzzleException
*/
public function destinationHeaderValueWithUserPersonalSpaceID(string $user, string $fileDestination):string {
$userPersonalSpaceID = $this->featureContext->getPersonalSpaceIdForUser($user, true);
$fullUrl = $this->baseUrl . "/dav/spaces/" . $userPersonalSpaceID;
return \rtrim($fullUrl, '/') . '/' . \ltrim($fileDestination, '/');
}

/**
* COPY request for files|folders
*
* @param string $user
* @param string $fullUrl
* @param string $headers
*
* @return void
* @throws GuzzleException
*/
public function copyFilesAndFoldersRequest(string $user, string $fullUrl, array $headers):void {
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$fullUrl,
"",
'COPY',
$user,
$this->featureContext->getPasswordForUser($user),
$headers,
""
)
);
}

/**
* @Given /^user "([^"]*)" has uploaded a file inside space "([^"]*)" with content "([^"]*)" to "([^"]*)"$/
Expand Down

0 comments on commit 02c87cb

Please sign in to comment.