Skip to content

Commit 39272bf

Browse files
Merge pull request #46918 from nextcloud/fix/recent-view
fix(files): Correctly create Nodes from WebDAV result in "recent"-view
2 parents 014fcb0 + 6aaea2a commit 39272bf

7 files changed

Lines changed: 64 additions & 19 deletions

File tree

apps/files/src/services/Files.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,19 @@
22
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5-
import type { ContentsWithRoot } from '@nextcloud/files'
5+
import type { ContentsWithRoot, File, Folder } from '@nextcloud/files'
66
import type { FileStat, ResponseDataDetailed } from 'webdav'
77

88
import { CancelablePromise } from 'cancelable-promise'
9-
import { File, Folder, davGetDefaultPropfind, davResultToNode, davRootPath } from '@nextcloud/files'
9+
import { davGetDefaultPropfind, davResultToNode, davRootPath } from '@nextcloud/files'
1010
import { client } from './WebdavClient.ts'
1111
import logger from '../logger.ts'
1212

1313
/**
1414
* Slim wrapper over `@nextcloud/files` `davResultToNode` to allow using the function with `Array.map`
1515
* @param node The node returned by the webdav library
1616
*/
17-
export const resultToNode = (node: FileStat): File | Folder => {
18-
// TODO remove this hack with nextcloud-files v3.7
19-
// just needed because of a bug in the webdav client
20-
if (node.props?.displayname !== undefined) {
21-
node.props.displayname = String(node.props.displayname)
22-
}
23-
return davResultToNode(node)
24-
}
17+
export const resultToNode = (node: FileStat): File | Folder => davResultToNode(node)
2518

2619
export const getContents = (path = '/'): CancelablePromise<ContentsWithRoot> => {
2720
const controller = new AbortController()

apps/files/src/services/Recent.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,26 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55
import type { ContentsWithRoot, Node } from '@nextcloud/files'
6-
import type { ResponseDataDetailed, SearchResult } from 'webdav'
6+
import type { FileStat, ResponseDataDetailed, SearchResult } from 'webdav'
77

88
import { getCurrentUser } from '@nextcloud/auth'
9-
import { Folder, Permission, davGetRecentSearch, davRootPath, davRemoteURL } from '@nextcloud/files'
9+
import { Folder, Permission, davGetRecentSearch, davRootPath, davRemoteURL, davResultToNode } from '@nextcloud/files'
1010
import { CancelablePromise } from 'cancelable-promise'
1111
import { useUserConfigStore } from '../store/userconfig.ts'
1212
import { pinia } from '../store/index.ts'
1313
import { client } from './WebdavClient.ts'
14-
import { resultToNode } from './Files.ts'
14+
import { getBaseUrl } from '@nextcloud/router'
1515

1616
const lastTwoWeeksTimestamp = Math.round((Date.now() / 1000) - (60 * 60 * 24 * 14))
1717

18+
/**
19+
* Helper to map a WebDAV result to a Nextcloud node
20+
* The search endpoint already includes the dav remote URL so we must not include it in the source
21+
*
22+
* @param stat the WebDAV result
23+
*/
24+
const resultToNode = (stat: FileStat) => davResultToNode(stat, davRootPath, getBaseUrl())
25+
1826
/**
1927
* Get recently changed nodes
2028
*
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import type { User } from '@nextcloud/cypress'
7+
import { getRowForFile, triggerActionForFile } from './FilesUtils'
8+
9+
describe('files: Recent view', { testIsolation: true }, () => {
10+
let user: User
11+
12+
beforeEach(() => cy.createRandomUser().then(($user) => {
13+
user = $user
14+
15+
cy.uploadContent(user, new Blob([]), 'text/plain', '/file.txt')
16+
cy.login(user)
17+
}))
18+
19+
it('see the recently created file in the recent view', () => {
20+
cy.visit('/apps/files/recent')
21+
// All are visible by default
22+
getRowForFile('file.txt').should('be.visible')
23+
})
24+
25+
/**
26+
* Regression test: There was a bug that the files were correctly loaded but with invalid source
27+
* so the delete action failed.
28+
*/
29+
it('can delete a file in the recent view', () => {
30+
cy.intercept('DELETE', '**/remote.php/dav/files/**').as('deleteFile')
31+
32+
cy.visit('/apps/files/recent')
33+
// See the row
34+
getRowForFile('file.txt').should('be.visible')
35+
// delete the file
36+
triggerActionForFile('file.txt', 'delete')
37+
cy.wait('@deleteFile')
38+
// See it is not visible anymore
39+
getRowForFile('file.txt').should('not.exist')
40+
// also not existing in default view after reload
41+
cy.visit('/apps/files')
42+
getRowForFile('file.txt').should('not.exist')
43+
})
44+
})

dist/files-init.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-init.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)