Skip to content

Commit

Permalink
Merge branch 'master' into PHRAS-3945-mv-config-pusher
Browse files Browse the repository at this point in the history
  • Loading branch information
nmaillat authored Nov 22, 2023
2 parents d830ea3 + 07f4462 commit ec54f7b
Show file tree
Hide file tree
Showing 26 changed files with 956 additions and 901 deletions.
1 change: 1 addition & 0 deletions config/configuration.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ registry:
api-subdef_service: false
actions:
export-stamp-choice: false
stamp-subdefs: false
crossdomain:
site-control: 'master-only'
allow-access-from:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,9 @@ public function submitSuggestedValues(Request $request, $bas_id)
try {
if ('' !== trim($prefs)) {
$domdoc = new \DOMDocument();
if (true === @$domdoc->loadXML($prefs)) {
if (true === @$domdoc->loadXML($prefs, LIBXML_NONET | LIBXML_NOBLANKS)) {
$domdoc->formatOutput = true;
$domdoc->saveXML(null, LIBXML_NOEMPTYTAG);
$collection->set_prefs($domdoc);
$success = true;
}
Expand Down
24 changes: 17 additions & 7 deletions lib/Alchemy/Phrasea/Controller/Prod/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Alchemy\Phrasea\Core\Event\DownloadAsyncEvent;
use Alchemy\Phrasea\Core\Event\ExportEvent;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Filesystem\PhraseanetFilesystem;
use Alchemy\Phrasea\Model\Manipulator\TokenManipulator;
use set_export;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down Expand Up @@ -42,19 +43,21 @@ public function checkDownload(Request $request)
$ssttid = $request->request->get('ssttid', '');
$subdefs = $request->request->get('obj', []);

$download = new \set_export($this->app, $lst, $ssttid);
$download = new set_export($this->app, $lst, $ssttid);

if (0 === $download->get_total_download()) {
$this->app->abort(403);
}

$list = $download->prepare_export(
$this->getAuthenticatedUser(),
$this->app['filesystem'],
$this->getFilesystem(),
$subdefs,
$request->request->get('type') === 'title' ? true : false,
$request->request->get('businessfields'),
$request->request->get('stamp_choice') === "NO_STAMP" ? \set_export::NO_STAMP : \set_export::STAMP_SYNC
set_export::STAMP_SYNC,
$request->request->get('stamp_choice') === "REMOVE_STAMP",
false
);

$list['export_name'] = sprintf('%s.zip', $download->getExportName());
Expand Down Expand Up @@ -89,7 +92,7 @@ public function listDownloadAsync(Request $request)
$ssttid = $request->request->get('ssttid', '');
$subdefs = $request->request->get('obj', []);

$download = new \set_export($this->app, $lst, $ssttid);
$download = new set_export($this->app, $lst, $ssttid);

if (0 === $download->get_total_download()) {
$this->app->abort(403);
Expand All @@ -103,12 +106,12 @@ public function listDownloadAsync(Request $request)

$list = $download->prepare_export(
$this->getAuthenticatedUser(),
$this->app['filesystem'],
$this->getFilesystem(),
$subdefs,
$request->request->get('type') === 'title' ? true : false,
$request->request->get('businessfields'),
// do not stamp now, worker will do
$stamp_method,
set_export::STAMP_ASYNC,
$request->request->get('stamp_choice') === "REMOVE_STAMP",
true
);
$list['export_name'] = sprintf('%s.zip', $download->getExportName());
Expand Down Expand Up @@ -212,4 +215,11 @@ protected function getSession()
{
return $this->app['session'];
}
/**
* @return PhraseanetFilesystem
*/
private function getFilesystem()
{
return $this->app['filesystem'];
}
}
75 changes: 68 additions & 7 deletions lib/Alchemy/Phrasea/Controller/Prod/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
namespace Alchemy\Phrasea\Controller\Prod;

use ACL;
use Alchemy\Phrasea\Application\Helper\DispatcherAware;
use Alchemy\Phrasea\Application\Helper\FilesystemAware;
use Alchemy\Phrasea\Application\Helper\NotifierAware;
Expand All @@ -19,6 +20,8 @@
use Alchemy\Phrasea\Model\Manipulator\TokenManipulator;
use Alchemy\Phrasea\WorkerManager\Event\ExportFtpEvent;
use Alchemy\Phrasea\WorkerManager\Event\WorkerEvents;
use DOMDocument;
use DOMXPath;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -29,6 +32,15 @@ class ExportController extends Controller
use FilesystemAware;
use NotifierAware;

/**
* @return ACL
*/
private function getAclForConnectedUser()
{
return $this->getAclForUser($this->getAuthenticatedUser());
}


/**
* Display form to export documents
*
Expand All @@ -44,17 +56,63 @@ public function displayMultiExport(Request $request)
$request->request->get('story')
);

// we must propose "do not stamp" when at least one collection is stamped AND the user has right to
// remove stamp on this collection
$removeable_stamp = false; // true if at least one coll is "unstampable"
$removeable_stamp_by_base = []; // unset: no stamp ; false: stamp not "unstampable" ; true: stamp "unstampable"

$colls_manageable = array_keys($this->getAclForConnectedUser()->get_granted_base([ACL::COLL_MANAGE]) ?? []);
$dbox_manageable = array_keys($this->getAclForConnectedUser()->get_granted_sbas([ACL::BAS_MANAGE]) ?? []);

foreach($download->get_elements() as $recordAdapter) {
// check collection only once
if(array_key_exists($bid = $recordAdapter->getCollection()->get_base_id(), $removeable_stamp_by_base)) {
continue;
}
// check stamp
$domprefs = new DOMDocument();
if ( !$domprefs->loadXML($recordAdapter->getCollection()->get_prefs()) ) {
continue;
}
$xpprefs = new DOMXPath($domprefs);
if ($xpprefs->query('/baseprefs/stamp')->length == 0) {
// the collection has no stamp settings
continue;
}
unset($domprefs);
// the collection has stamp, check user's right to remove it
$removeable_stamp_by_base[$bid] = false;
switch ((string)$this->getConf()->get(['registry', 'actions', 'export-stamp-choice'], false)) {
case '1': // == (string)true
// everybody can remove stamp (bc)
$removeable_stamp_by_base[$bid] = $removeable_stamp = true;
break;
case 'manage_collection':
if (in_array($bid, $colls_manageable)) {
$removeable_stamp_by_base[$bid] = $removeable_stamp = true;
}
break;
case 'manage_databox':
if (in_array($recordAdapter->getDatabox()->get_sbas_id(), $dbox_manageable)) {
$removeable_stamp_by_base[$bid] = $removeable_stamp = true;
}
break;
}
}

$this->setSessionFormToken('prodExportDownload');
$this->setSessionFormToken('prodExportEmail');
$this->setSessionFormToken('prodExportFTP');
$this->setSessionFormToken('prodExportOrder');

return new Response($this->render('common/dialog_export.html.twig', [
'download' => $download,
'ssttid' => $request->request->get('ssel'),
'lst' => $download->serialize_list(),
'default_export_title' => $this->getConf()->get(['registry', 'actions', 'default-export-title']),
'choose_export_title' => $this->getConf()->get(['registry', 'actions', 'export-title-choice'])
'download' => $download,
'ssttid' => $request->request->get('ssel'),
'lst' => $download->serialize_list(),
'default_export_title' => $this->getConf()->get(['registry', 'actions', 'default-export-title']),
'choose_export_title' => $this->getConf()->get(['registry', 'actions', 'export-title-choice']),
'removeable_stamp' => $removeable_stamp,
'removeable_stamp_by_base' => $removeable_stamp_by_base,
]));
}

Expand Down Expand Up @@ -123,7 +181,9 @@ public function exportFtp(Request $request)
$request->request->get('obj'),
false,
$request->request->get('businessfields'),
$request->request->get('stamp_choice') === "NO_STAMP" ? \set_export::NO_STAMP : \set_export::STAMP_ASYNC
\set_export::STAMP_ASYNC,
$request->request->get('stamp_choice') === "REMOVE_STAMP",
false
);

$exportFtpId = $download->export_ftp(
Expand Down Expand Up @@ -181,7 +241,8 @@ public function exportMail(Request $request)
(array) $request->request->get('obj'),
$request->request->get("type") == "title" ? : false,
$request->request->get('businessfields'),
$request->request->get('stamp_choice') === "NO_STAMP" ? \set_export::NO_STAMP : \set_export::STAMP_ASYNC,
\set_export::STAMP_ASYNC,
$request->request->get('stamp_choice') === "REMOVE_STAMP",
true
);

Expand Down
3 changes: 2 additions & 1 deletion lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@ public function autoSubtitleAction(Request $request)
new RecordAutoSubtitleEvent(
$record,
$request->request->get("subtitle_language_source"),
json_decode($request->request->get("subtitle_destination"), true)
json_decode($request->request->get("subtitle_destination"), true),
$this->getAuthenticatedUser()->getId()
)
);

Expand Down
2 changes: 2 additions & 0 deletions lib/Alchemy/Phrasea/ControllerProvider/Admin/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ public function connect(Application $app)
->assert('bas_id', '\d+')
->bind('admin_display_collection');

/** @uses CollectionController::getSuggestedValues */
$controllers->get('/{bas_id}/suggested-values/', 'controller.admin.collection:getSuggestedValues')
->assert('bas_id', '\d+')
->bind('admin_collection_display_suggested_values');

/** @uses CollectionController::submitSuggestedValues */
$controllers->post('/{bas_id}/suggested-values/', 'controller.admin.collection:submitSuggestedValues')
->assert('bas_id', '\d+')
->bind('admin_collection_submit_suggested_values');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@
class RecordAutoSubtitleEvent extends RecordEvent
{
private $languageSource;
private $metaStructureIdSource;
private $languageDestination;
private $metaStructureIdDestination;
private $authenticatedUserId;

public function __construct(
RecordInterface $record,
$languageSource,
$languageDestination
$languageDestination,
$authenticatedUserId
)
{
parent::__construct($record);

$this->languageSource = $languageSource;
$this->languageDestination = $languageDestination;
$this->authenticatedUserId = $authenticatedUserId;
}

public function getLanguageSource()
Expand All @@ -33,8 +34,8 @@ public function getLanguageDestination()
return $this->languageDestination;
}

public function getMetaStructureIdDestination()
public function getAuthenticatedUserId()
{
return $this->metaStructureIdDestination;
return $this->authenticatedUserId;
}
}
11 changes: 10 additions & 1 deletion lib/Alchemy/Phrasea/Order/Controller/ApiOrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,16 @@ public function getArchiveAction($orderId)
$subdefs = $this->findDataboxSubdefNames();

try {
$exportData = $export->prepare_export($user, $this->getFilesystem(), $subdefs, true, true, false);
$exportData = $export->prepare_export(
$user,
$this->getFilesystem(),
$subdefs,
true,
true,
\set_export::STAMP_SYNC,
false,
false
);
}
catch (\Exception $e) {
throw new NotFoundHttpException(sprintf('No archive could be downloaded for Order "%d"', $order->getId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Alchemy\Phrasea\Core\Event\Record\RecordAutoSubtitleEvent;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Model\Entities\WorkerJob;
use Alchemy\Phrasea\Model\Repositories\WorkerJobRepository;
use Alchemy\Phrasea\WorkerManager\Queue\MessagePublisher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand Down Expand Up @@ -33,6 +32,7 @@ public function onRecordAutoSubtitle(RecordAutoSubtitleEvent $event)
"recordId" => $event->getRecord()->getRecordId(),
"languageSource" => $event->getLanguageSource(),
"languageDestination" => $event->getLanguageDestination(),
"authenticatedUserId" => $event->getAuthenticatedUserId(),
"type" => MessagePublisher::SUBTITLE_TYPE // used to specify the final Q to publish message
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function process(array $payload)
}

foreach($v_file['subdefs'] as $k_subdef => $v_subdef) {
if($k_subdef === "document" && $v_subdef['to_stamp']) {
if($v_subdef['to_stamp']) {
// we must stamp this document
try {
if(!$record) {
Expand Down
23 changes: 23 additions & 0 deletions lib/Alchemy/Phrasea/WorkerManager/Worker/SubtitleWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,18 @@ public function process(array $payload)
// order to write meta in file
$this->dispatcher->dispatch(WorkerEvents::RECORDS_WRITE_META,
new RecordsWriteMetaEvent([$record->getRecordId()], $record->getDataboxId()));

$this->getEventsManager()->notify(
$payload['authenticatedUserId'],
'eventsmanager_notify_subtitle',
json_encode([
'translateMessage' => 'notification:: subtitle "%langues%" generated for "%title%" !',
'langues' => implode(', ', array_keys($payload['languageDestination'])),
'title' => htmlentities($record->get_title())
]),
false
);

} catch (\Exception $e) {
$this->logger->error($e->getMessage());
$this->jobFinished();
Expand Down Expand Up @@ -476,4 +488,15 @@ private function getTargetLanguageByCode($code)

return $t[0];
}

/**
* @return \eventsmanager_broker
*/
private function getEventsManager()
{
$app = $this->getApplicationBox()->getPhraseApplication();

return $app['events-manager'];
}

}
1 change: 1 addition & 0 deletions lib/classes/eventsmanager/broker.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function start()
'eventsmanager_notify_push',
'eventsmanager_notify_basketwip',
'eventsmanager_notify_register',
'eventsmanager_notify_subtitle',
'eventsmanager_notify_uploadquarantine',
'eventsmanager_notify_validate',
'eventsmanager_notify_validationdone',
Expand Down
Loading

0 comments on commit ec54f7b

Please sign in to comment.