Skip to content

Commit 0efc694

Browse files
committed
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 <opensource@fthiessen.de>
1 parent 86f5fb0 commit 0efc694

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

apps/files/src/components/FileEntry/FileEntryName.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,13 @@ export default defineComponent({
299299
},
300300
})
301301
302+
if (oldName === this.source.attributes?.displayname) {
303+
// We have to assume that the displayname is not set but just the Nextcloud fallback to the basename
304+
// so we need to adjust this as well
305+
// eslint-disable-next-line vue/no-mutating-props
306+
this.source.attributes.displayname = this.source.basename
307+
}
308+
302309
// Success 🎉
303310
emit('files:node:updated', this.source)
304311
emit('files:node:renamed', this.source)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { getRowForFile, renameFile, triggerActionForFile } from './FilesUtils.ts'
7+
8+
/**
9+
* This is a regression test for https://github.com/nextcloud/server/issues/43331
10+
* Where files with XML entities in their names were wrongly displayed and could no longer be renamed / deleted etc.
11+
*/
12+
describe('Files: Can rename files', { testIsolation: false }, () => {
13+
before(() => {
14+
cy.createRandomUser().then((user) => {
15+
cy.uploadContent(user, new Blob(), 'text/plain', '/foo.txt')
16+
cy.login(user)
17+
cy.visit('/apps/files/')
18+
})
19+
})
20+
21+
it('See that the file is named correctly', () => {
22+
getRowForFile('foo.txt')
23+
.should('be.visible')
24+
.should('contain.text', 'foo.txt')
25+
})
26+
27+
it('Can rename the file', () => {
28+
cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('renameFile')
29+
30+
renameFile('foo.txt', 'bar.txt')
31+
cy.wait('@renameFile')
32+
33+
getRowForFile('bar.txt')
34+
.should('be.visible')
35+
})
36+
37+
it('See that the name is correctly shown', () => {
38+
getRowForFile('bar.txt')
39+
.should('be.visible')
40+
.should('contain.text', 'bar.txt')
41+
})
42+
43+
it('See that the name preserved on reload', () => {
44+
cy.reload()
45+
46+
getRowForFile('bar.txt')
47+
.should('be.visible')
48+
.should('contain.text', 'bar.txt')
49+
})
50+
})

0 commit comments

Comments
 (0)