Skip to content

Commit

Permalink
fix(files): Update displayname on rename
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
susnux committed Jul 12, 2024
1 parent 86f5fb0 commit 0efc694
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apps/files/src/components/FileEntry/FileEntryName.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
50 changes: 50 additions & 0 deletions cypress/e2e/files/files-rename.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { getRowForFile, renameFile, triggerActionForFile } from './FilesUtils.ts'

/**
* This is a regression test for https://github.com/nextcloud/server/issues/43331
* Where files with XML entities in their names were wrongly displayed and could no longer be renamed / deleted etc.
*/
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')
})
})

0 comments on commit 0efc694

Please sign in to comment.