Skip to content

Commit 8b36b91

Browse files
committed
fix(files_trashbin): disable bulk download for trashbin
The backend does not allow bulk download within the trashbin, so we need to disable this also on the frontend. Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 8213252 commit 8b36b91

File tree

3 files changed

+85
-5
lines changed

3 files changed

+85
-5
lines changed

apps/files/src/actions/downloadAction.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5-
import { FileAction, Node, FileType, DefaultType } from '@nextcloud/files'
5+
import type { Node, View } from '@nextcloud/files'
6+
import { FileAction, FileType, DefaultType } from '@nextcloud/files'
67
import { t } from '@nextcloud/l10n'
78
import { isDownloadable } from '../utils/permissions'
89

@@ -75,7 +76,7 @@ export const action = new FileAction({
7576
displayName: () => t('files', 'Download'),
7677
iconSvgInline: () => ArrowDownSvg,
7778

78-
enabled(nodes: Node[]) {
79+
enabled(nodes: Node[], view: View) {
7980
if (nodes.length === 0) {
8081
return false
8182
}
@@ -85,6 +86,11 @@ export const action = new FileAction({
8586
return false
8687
}
8788

89+
// Trashbin does not allow batch download
90+
if (nodes.length > 1 && view.id === 'trashbin') {
91+
return false
92+
}
93+
8894
return nodes.every(isDownloadable)
8995
},
9096

cypress/e2e/files/FilesUtils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import type { User } from '@nextcloud/cypress'
7-
import { ACTION_COPY_MOVE } from "../../../apps/files/src/actions/moveOrCopyAction"
7+
import { ACTION_COPY_MOVE } from '../../../apps/files/src/actions/moveOrCopyAction.ts'
88

99
export const getRowForFileId = (fileid: number) => cy.get(`[data-cy-files-list-row-fileid="${fileid}"]`)
1010
export const getRowForFile = (filename: string) => cy.get(`[data-cy-files-list-row-name="${CSS.escape(filename)}"]`)
@@ -15,7 +15,7 @@ export const getActionsForFile = (filename: string) => getRowForFile(filename).f
1515
export const getActionButtonForFileId = (fileid: number) => getActionsForFileId(fileid).findByRole('button', { name: 'Actions' })
1616
export const getActionButtonForFile = (filename: string) => getActionsForFile(filename).findByRole('button', { name: 'Actions' })
1717

18-
const searchForActionInRow = (row: JQuery<HTMLElement>, actionId: string): Cypress.Chainable<JQuery<HTMLElement>> => {
18+
const searchForActionInRow = (row: JQuery<HTMLElement>, actionId: string): Cypress.Chainable<JQuery<HTMLElement>> => {
1919
const action = row.find(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`)
2020
if (action.length > 0) {
2121
cy.log('Found action in row')
@@ -229,7 +229,11 @@ export const deleteFileWithRequest = (user: User, path: string) => {
229229
const requestToken = body.token
230230
cy.request({
231231
method: 'DELETE',
232-
url: `${Cypress.env('baseUrl')}/remote.php/dav/files/${user.userId}` + path,
232+
url: `${Cypress.env('baseUrl')}/remote.php/dav/files/${user.userId}${path}`,
233+
auth: {
234+
user: user.userId,
235+
password: user.password,
236+
},
233237
headers: {
234238
requestToken,
235239
},
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*!
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import type { User } from '@nextcloud/cypress'
7+
8+
// @ts-expect-error package has wrong typings
9+
import { deleteDownloadsFolderBeforeEach } from 'cypress-delete-downloads-folder'
10+
import { deleteFileWithRequest, getRowForFileId, selectAllFiles, triggerActionForFileId } from '../files/FilesUtils.ts'
11+
12+
describe('files_trashbin: download files', { testIsolation: true }, () => {
13+
let user: User
14+
const fileids: number[] = []
15+
16+
deleteDownloadsFolderBeforeEach()
17+
18+
before(() => {
19+
cy.createRandomUser().then(($user) => {
20+
user = $user
21+
22+
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/file.txt')
23+
.then(({ headers }) => fileids.push(Number.parseInt(headers['oc-fileid'])))
24+
.then(() => deleteFileWithRequest(user, '/file.txt'))
25+
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/other-file.txt')
26+
.then(({ headers }) => fileids.push(Number.parseInt(headers['oc-fileid'])))
27+
.then(() => deleteFileWithRequest(user, '/other-file.txt'))
28+
})
29+
})
30+
31+
beforeEach(() => {
32+
cy.login(user)
33+
cy.visit('/apps/files/trashbin')
34+
})
35+
36+
it('can download file', () => {
37+
getRowForFileId(fileids[0]).should('be.visible')
38+
getRowForFileId(fileids[1]).should('be.visible')
39+
40+
triggerActionForFileId(fileids[0], 'download')
41+
42+
const downloadsFolder = Cypress.config('downloadsFolder')
43+
cy.readFile(`${downloadsFolder}/file.txt`, { timeout: 15000 })
44+
.should('exist')
45+
.and('have.length.gt', 8)
46+
.and('equal', '<content>')
47+
})
48+
49+
it('can download a file using default action', () => {
50+
getRowForFileId(fileids[0])
51+
.should('be.visible')
52+
.findByRole('button', { name: 'Download' })
53+
.click({ force: true })
54+
55+
const downloadsFolder = Cypress.config('downloadsFolder')
56+
cy.readFile(`${downloadsFolder}/file.txt`, { timeout: 15000 })
57+
.should('exist')
58+
.and('have.length.gt', 8)
59+
.and('equal', '<content>')
60+
})
61+
62+
// TODO: Fix this as this dependens on the webdav zip folder plugin not working for trashbin (and never worked with old NC legacy download ajax as well)
63+
it('does not offer bulk download', () => {
64+
cy.get('[data-cy-files-list-row-checkbox]').should('have.length', 2)
65+
selectAllFiles()
66+
cy.get('.files-list__selected').should('have.text', '2 selected')
67+
cy.get('[data-cy-files-list-selection-action="restore"]').should('be.visible')
68+
cy.get('[data-cy-files-list-selection-action="download"]').should('not.exist')
69+
})
70+
})

0 commit comments

Comments
 (0)