/*! * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ import type { User } from '@nextcloud/cypress' // @ts-expect-error package has wrong typings import { deleteDownloadsFolderBeforeEach } from 'cypress-delete-downloads-folder' import { deleteFileWithRequest, getRowForFileId, selectAllFiles, triggerActionForFileId } from '../files/FilesUtils.ts' describe('files_trashbin: download files', { testIsolation: true }, () => { let user: User const fileids: number[] = [] deleteDownloadsFolderBeforeEach() before(() => { cy.createRandomUser().then(($user) => { user = $user cy.uploadContent(user, new Blob(['']), 'text/plain', '/file.txt') .then(({ headers }) => fileids.push(Number.parseInt(headers['oc-fileid']))) .then(() => deleteFileWithRequest(user, '/file.txt')) cy.uploadContent(user, new Blob(['']), 'text/plain', '/other-file.txt') .then(({ headers }) => fileids.push(Number.parseInt(headers['oc-fileid']))) .then(() => deleteFileWithRequest(user, '/other-file.txt')) }) }) beforeEach(() => { cy.login(user) cy.visit('/apps/files/trashbin') }) it('can download file', () => { getRowForFileId(fileids[0]).should('be.visible') getRowForFileId(fileids[1]).should('be.visible') triggerActionForFileId(fileids[0], 'download') const downloadsFolder = Cypress.config('downloadsFolder') cy.readFile(`${downloadsFolder}/file.txt`, { timeout: 15000 }) .should('exist') .and('have.length.gt', 8) .and('equal', '') }) it('can download a file using default action', () => { getRowForFileId(fileids[0]) .should('be.visible') .findByRole('button', { name: 'Download' }) .click({ force: true }) const downloadsFolder = Cypress.config('downloadsFolder') cy.readFile(`${downloadsFolder}/file.txt`, { timeout: 15000 }) .should('exist') .and('have.length.gt', 8) .and('equal', '') }) // 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) it('does not offer bulk download', () => { cy.get('[data-cy-files-list-row-checkbox]').should('have.length', 2) selectAllFiles() cy.get('.files-list__selected').should('contain.text', '2 selected') cy.get('[data-cy-files-list-selection-action="restore"]').should('be.visible') cy.get('[data-cy-files-list-selection-action="download"]').should('not.exist') }) }) ption> Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
blob: 6671a78efff1464371e6d6d04dbf100814a76602 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php

/**
 * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OCA\Files_Sharing\Middleware;

use OCA\Files_Sharing\Controller\ShareAPIController;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\IL10N;
use OCP\Share\IManager;

class OCSShareAPIMiddleware extends Middleware {
	public function __construct(
		private IManager $shareManager,
		private IL10N $l,
	) {
	}

	/**
	 * @param Controller $controller
	 * @param string $methodName
	 *
	 * @throws OCSNotFoundException
	 */
	public function beforeController($controller, $methodName) {
		if ($controller instanceof ShareAPIController) {
			if (!$this->shareManager->shareApiEnabled()) {
				throw new OCSNotFoundException($this->l->t('Share API is disabled'));
			}
		}
	}

	/**
	 * @param Controller $controller
	 * @param string $methodName
	 * @param Response $response
	 * @return Response
	 */
	public function afterController($controller, $methodName, Response $response) {
		if ($controller instanceof ShareAPIController) {
			/** @var ShareAPIController $controller */
			$controller->cleanup();
		}

		return $response;
	}
}