Skip to content

Commit

Permalink
Merge pull request #46918 from nextcloud/fix/recent-view
Browse files Browse the repository at this point in the history
fix(files): Correctly create Nodes from WebDAV result in "recent"-view
  • Loading branch information
AndyScherzinger authored Aug 1, 2024
2 parents 014fcb0 + 6aaea2a commit 39272bf
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 19 deletions.
13 changes: 3 additions & 10 deletions apps/files/src/services/Files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,19 @@
* 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'

/**
* 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()
Expand Down
14 changes: 11 additions & 3 deletions apps/files/src/services/Recent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
44 changes: 44 additions & 0 deletions cypress/e2e/files/recent-view.cy.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 2 deletions dist/files-init.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-init.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

0 comments on commit 39272bf

Please sign in to comment.