diff --git a/lib/Controller/WopiController.php b/lib/Controller/WopiController.php index 256057cace..eb7d16b09e 100644 --- a/lib/Controller/WopiController.php +++ b/lib/Controller/WopiController.php @@ -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([ diff --git a/tests/features/bootstrap/RichDocumentsContext.php b/tests/features/bootstrap/RichDocumentsContext.php index 786e5b3669..cd78443ec5 100644 --- a/tests/features/bootstrap/RichDocumentsContext.php +++ b/tests/features/bootstrap/RichDocumentsContext.php @@ -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); + } } diff --git a/tests/features/bootstrap/WopiContext.php b/tests/features/bootstrap/WopiContext.php index 9b5a2f3a1e..724f198e3e 100644 --- a/tests/features/bootstrap/WopiContext.php +++ b/tests/features/bootstrap/WopiContext.php @@ -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(); + } + } } diff --git a/tests/features/wopi.feature b/tests/features/wopi.feature index 522e1d2fd7..be7ebcb894 100644 --- a/tests/features/wopi.feature +++ b/tests/features/wopi.feature @@ -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 \ No newline at end of file