Skip to content

Commit cfa99ed

Browse files
authored
Merge pull request #4519 from nextcloud/backport/4378/stable29
[stable29] fix(sharing): use correct save path when renaming
2 parents c96f03e + dd17831 commit cfa99ed

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
@@ -606,8 +606,7 @@ public function postFile(string $fileId, string $access_token): JSONResponse {
606606
$suggested = $this->request->getHeader('X-WOPI-RequestedName');
607607
$suggested = mb_convert_encoding($suggested, 'utf-8', 'utf-7') . '.' . $file->getExtension();
608608

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

612611
if ($path === '') {
613612
return new JSONResponse([

tests/features/bootstrap/RichDocumentsContext.php

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

tests/features/bootstrap/WopiContext.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,21 @@ public function collaboraSavesTheFileAs($source, $newName) {
316316
$this->response = $e->getResponse();
317317
}
318318
}
319+
320+
public function collaboraRenamesTo($fileId, $newName) {
321+
$client = new Client();
322+
$options = [
323+
'headers' => [
324+
'X-LOOL-WOPI-Timestamp' => $this->checkFileInfoResult['LastModifiedTime'],
325+
'X-WOPI-RequestedName' => $newName,
326+
'X-WOPI-Override' => 'RENAME_FILE',
327+
],
328+
];
329+
330+
try {
331+
$this->response = $client->post($this->getWopiEndpointBaseUrl() . 'index.php/apps/richdocuments/wopi/files/' . $fileId . '?access_token=' . $this->wopiToken, $options);
332+
} catch (\GuzzleHttp\Exception\ClientException $e) {
333+
$this->response = $e->getResponse();
334+
}
335+
}
319336
}

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)