]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(files): Update displayname on rename fix/files-renaming 46474/head
authorFerdinand Thiessen <opensource@fthiessen.de>
Fri, 12 Jul 2024 17:28:50 +0000 (19:28 +0200)
committerFerdinand Thiessen <opensource@fthiessen.de>
Mon, 15 Jul 2024 08:57:56 +0000 (10:57 +0200)
Nextcloud always sets the `displayname` attribute, with fallback to the basename.
So if we move or rename a file the old displayname will still be used as we only update the basename but not the displayname.
Safest would be refetch, but if displayname and basename is equal we can safe one request and set the displayname to the new basename.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
apps/files/src/components/FileEntry/FileEntryName.vue
cypress/e2e/files/files-rename.cy.ts [new file with mode: 0644]

index 4e5a3571e74ba98fef3181643d0d2160053736cc..267963a5f538aefa38c08e79fb9da07e6e329044 100644 (file)
@@ -299,6 +299,13 @@ export default defineComponent({
                                        },
                                })
 
+                               if (oldName === this.source.attributes?.displayname) {
+                                       // We have to assume that the displayname is not set but just the Nextcloud fallback to the basename
+                                       // so we need to adjust this as well
+                                       // eslint-disable-next-line vue/no-mutating-props
+                                       this.source.attributes.displayname = this.source.basename
+                               }
+
                                // Success ðŸŽ‰
                                emit('files:node:updated', this.source)
                                emit('files:node:renamed', this.source)
diff --git a/cypress/e2e/files/files-rename.cy.ts b/cypress/e2e/files/files-rename.cy.ts
new file mode 100644 (file)
index 0000000..2c846c5
--- /dev/null
@@ -0,0 +1,46 @@
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import { getRowForFile, renameFile } from './FilesUtils.ts'
+
+describe('Files: Can rename files', { testIsolation: false }, () => {
+       before(() => {
+               cy.createRandomUser().then((user) => {
+                       cy.uploadContent(user, new Blob(), 'text/plain', '/foo.txt')
+                       cy.login(user)
+                       cy.visit('/apps/files/')
+               })
+       })
+
+       it('See that the file is named correctly', () => {
+               getRowForFile('foo.txt')
+                       .should('be.visible')
+                       .should('contain.text', 'foo.txt')
+       })
+
+       it('Can rename the file', () => {
+               cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('renameFile')
+
+               renameFile('foo.txt', 'bar.txt')
+               cy.wait('@renameFile')
+
+               getRowForFile('bar.txt')
+                       .should('be.visible')
+       })
+
+       it('See that the name is correctly shown', () => {
+               getRowForFile('bar.txt')
+                       .should('be.visible')
+                       .should('contain.text', 'bar.txt')
+       })
+
+       it('See that the name preserved on reload', () => {
+               cy.reload()
+
+               getRowForFile('bar.txt')
+                       .should('be.visible')
+                       .should('contain.text', 'bar.txt')
+       })
+})