Skip to content

Commit 617af2f

Browse files
artongebackportbot[bot]
authored andcommitted
fix: Replace the deprecated direct download link with the public DAV endpoint
Follow-up of #48098 Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent 7a02618 commit 617af2f

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

apps/files_sharing/lib/DefaultPublicShareTemplateProvider.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,7 @@ public function renderPage(IShare $share, string $token, string $path): Template
150150
$headerActions = [];
151151
if ($view !== 'public-file-drop' && !$share->getHideDownload()) {
152152
// The download URL is used for the "download" header action as well as in some cases for the direct link
153-
$downloadUrl = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', [
154-
'token' => $token,
155-
'filename' => ($shareNode instanceof File) ? $shareNode->getName() : null,
156-
]);
153+
$downloadUrl = $this->urlGenerator->getAbsoluteURL('/public.php/dav/files/' . $token . '/?accept=zip');
157154

158155
// If not a file drop, then add the download header action
159156
$headerActions[] = new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', $downloadUrl, 0, (string)$shareNode->getSize());

apps/files_sharing/tests/Controller/ShareControllerTest.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,12 @@ public function testShowShare(): void {
261261
['files_sharing.sharecontroller.showShare', ['token' => 'token'], 'shareUrl'],
262262
// this share is not an image to the default preview is used
263263
['files_sharing.PublicPreview.getPreview', ['x' => 256, 'y' => 256, 'file' => $share->getTarget(), 'token' => 'token'], 'previewUrl'],
264-
// for the direct link
265-
['files_sharing.sharecontroller.downloadShare', ['token' => 'token', 'filename' => $filename ], 'downloadUrl'],
264+
]);
265+
266+
$this->urlGenerator->expects($this->once())
267+
->method('getAbsoluteURL')
268+
->willReturnMap([
269+
['/public.php/dav/files/token/?accept=zip', 'downloadUrl'],
266270
]);
267271

268272
$this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
@@ -552,8 +556,12 @@ public function testShowShareWithPrivateName(): void {
552556
['files_sharing.sharecontroller.showShare', ['token' => 'token'], 'shareUrl'],
553557
// this share is not an image to the default preview is used
554558
['files_sharing.PublicPreview.getPreview', ['x' => 256, 'y' => 256, 'file' => $share->getTarget(), 'token' => 'token'], 'previewUrl'],
555-
// for the direct link
556-
['files_sharing.sharecontroller.downloadShare', ['token' => 'token', 'filename' => $filename ], 'downloadUrl'],
559+
]);
560+
561+
$this->urlGenerator->expects($this->once())
562+
->method('getAbsoluteURL')
563+
->willReturnMap([
564+
['/public.php/dav/files/token/?accept=zip', 'downloadUrl'],
557565
]);
558566

559567
$this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);

cypress/e2e/files_sharing/public-share/header-menu.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('files_sharing: Public share - header actions menu', { testIsolation: t
5353
cy.findByRole('menuitem', { name: 'Direct link' })
5454
.should('be.visible')
5555
.and('have.attr', 'href')
56-
.then((attribute) => expect(attribute).to.match(/^http:\/\/.+\/download$/))
56+
.then((attribute) => expect(attribute).to.match(new RegExp(`^${Cypress.env('baseUrl')}/public.php/dav/files/.+/?accept=zip$`)))
5757
// see menu closes on click
5858
cy.findByRole('menuitem', { name: 'Direct link' })
5959
.click()
@@ -188,7 +188,7 @@ describe('files_sharing: Public share - header actions menu', { testIsolation: t
188188
cy.findByRole('menuitem', { name: 'Direct link' })
189189
.should('be.visible')
190190
.and('have.attr', 'href')
191-
.then((attribute) => expect(attribute).to.match(/^http:\/\/.+\/download$/))
191+
.then((attribute) => expect(attribute).to.match(new RegExp(`^${Cypress.env('baseUrl')}/public.php/dav/files/.+/?accept=zip$`)))
192192
// See remote share works
193193
cy.findByRole('menuitem', { name: /Add to your/i })
194194
.should('be.visible')

0 commit comments

Comments
 (0)