From 94d547d897fd3f3c2741ed91bf179594ad376cab Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 28 Nov 2013 11:49:19 +0100 Subject: [PATCH] Fix #1593 : "download" query parameter is not working anymore on permalink URIs --- .../Phrasea/Controller/AbstractDelivery.php | 4 +++- .../Tests/Phrasea/Application/OverviewTest.php | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/Alchemy/Phrasea/Controller/AbstractDelivery.php b/lib/Alchemy/Phrasea/Controller/AbstractDelivery.php index f179dfb03d..abc9cd7090 100644 --- a/lib/Alchemy/Phrasea/Controller/AbstractDelivery.php +++ b/lib/Alchemy/Phrasea/Controller/AbstractDelivery.php @@ -52,7 +52,9 @@ abstract class AbstractDelivery implements ControllerProviderInterface } - $response = $app['phraseanet.file-serve']->deliverFile($pathOut, $file->get_file(), DeliverDataInterface::DISPOSITION_INLINE, $file->get_mime()); + $disposition = $request->query->get('download') ? DeliverDataInterface::DISPOSITION_ATTACHMENT : DeliverDataInterface::DISPOSITION_INLINE; + + $response = $app['phraseanet.file-serve']->deliverFile($pathOut, $file->get_file(), $disposition, $file->get_mime()); $response->setPrivate(); /* @var $response \Symfony\Component\HttpFoundation\Response */ diff --git a/tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php b/tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php index 6e4e86f264..075d1cefdf 100644 --- a/tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php +++ b/tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php @@ -94,6 +94,20 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac $this->get_a_permaview(array("Content-Type" => "text/html; charset=UTF-8")); } + public function testPermalinkAuthenticatedWithDownloadQuery() + { + $token = self::$DI['record_1']->get_preview()->get_permalink()->get_token(); + $url = '/permalink/v1/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/preview/whateverIwannt.jpg?token=' . $token . '&download=1'; + + self::$DI['client']->request('GET', $url); + $response = self::$DI['client']->getResponse(); + + $this->assertRegExp('/^attachment;/', $response->headers->get('content-disposition')); + + $this->assertEquals(rtrim(self::$DI['app']['phraseanet.configuration']['main']['servername'], '/') . "/permalink/v1/1/". self::$DI['record_1']->get_record_id()."/caption/?token=".$token, $response->headers->get("Link")); + $this->assertEquals(200, $response->getStatusCode()); + } + public function testPermalinkNotAuthenticated() { $this->logout(self::$DI['app']); @@ -244,6 +258,7 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac $crawler = self::$DI['client']->request('GET', $url); $response = self::$DI['client']->getResponse(); + $this->assertRegExp('/^inline;/', $response->headers->get('content-disposition')); foreach ($headers as $name => $value) { $this->assertEquals($value, $response->headers->get($name)); }