Merge pull request #46918 from nextcloud/fix/recent-view

fix(files): Correctly create Nodes from WebDAV result in "recent"-view
This commit is contained in:
Andy Scherzinger 2024-08-01 15:12:16 +02:00 committed by GitHub
commit 39272bf458
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 64 additions and 19 deletions

View file

@ -2,11 +2,11 @@
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { ContentsWithRoot } from '@nextcloud/files'
import type { ContentsWithRoot, File, Folder } from '@nextcloud/files'
import type { FileStat, ResponseDataDetailed } from 'webdav'
import { CancelablePromise } from 'cancelable-promise'
import { File, Folder, davGetDefaultPropfind, davResultToNode, davRootPath } from '@nextcloud/files'
import { davGetDefaultPropfind, davResultToNode, davRootPath } from '@nextcloud/files'
import { client } from './WebdavClient.ts'
import logger from '../logger.ts'
@ -14,14 +14,7 @@ import logger from '../logger.ts'
* Slim wrapper over `@nextcloud/files` `davResultToNode` to allow using the function with `Array.map`
* @param node The node returned by the webdav library
*/
export const resultToNode = (node: FileStat): File | Folder => {
// TODO remove this hack with nextcloud-files v3.7
// just needed because of a bug in the webdav client
if (node.props?.displayname !== undefined) {
node.props.displayname = String(node.props.displayname)
}
return davResultToNode(node)
}
export const resultToNode = (node: FileStat): File | Folder => davResultToNode(node)
export const getContents = (path = '/'): CancelablePromise<ContentsWithRoot> => {
const controller = new AbortController()

View file

@ -3,18 +3,26 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { ContentsWithRoot, Node } from '@nextcloud/files'
import type { ResponseDataDetailed, SearchResult } from 'webdav'
import type { FileStat, ResponseDataDetailed, SearchResult } from 'webdav'
import { getCurrentUser } from '@nextcloud/auth'
import { Folder, Permission, davGetRecentSearch, davRootPath, davRemoteURL } from '@nextcloud/files'
import { Folder, Permission, davGetRecentSearch, davRootPath, davRemoteURL, davResultToNode } from '@nextcloud/files'
import { CancelablePromise } from 'cancelable-promise'
import { useUserConfigStore } from '../store/userconfig.ts'
import { pinia } from '../store/index.ts'
import { client } from './WebdavClient.ts'
import { resultToNode } from './Files.ts'
import { getBaseUrl } from '@nextcloud/router'
const lastTwoWeeksTimestamp = Math.round((Date.now() / 1000) - (60 * 60 * 24 * 14))
/**
* Helper to map a WebDAV result to a Nextcloud node
* The search endpoint already includes the dav remote URL so we must not include it in the source
*
* @param stat the WebDAV result
*/
const resultToNode = (stat: FileStat) => davResultToNode(stat, davRootPath, getBaseUrl())
/**
* Get recently changed nodes
*

View file

@ -0,0 +1,44 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { User } from '@nextcloud/cypress'
import { getRowForFile, triggerActionForFile } from './FilesUtils'
describe('files: Recent view', { testIsolation: true }, () => {
let user: User
beforeEach(() => cy.createRandomUser().then(($user) => {
user = $user
cy.uploadContent(user, new Blob([]), 'text/plain', '/file.txt')
cy.login(user)
}))
it('see the recently created file in the recent view', () => {
cy.visit('/apps/files/recent')
// All are visible by default
getRowForFile('file.txt').should('be.visible')
})
/**
* Regression test: There was a bug that the files were correctly loaded but with invalid source
* so the delete action failed.
*/
it('can delete a file in the recent view', () => {
cy.intercept('DELETE', '**/remote.php/dav/files/**').as('deleteFile')
cy.visit('/apps/files/recent')
// See the row
getRowForFile('file.txt').should('be.visible')
// delete the file
triggerActionForFile('file.txt', 'delete')
cy.wait('@deleteFile')
// See it is not visible anymore
getRowForFile('file.txt').should('not.exist')
// also not existing in default view after reload
cy.visit('/apps/files')
getRowForFile('file.txt').should('not.exist')
})
})

4
dist/files-init.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
dist/files-main.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long