fix: Replace the deprecated direct download link with the public DAV endpoint

Follow-up of #48098

Signed-off-by: Louis Chemineau <louis@chmn.me>
pull/52810/head
Louis Chemineau 2025-05-21 16:01:54 +07:00
parent 009d0c550c
commit ec1db0c32a
No known key found for this signature in database
3 changed files with 15 additions and 10 deletions

@ -149,10 +149,7 @@ class DefaultPublicShareTemplateProvider implements IPublicShareTemplateProvider
$headerActions = []; $headerActions = [];
if ($view !== 'public-file-drop' && !$share->getHideDownload()) { if ($view !== 'public-file-drop' && !$share->getHideDownload()) {
// The download URL is used for the "download" header action as well as in some cases for the direct link // The download URL is used for the "download" header action as well as in some cases for the direct link
$downloadUrl = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', [ $downloadUrl = $this->urlGenerator->getAbsoluteURL('/public.php/dav/files/' . $token . '/?accept=zip');
'token' => $token,
'filename' => ($shareNode instanceof File) ? $shareNode->getName() : null,
]);
// If not a file drop, then add the download header action // If not a file drop, then add the download header action
$headerActions[] = new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', $downloadUrl, 0, (string)$shareNode->getSize()); $headerActions[] = new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', $downloadUrl, 0, (string)$shareNode->getSize());

@ -261,8 +261,12 @@ class ShareControllerTest extends \Test\TestCase {
['files_sharing.sharecontroller.showShare', ['token' => 'token'], 'shareUrl'], ['files_sharing.sharecontroller.showShare', ['token' => 'token'], 'shareUrl'],
// this share is not an image to the default preview is used // this share is not an image to the default preview is used
['files_sharing.PublicPreview.getPreview', ['x' => 256, 'y' => 256, 'file' => $share->getTarget(), 'token' => 'token'], 'previewUrl'], ['files_sharing.PublicPreview.getPreview', ['x' => 256, 'y' => 256, 'file' => $share->getTarget(), 'token' => 'token'], 'previewUrl'],
// for the direct link ]);
['files_sharing.sharecontroller.downloadShare', ['token' => 'token', 'filename' => $filename ], 'downloadUrl'],
$this->urlGenerator->expects($this->once())
->method('getAbsoluteURL')
->willReturnMap([
['/public.php/dav/files/token/?accept=zip', 'downloadUrl'],
]); ]);
$this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true); $this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
@ -552,8 +556,12 @@ class ShareControllerTest extends \Test\TestCase {
['files_sharing.sharecontroller.showShare', ['token' => 'token'], 'shareUrl'], ['files_sharing.sharecontroller.showShare', ['token' => 'token'], 'shareUrl'],
// this share is not an image to the default preview is used // this share is not an image to the default preview is used
['files_sharing.PublicPreview.getPreview', ['x' => 256, 'y' => 256, 'file' => $share->getTarget(), 'token' => 'token'], 'previewUrl'], ['files_sharing.PublicPreview.getPreview', ['x' => 256, 'y' => 256, 'file' => $share->getTarget(), 'token' => 'token'], 'previewUrl'],
// for the direct link ]);
['files_sharing.sharecontroller.downloadShare', ['token' => 'token', 'filename' => $filename ], 'downloadUrl'],
$this->urlGenerator->expects($this->once())
->method('getAbsoluteURL')
->willReturnMap([
['/public.php/dav/files/token/?accept=zip', 'downloadUrl'],
]); ]);
$this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true); $this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);

@ -53,7 +53,7 @@ describe('files_sharing: Public share - header actions menu', { testIsolation: t
cy.findByRole('menuitem', { name: 'Direct link' }) cy.findByRole('menuitem', { name: 'Direct link' })
.should('be.visible') .should('be.visible')
.and('have.attr', 'href') .and('have.attr', 'href')
.then((attribute) => expect(attribute).to.match(/^http:\/\/.+\/download$/)) .then((attribute) => expect(attribute).to.match(new RegExp(`^${Cypress.env('baseUrl')}/public.php/dav/files/.+/?accept=zip$`)))
// see menu closes on click // see menu closes on click
cy.findByRole('menuitem', { name: 'Direct link' }) cy.findByRole('menuitem', { name: 'Direct link' })
.click() .click()
@ -188,7 +188,7 @@ describe('files_sharing: Public share - header actions menu', { testIsolation: t
cy.findByRole('menuitem', { name: 'Direct link' }) cy.findByRole('menuitem', { name: 'Direct link' })
.should('be.visible') .should('be.visible')
.and('have.attr', 'href') .and('have.attr', 'href')
.then((attribute) => expect(attribute).to.match(/^http:\/\/.+\/download$/)) .then((attribute) => expect(attribute).to.match(new RegExp(`^${Cypress.env('baseUrl')}/public.php/dav/files/.+/?accept=zip$`)))
// See remote share works // See remote share works
cy.findByRole('menuitem', { name: /Add to your/i }) cy.findByRole('menuitem', { name: /Add to your/i })
.should('be.visible') .should('be.visible')