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 15, 2024
1 parent b05e963 commit 374e6e9
Show file tree
Hide file tree
Showing 2 changed files with 53 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
46 changes: 46 additions & 0 deletions cypress/e2e/files/files-rename.cy.ts
Original file line number Diff line number Diff line change
@@ -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')
})
})

0 comments on commit 374e6e9

Please sign in to comment.