Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sharing): use correct save path when renaming #4378

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/Controller/WopiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,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
Loading