Skip to content

Commit e27501d

Browse files
authored
Merge pull request #4378 from nextcloud/fix/4370
fix(sharing): use correct save path when renaming
2 parents b612d2d + a7892ca commit e27501d

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

lib/Controller/WopiController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,7 @@ public function postFile(string $fileId, string $access_token): JSONResponse {
571571
$suggested = $this->request->getHeader('X-WOPI-RequestedName');
572572
$suggested = mb_convert_encoding($suggested, 'utf-8', 'utf-7') . '.' . $file->getExtension();
573573

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

577576
if ($path === '') {
578577
return new JSONResponse([

tests/features/bootstrap/RichDocumentsContext.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,17 @@ public function updateTheGuestDisplayName($displayName) {
235235
'guestName' => $displayName,
236236
], [ 'auth' => null ]);
237237
}
238+
239+
/**
240+
* @Given /^as "([^"]*)" rename "([^"]*)" to "([^"]*)"$/
241+
*/
242+
public function renameFileTo($user, $file, $newName) {
243+
$this->serverContext->usingWebAsUser($user);
244+
$davClient = $this->filesContext->getSabreClient($user);
245+
$path = $this->filesContext->makeSabrePath($user, $file);
246+
$result = $davClient->propFind($path, ['{http://owncloud.org/ns}fileid']);
247+
$fileId = $result['{http://owncloud.org/ns}fileid'];
248+
249+
$this->wopiContext->collaboraRenamesTo($fileId, $newName);
250+
}
238251
}

tests/features/bootstrap/WopiContext.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,21 @@ public function collaboraSavesTheFileAs($source, $newName) {
298298
$this->response = $e->getResponse();
299299
}
300300
}
301+
302+
public function collaboraRenamesTo($fileId, $newName) {
303+
$client = new Client();
304+
$options = [
305+
'headers' => [
306+
'X-LOOL-WOPI-Timestamp' => $this->checkFileInfoResult['LastModifiedTime'],
307+
'X-WOPI-RequestedName' => $newName,
308+
'X-WOPI-Override' => 'RENAME_FILE',
309+
],
310+
];
311+
312+
try {
313+
$this->response = $client->post($this->getWopiEndpointBaseUrl() . 'index.php/apps/richdocuments/wopi/files/' . $fileId . '?access_token=' . $this->wopiToken, $options);
314+
} catch (\GuzzleHttp\Exception\ClientException $e) {
315+
$this->response = $e->getResponse();
316+
}
317+
}
301318
}

tests/features/wopi.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,21 @@ Feature: WOPI
358358
And Collabora saves the content of "./../emptyTemplates/template.ods" as "/saved-as-guest-document.odt"
359359
And as "user1" the file "/SharedFolder/saved-as-guest-document.odt" exists
360360
And as "user1" the file "/saved-as-guest-document.odt" does not exist
361+
362+
Scenario: Rename file on share link
363+
Given as user "user1"
364+
365+
And User "user1" creates a folder "/SharedFolder"
366+
And User "user1" uploads file "./../emptyTemplates/template.odt" to "/SharedFolder/file.odt"
367+
And as "user1" create a share with
368+
| path | /SharedFolder |
369+
| shareType | 3 |
370+
And Updating last share with
371+
| permissions | 31 |
372+
And User "user1" opens the file "file.odt" of the shared link
373+
And Collabora fetches checkFileInfo
374+
375+
And as "user1" rename "/SharedFolder/file.odt" to "renamed_file"
376+
And as "user1" the file "/SharedFolder/renamed_file.odt" exists
377+
And as "user1" the file "/SharedFolder/file.odt" does not exist
378+
And as "user1" the file "/renamed_file.odt" does not exist

0 commit comments

Comments
 (0)