PHRAS-3958_download-one-asset (#4425)

* fix sync-download 1 doc ; fix stamp not removed

* remove test
This commit is contained in:
jygaulier
2023-11-30 15:15:34 +01:00
committed by GitHub
parent bfe3bd04f4
commit 00fc6e1c7a
4 changed files with 28 additions and 30 deletions

View File

@@ -9,14 +9,12 @@
*/
namespace Alchemy\Phrasea\Controller\Prod;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Application\Helper\DelivererAware;
use Alchemy\Phrasea\Application\Helper\DispatcherAware;
use Alchemy\Phrasea\Application\Helper\FilesystemAware;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Http\DeliverDataInterface;
use Alchemy\Phrasea\Model\Entities\Token;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
@@ -107,17 +105,17 @@ class DoDownloadController extends Controller
$exportName = $list['export_name'];
if ($list['count'] === 1 && !$list['cgu']) {
$file = end($list['files']);
$subdef = end($file['subdefs']);
$exportName = sprintf('%s%s.%s', $file['export_name'], $subdef['ajout'], $subdef['exportExt']);
$exportFile = \p4string::addEndSlash($subdef['path']) . $subdef['file'];
$mime = $subdef['mime'];
$list['complete'] = true;
} else {
// if ($list['count'] === 1 && !$list['cgu']) {
// $file = end($list['files']);
// $subdef = end($file['subdefs']);
// $exportName = sprintf('%s%s.%s', $file['export_name'], $subdef['ajout'], $subdef['exportExt']);
// $exportFile = \p4string::addEndSlash($subdef['path']) . $subdef['file'];
// $mime = $subdef['mime'];
// $list['complete'] = true;
// } else {
$exportFile = $this->app['tmp.download.path'].'/'.$token->getValue() . '.zip';
$mime = 'application/zip';
}
// }
if (!$this->getFilesystem()->exists($exportFile)) {
$this->app->abort(404, 'Download file not found');
@@ -159,21 +157,21 @@ class DoDownloadController extends Controller
$session->save();
ignore_user_abort(true);
if ($list['count'] > 1) {
// if ($list['count'] > 1 || $list['cgu']) {
\set_export::build_zip(
$this->app,
$token,
$list,
sprintf('%s/%s.zip', $this->app['tmp.download.path'], $token->getValue()) // Dest file
);
} else {
$list['complete'] = true;
$token->setData(serialize($list));
/** @var EntityManagerInterface $manager */
$manager = $this->app['orm.em'];
$manager->persist($token);
$manager->flush();
}
// } else {
// $list['complete'] = true;
// $token->setData(serialize($list));
// /** @var EntityManagerInterface $manager */
// $manager = $this->app['orm.em'];
// $manager->persist($token);
// $manager->flush();
// }
return $this->app->json([
'success' => true,

View File

@@ -17,6 +17,7 @@ use Alchemy\Phrasea\Core\Event\ExportEvent;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Filesystem\PhraseanetFilesystem;
use Alchemy\Phrasea\Model\Manipulator\TokenManipulator;
use Exception;
use set_export;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -81,6 +82,7 @@ class DownloadController extends Controller
*
* @param Request $request
* @return Response
* @throws Exception
*/
public function listDownloadAsync(Request $request)
{
@@ -98,12 +100,6 @@ class DownloadController extends Controller
$this->app->abort(403);
}
// "stamp_choice" is a ckbox with value "NO_STAMP" to "remove stamp" on download
$stamp_method = set_export::STAMP_ASYNC; // will not stamp, but flag files to be stamped
if($request->request->get('stamp_choice') === set_export::NO_STAMP) {
$stamp_method = set_export::NO_STAMP;
}
$list = $download->prepare_export(
$this->getAuthenticatedUser(),
$this->getFilesystem(),
@@ -128,7 +124,7 @@ class DownloadController extends Controller
try {
$record = new \record_adapter($this->app, $sbasId, $file['record_id']);
} catch (\Exception $e) {
} catch (Exception $e) {
continue;
}
@@ -183,10 +179,10 @@ class DownloadController extends Controller
]);
}
else {
throw new \Exception("invalid or expired token");
throw new Exception("invalid or expired token");
}
}
catch(\Exception $e) {
catch(Exception $e) {
// no-op
$this->app->abort(403, $e->getMessage());
}

View File

@@ -173,7 +173,7 @@
{% if removeable_stamp and download.has_stamp_option() == true %}
<div id="stamp_choice" class="well-small" style="margin-left: 20px;" >
<label for="option_stamp" class="checkbox">
<input class="stamp_choice" type="checkbox" id="stamp_choice" name="stamp_choice" value="NO_STAMP" />
<input class="stamp_choice" type="checkbox" id="stamp_choice" name="stamp_choice" value="REMOVE_STAMP" />
{{ 'prod::download: delete-marking-stamp' | trans }}
</label>
</div>

View File

@@ -79,6 +79,9 @@ class DoDownloadTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testOneDocumentsDownload()
{
$this->markTestSkipped("direct download removed by PHRAS-3958");
/*
$nbRowLogsBefore = $this->getNbRowLogs(self::$DI['record_1']->get_databox());
$thumbnail = self::$DI['record_1']->get_thumbnail();
@@ -119,6 +122,7 @@ class DoDownloadTest extends \PhraseanetAuthenticatedWebTestCase
$nbRowLogsAfter = $this->getNbRowLogs(self::$DI['record_1']->get_databox());
$this->assertGreaterThan($nbRowLogsBefore, $nbRowLogsAfter);
unset($response);
*/
}
/**
* @covers Alchemy\Phrasea\Controller\Prod\DoDownload::downloadDocuments