Skip to content

Commit

Permalink
disable excel report for legacy download (#4449)
Browse files Browse the repository at this point in the history
log async downloads
send EXPORT_CREATE event for async download (listened by ExpiringRights plugin)
  • Loading branch information
jygaulier authored Dec 21, 2023
1 parent 9b34492 commit e2fb405
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
27 changes: 26 additions & 1 deletion lib/Alchemy/Phrasea/Controller/Prod/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class DownloadController extends Controller
{
Expand Down Expand Up @@ -62,6 +64,9 @@ public function checkDownload(Request $request)
);

$list['export_name'] = sprintf('%s.zip', $download->getExportName());
$list['include_report'] = $request->request->get('include_report') === 'INCLUDE_REPORT';
$list['include_businessfields'] = (bool)$request->request->get('businessfields');

$token = $this->getTokenManipulator()->createDownloadToken($this->getAuthenticatedUser(), serialize($list));

$this->getDispatcher()->dispatch(PhraseaEvents::EXPORT_CREATE, new ExportEvent(
Expand All @@ -73,7 +78,7 @@ public function checkDownload(Request $request)
)
);

/** @see DoDownloadController::prepareDownload */
/** @uses DoDownloadController::prepareDownload */
return $this->app->redirectPath('prepare_download', ['token' => $token->getValue()]);
}

Expand Down Expand Up @@ -134,6 +139,26 @@ public function listDownloadAsync(Request $request)
$token = $this->getTokenManipulator()->createDownloadToken($this->getAuthenticatedUser(), serialize($list));

$pusher_auth_key =$this->getConf()->get(['download_async', 'enabled'], false) ? $this->getConf()->get(['externalservice', 'pusher', 'auth_key'], '') : null;

$this->getDispatcher()->dispatch(PhraseaEvents::EXPORT_CREATE, new ExportEvent(
$this->getAuthenticatedUser(),
$ssttid,
$lst,
$subdefs,
$download->getExportName()
)
);

$this->getDispatcher()->addListener(KernelEvents::RESPONSE, function (FilterResponseEvent $event) use ($list) {
\set_export::log_download(
$this->app,
$list,
$event->getRequest()->get('type'),
!!$event->getRequest()->get('anonymous', false),
(isset($list['email']) ? $list['email'] : '')
);
});

return new Response($this->render(
/** @uses templates/web/prod/actions/Download/prepare_async.html.twig */
'/prod/actions/Download/prepare_async.html.twig', [
Expand Down
25 changes: 24 additions & 1 deletion templates/web/common/dialog_export.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,18 @@
<li><a href="#ftp">{{ 'export:: FTP' | trans }}</a></li>
{% endif %}
</ul>
{% if download.get_total_download() > 0 %}
{# ##########################################
direct / async download
############################################# #}
<div id="download">
<div style="padding:10px; text-align: center;">
<h4>{{ 'export:: telechargement' | trans }}</h4>
{% if app['conf'].get(['download_async', 'enabled'], false) %}
{# \Alchemy\Phrasea\Controller\Prod\DownloadController::checkDownloadAsync #}
{# \Alchemy\Phrasea\Controller\Prod\DownloadController::listDownloadAsync #}
{% set download_path = 'list_download_async' %}
{% else %}
{# \Alchemy\Phrasea\Controller\Prod\DownloadController::checkDownload #}
Expand Down Expand Up @@ -145,12 +150,14 @@
</div>
{% endif %}
{% endfor %}
{% if app['conf'].get(['download_async', 'enabled'], false) %}
<div class="well-small">
<label for="include_report" class="checkbox">
<input class="caption" type="checkbox" id="include_report" name="include_report" value="INCLUDE_REPORT" />
{{ 'prod::download: report as spreadsheet' | trans }}
</label>
</div>
{% endif %}
{% if download.has_business_fields_access() %}
<div class="businessfields well-small" style="margin-left:20px;display:none;">
<label for="business_download" class="checkbox">
Expand Down Expand Up @@ -187,6 +194,10 @@
</div>
</div>
{# ##########################################
email
############################################# #}
<div id="sendmail">
<div style="padding:10px; text-align: center;">
<h4>{{ 'export:: envoi par mail' | trans }}</h4>
Expand Down Expand Up @@ -288,6 +299,12 @@
</div>
{% endif %}
{% if download.get_total_order() > 0 %}
{# ##########################################
order
############################################# #}
<div id="order">
{% for name, values in download.get_display_orderable() %}
{% if values.available > 0 %}
Expand Down Expand Up @@ -434,6 +451,12 @@
</form>
</div>
{% endif %}
{# ##########################################
ftp
############################################# #}
{% if download.get_total_ftp() > 0 %}
<div id="ftp">
<div style="padding:10px; text-align: center;">
Expand Down
2 changes: 2 additions & 0 deletions templates/web/prod/actions/Download/prepare.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
</div>

<div style="display:none">
{# \Alchemy\Phrasea\Controller\Prod\DoDownloadController::downloadDocuments #}
<form name="download" action="{{ path('document_download', {'token': token.getValue(), 'type': type, 'anonymous': anonymous}) }}" method="post" target="file_frame">
{% if anonymous %}
<input type="hidden" name="anonymous" value="1" />
Expand All @@ -105,6 +106,7 @@
{% set time = time < 1 ? 2 : (time > 10 ? 10 : time) %}
{% if list['complete'] is not defined %} {# Zip not done #}
{# \Alchemy\Phrasea\Controller\Prod\DoDownloadController::downloadExecute #}
$.post("{{ path('execute_download', {'token': token.getValue(), 'type': type, 'anonymous': anonymous}) }}", function(data){
if(data.success) {
$('form[name=download]').submit();
Expand Down

0 comments on commit e2fb405

Please sign in to comment.