mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #58467 from nextcloud/backport/56967/stable31
Some checks failed
Integration sqlite / changes (push) Has been cancelled
Psalm static code analysis / static-code-analysis (push) Has been cancelled
Psalm static code analysis / static-code-analysis-security (push) Has been cancelled
Psalm static code analysis / static-code-analysis-ocp (push) Has been cancelled
Psalm static code analysis / static-code-analysis-ncu (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, --tags ~@large files_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, capabilities_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, collaboration_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, comments_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, dav_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, federation_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, file_conversions) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, files_reminders) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, filesdrop_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, ldap_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, openldap_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, openldap_numerical_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, remoteapi_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, setup_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, sharees_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, sharing_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, theming_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, videoverification_features) (push) Has been cancelled
Integration sqlite / integration-sqlite-summary (push) Has been cancelled
Some checks failed
Integration sqlite / changes (push) Has been cancelled
Psalm static code analysis / static-code-analysis (push) Has been cancelled
Psalm static code analysis / static-code-analysis-security (push) Has been cancelled
Psalm static code analysis / static-code-analysis-ocp (push) Has been cancelled
Psalm static code analysis / static-code-analysis-ncu (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, --tags ~@large files_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, capabilities_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, collaboration_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, comments_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, dav_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, federation_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, file_conversions) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, files_reminders) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, filesdrop_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, ldap_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, openldap_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, openldap_numerical_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, remoteapi_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, setup_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, sharees_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, sharing_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, theming_features) (push) Has been cancelled
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, videoverification_features) (push) Has been cancelled
Integration sqlite / integration-sqlite-summary (push) Has been cancelled
[stable31] fix(files_sharing): make legacy `downloadShare` endpoint compatible with legacy behavior
This commit is contained in:
commit
4490c4eb42
2 changed files with 54 additions and 23 deletions
|
|
@ -13,6 +13,7 @@ use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
|
|||
use OCA\Files_Sharing\Event\ShareLinkAccessedEvent;
|
||||
use OCP\Accounts\IAccountManager;
|
||||
use OCP\AppFramework\AuthPublicShareController;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
|
||||
use OCP\AppFramework\Http\Attribute\OpenAPI;
|
||||
use OCP\AppFramework\Http\Attribute\PublicPage;
|
||||
|
|
@ -28,6 +29,7 @@ use OCP\Files\File;
|
|||
use OCP\Files\Folder;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\Files\NotPermittedException;
|
||||
use OCP\HintException;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
|
|
@ -359,49 +361,75 @@ class ShareController extends AuthPublicShareController {
|
|||
$share = $this->shareManager->getShareByToken($token);
|
||||
|
||||
if (!($share->getPermissions() & Constants::PERMISSION_READ)) {
|
||||
return new DataResponse('Share has no read permission');
|
||||
return new DataResponse('Share has no read permission', Http::STATUS_FORBIDDEN);
|
||||
}
|
||||
|
||||
$attributes = $share->getAttributes();
|
||||
if ($attributes?->getAttribute('permissions', 'download') === false) {
|
||||
return new DataResponse('Share has no download permission');
|
||||
return new DataResponse('Share has no download permission', Http::STATUS_FORBIDDEN);
|
||||
}
|
||||
|
||||
if (!$this->validateShare($share)) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
$node = $share->getNode();
|
||||
if ($node instanceof Folder) {
|
||||
// Directory share
|
||||
if ($share->getHideDownload()) {
|
||||
// download API does not work if hidden - use the DAV endpoint for previews
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
// Try to get the path
|
||||
if ($path !== '') {
|
||||
$node = $share->getNode();
|
||||
if ($path !== '') {
|
||||
if (!$node instanceof Folder) {
|
||||
return new NotFoundResponse();
|
||||
}
|
||||
|
||||
try {
|
||||
$node = $node->get($path);
|
||||
} catch (NotFoundException|NotPermittedException) {
|
||||
$this->emitAccessShareHook($share, 404, 'Share not found');
|
||||
$this->emitShareAccessEvent($share, self::SHARE_DOWNLOAD, 404, 'Share not found');
|
||||
return new NotFoundResponse();
|
||||
}
|
||||
}
|
||||
|
||||
if ($files !== null) {
|
||||
if (!$node instanceof Folder) {
|
||||
return new NotFoundResponse();
|
||||
}
|
||||
|
||||
$filesParam = json_decode($files, true);
|
||||
if (!is_array($filesParam)) {
|
||||
try {
|
||||
$node = $node->get($path);
|
||||
} catch (NotFoundException $e) {
|
||||
// legacy wise this allows also passing the filename
|
||||
$node = $node->get($files);
|
||||
$files = null;
|
||||
} catch (NotFoundException|NotPermittedException) {
|
||||
$this->emitAccessShareHook($share, 404, 'Share not found');
|
||||
$this->emitShareAccessEvent($share, self::SHARE_DOWNLOAD, 404, 'Share not found');
|
||||
return new NotFoundResponse();
|
||||
}
|
||||
}
|
||||
|
||||
if ($node instanceof Folder) {
|
||||
if ($files === null || $files === '') {
|
||||
if ($share->getHideDownload()) {
|
||||
throw new NotFoundException('Downloading a folder');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->emitAccessShareHook($share);
|
||||
$this->emitShareAccessEvent($share, self::SHARE_DOWNLOAD);
|
||||
|
||||
$davUrl = '/public.php/dav/files/' . $token . '/?accept=zip';
|
||||
if ($files !== null) {
|
||||
$davUrl .= '&files=' . $files;
|
||||
$davPath = '';
|
||||
if ($node !== $share->getNode()) {
|
||||
$davPath = substr($node->getPath(), strlen($share->getNode()->getPath()));
|
||||
}
|
||||
|
||||
$params = [];
|
||||
if ($files !== null) {
|
||||
$params['files'] = $files;
|
||||
}
|
||||
if ($node instanceof Folder) {
|
||||
$params['accept'] = 'zip';
|
||||
}
|
||||
|
||||
$davUrl = '/public.php/dav/files/' . $token . $davPath;
|
||||
$davUrl .= '?' . http_build_query($params);
|
||||
return new RedirectResponse($this->urlGenerator->getAbsoluteURL($davUrl));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use OCP\Accounts\IAccount;
|
|||
use OCP\Accounts\IAccountManager;
|
||||
use OCP\Accounts\IAccountProperty;
|
||||
use OCP\Activity\IManager;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Http\Template\ExternalShareMenuAction;
|
||||
|
|
@ -688,7 +689,9 @@ class ShareControllerTest extends \Test\TestCase {
|
|||
->with('token')
|
||||
->willReturn($share);
|
||||
|
||||
$this->userManager->method('get')->with('ownerUID')->willReturn($owner);
|
||||
$this->userManager->method('get')
|
||||
->with('ownerUID')
|
||||
->willReturn($owner);
|
||||
|
||||
$this->shareController->showShare();
|
||||
}
|
||||
|
|
@ -709,7 +712,7 @@ class ShareControllerTest extends \Test\TestCase {
|
|||
|
||||
// Test with a password protected share and no authentication
|
||||
$response = $this->shareController->downloadShare('validtoken');
|
||||
$expectedResponse = new DataResponse('Share has no read permission');
|
||||
$expectedResponse = new DataResponse('Share has no read permission', Http::STATUS_FORBIDDEN);
|
||||
$this->assertEquals($expectedResponse, $response);
|
||||
}
|
||||
|
||||
|
|
@ -737,7 +740,7 @@ class ShareControllerTest extends \Test\TestCase {
|
|||
|
||||
// Test with a password protected share and no authentication
|
||||
$response = $this->shareController->downloadShare('validtoken');
|
||||
$expectedResponse = new DataResponse('Share has no download permission');
|
||||
$expectedResponse = new DataResponse('Share has no download permission', Http::STATUS_FORBIDDEN);
|
||||
$this->assertEquals($expectedResponse, $response);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue