From: Ferdinand Thiessen Date: Fri, 12 Jul 2024 17:28:50 +0000 (+0200) Subject: fix(files): Update displayname on rename X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=374e6e94ac68149fc8597f9c48131666fd1ee356;p=nextcloud-server.git fix(files): Update displayname on rename 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 --- diff --git a/apps/files/src/components/FileEntry/FileEntryName.vue b/apps/files/src/components/FileEntry/FileEntryName.vue index 4e5a3571e74..267963a5f53 100644 --- a/apps/files/src/components/FileEntry/FileEntryName.vue +++ b/apps/files/src/components/FileEntry/FileEntryName.vue @@ -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 index 00000000000..2c846c588bc --- /dev/null +++ b/cypress/e2e/files/files-rename.cy.ts @@ -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') + }) +})