Skip to content

Commit

Permalink
fix(sharing): use correct save path when renaming
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <[email protected]>
  • Loading branch information
elzody authored and backportbot[bot] committed Jan 9, 2025
1 parent 674f5ab commit 7931917
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/Controller/WopiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,7 @@ public function postFile(string $fileId, string $access_token): JSONResponse {
$suggested = $this->request->getHeader('X-WOPI-RequestedName');
$suggested = mb_convert_encoding($suggested, 'utf-8', 'utf-7') . '.' . $file->getExtension();

$parent = $isPublic ? dirname($file->getPath()) : $userFolder->getPath();
$path = $this->normalizePath($suggested, $parent);
$path = $this->normalizePath($suggested, dirname($file->getPath()));

if ($path === '') {
return new JSONResponse([
Expand Down
13 changes: 13 additions & 0 deletions tests/features/bootstrap/RichDocumentsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,17 @@ public function updateTheGuestDisplayName($displayName) {
'guestName' => $displayName,
], [ 'auth' => null ]);
}

/**
* @Given /^as "([^"]*)" rename "([^"]*)" to "([^"]*)"$/
*/
public function renameFileTo($user, $file, $newName) {
$this->serverContext->usingWebAsUser($user);
$davClient = $this->filesContext->getSabreClient($user);
$path = $this->filesContext->makeSabrePath($user, $file);
$result = $davClient->propFind($path, ['{http://owncloud.org/ns}fileid']);
$fileId = $result['{http://owncloud.org/ns}fileid'];

$this->wopiContext->collaboraRenamesTo($fileId, $newName);
}
}
17 changes: 17 additions & 0 deletions tests/features/bootstrap/WopiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,21 @@ public function collaboraSavesTheFileAs($source, $newName) {
$this->response = $e->getResponse();
}
}

public function collaboraRenamesTo($fileId, $newName) {
$client = new Client();
$options = [
'headers' => [
'X-LOOL-WOPI-Timestamp' => $this->checkFileInfoResult['LastModifiedTime'],
'X-WOPI-RequestedName' => $newName,
'X-WOPI-Override' => 'RENAME_FILE',
],
];

try {
$this->response = $client->post($this->getWopiEndpointBaseUrl() . 'index.php/apps/richdocuments/wopi/files/' . $fileId . '?access_token=' . $this->wopiToken, $options);
} catch (\GuzzleHttp\Exception\ClientException $e) {
$this->response = $e->getResponse();
}
}
}
18 changes: 18 additions & 0 deletions tests/features/wopi.feature
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,21 @@ Feature: WOPI
And Collabora saves the content of "./../emptyTemplates/template.ods" as "/saved-as-guest-document.odt"
And as "user1" the file "/SharedFolder/saved-as-guest-document.odt" exists
And as "user1" the file "/saved-as-guest-document.odt" does not exist

Scenario: Rename file on share link
Given as user "user1"

And User "user1" creates a folder "/SharedFolder"
And User "user1" uploads file "./../emptyTemplates/template.odt" to "/SharedFolder/file.odt"
And as "user1" create a share with
| path | /SharedFolder |
| shareType | 3 |
And Updating last share with
| permissions | 31 |
And User "user1" opens the file "file.odt" of the shared link
And Collabora fetches checkFileInfo

And as "user1" rename "/SharedFolder/file.odt" to "renamed_file"
And as "user1" the file "/SharedFolder/renamed_file.odt" exists
And as "user1" the file "/SharedFolder/file.odt" does not exist
And as "user1" the file "/renamed_file.odt" does not exist

0 comments on commit 7931917

Please sign in to comment.