Skip to content

Commit

Permalink
Merge branch 'master' into PHRAS-3777-cleanup-old-keys
Browse files Browse the repository at this point in the history
  • Loading branch information
nmaillat authored Nov 30, 2023
2 parents d5fd4aa + 00fc6e1 commit ba1da1d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
38 changes: 18 additions & 20 deletions lib/Alchemy/Phrasea/Controller/Prod/DoDownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,17 +105,17 @@ public function downloadDocuments(Token $token)

$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');
Expand Down Expand Up @@ -159,21 +157,21 @@ public function downloadExecute(Token $token)
$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,
Expand Down
14 changes: 5 additions & 9 deletions lib/Alchemy/Phrasea/Controller/Prod/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;
Expand Down Expand Up @@ -81,6 +82,7 @@ public function checkDownload(Request $request)
*
* @param Request $request
* @return Response
* @throws Exception
*/
public function listDownloadAsync(Request $request)
{
Expand All @@ -98,12 +100,6 @@ public function listDownloadAsync(Request $request)
$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(),
Expand All @@ -128,7 +124,7 @@ public function listDownloadAsync(Request $request)

try {
$record = new \record_adapter($this->app, $sbasId, $file['record_id']);
} catch (\Exception $e) {
} catch (Exception $e) {
continue;
}

Expand Down Expand Up @@ -183,10 +179,10 @@ public function startDownloadAsync(Request $request)
]);
}
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());
}
Expand Down
2 changes: 1 addition & 1 deletion templates/web/common/dialog_export.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public function testPrepareDownloadInvalidData()
*/
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();
Expand Down Expand Up @@ -119,6 +122,7 @@ public function testOneDocumentsDownload()
$nbRowLogsAfter = $this->getNbRowLogs(self::$DI['record_1']->get_databox());
$this->assertGreaterThan($nbRowLogsBefore, $nbRowLogsAfter);
unset($response);
*/
}
/**
* @covers Alchemy\Phrasea\Controller\Prod\DoDownload::downloadDocuments
Expand Down

0 comments on commit ba1da1d

Please sign in to comment.