fix: Check file existence before using save as#5372
fix: Check file existence before using save as#5372juliusknorr wants to merge 4 commits intomainfrom
Conversation
426f5e5 to
773389e
Compare
Signed-off-by: Julius Knorr <jus@bitgrid.net>
773389e to
8f54906
Compare
|
@juliusknorr the code looks good. I see there are some build and merge issues. Also, could you point me at something, or tell me how to test this? |
|
The failing test indeed seems related to the change as it is affecting the save as feature to save a document under a new name. However it seems to only occur in the "direct editing" mode. This direct editing mode is used by the Nextcloud mobile clients to open office for editing in a webview: To manually test this you can use the steps from #4739 (comment) Could you maybe take over and see if it is a valid failure and if so work on a fix? Ping me if you need more assistance for getting this up locally or running tests locally. |
Yep, I can take over, I will try getting it up locally alone first - sometimes mistakes are good :) |
|
So my first go once setup
curl --request POST \
--url 'http://nextcloud.local/ocs/v2.php/apps/richdocuments/api/v1/document?format=json' -u admin:admin \
--header 'Content-Type: multipart/form-data' \
--header 'OCS-Apirequest: true' \
--form fileId=[file id] |
|
import { getClient, getDefaultPropfind, resultToNode, defaultRootPath } from '@nextcloud/files/dav' defaultRootPath is used to lookup the file, however it is undefined |
function getRootPath() {
if (isPublicShare()) {
return `/files/${getSharingToken()}`;
}
return `/files/${getCurrentUser()?.uid}`;
}in Gives |
|
Problem: When opening a document via a direct editing link (e.g. from the OCS API /api/v1/document) in an unauthenticated session (such as an incognito window to simulate the way mobile works - I have not looked at mobile), the "Save As" functionality was producing an invalid DAV URL: Root cause: The defaultRootPath from @nextcloud/files/dav is evaluated once at module import time. It relies on getCurrentUser() from @nextcloud/auth, which reads data-user from the HTML element. In direct editing sessions (rendered as a @publicpage with the 'base' template), there is no authenticated browser session, so getCurrentUser() returns null and the path becomes /files/undefined. Changed
|
Signed-off-by: James Manuel <moodyjmz@users.noreply.github.com>
Signed-off-by: James Manuel <moodyjmz@users.noreply.github.com>
2baf239 to
e378915
Compare
|
I left this open as I made some changes now - I think they are aligned with the original intent though |
juliusknorr
left a comment
There was a problem hiding this comment.
Indeed I missed that we have no webdav access with direct editing. This is good enough for fixing the reported issue I#d say.
When using the "Save as" function you may end up saving files with the same name which did not lead to a expected copy then. This extends to check for existence before issuing the save as method with Collabora.
In the future a file picker could be used for the folder but we would need to extend that with a name input and further logic in the library so this is a smaller change that can be backported.