Skip to content

Commit

Permalink
add stamp / no-stamp to export-by-email and export-by-ftp (#4437)
Browse files Browse the repository at this point in the history
add default (disabled) stamp settings on new collections
add "record_edit" & "image_tools" to conf / export-stamp-choice privilege
  • Loading branch information
jygaulier authored Dec 14, 2023
1 parent e97751b commit 8df3cf5
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 66 deletions.
74 changes: 45 additions & 29 deletions lib/Alchemy/Phrasea/Controller/Admin/DataboxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
use Alchemy\Phrasea\Authentication\Authenticator;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Core\Configuration\DisplaySettingService;
use Alchemy\Phrasea\Model\Manipulator\TaskManipulator;
use Alchemy\Phrasea\SearchEngine\Elastic\ElasticsearchOptions;
use Alchemy\Phrasea\WorkerManager\Event\PopulateIndexEvent;
use Alchemy\Phrasea\WorkerManager\Event\WorkerEvents;
use collection;
use Exception;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
Expand Down Expand Up @@ -103,7 +104,8 @@ public function deleteBase(Request $request, $databox_id)
$success = true;
$msg = $this->app->trans('Successful removal');
}
} catch (\Exception $e) {
}
catch (Exception $e) {

}
if (!$databox) {
Expand Down Expand Up @@ -150,7 +152,8 @@ public function setLabels(Request $request, $databox_id)
$value = $labels[$code] ?: null;
$databox->set_label($code, $value);
}
} catch (\Exception $e) {
}
catch (Exception $e) {
$success = false;
}

Expand Down Expand Up @@ -190,7 +193,9 @@ public function reindex(Request $request, $databox_id)
try {
$this->getDispatcher()->dispatch(WorkerEvents::POPULATE_INDEX, new PopulateIndexEvent($populateInfo));
$success = true;
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}

if ('json' === $request->getRequestFormat()) {
Expand Down Expand Up @@ -222,8 +227,8 @@ public function setIndexable(Request $request, $databox_id)
$indexable = !!$request->request->get('indexable', false);
$this->getApplicationBox()->set_databox_indexable($databox, $indexable);
$success = true;
} catch (\Exception $e) {

} catch (Exception $e) {
// no-op
}

if ('json' === $request->getRequestFormat()) {
Expand Down Expand Up @@ -255,7 +260,8 @@ public function updateDatabaseCGU(Request $request, $databox_id)
foreach ($request->request->get('TOU', []) as $loc => $terms) {
$databox->update_cgus($loc, $terms, !!$request->request->get('valid', false));
}
} catch (\Exception $e) {
}
catch (Exception $e) {
return $this->app->redirectPath('admin_database_display_cgus', [
'databox_id' => $databox_id,
'success' => 0,
Expand Down Expand Up @@ -283,7 +289,7 @@ public function mountCollection(Request $request, $databox_id, $collection_id)
try {
/** @var Authenticator $authenticator */
$authenticator = $this->app->getAuthenticator();
$baseId = \collection::mount_collection(
$baseId = collection::mount_collection(
$this->app,
$this->findDataboxById($databox_id),
$collection_id,
Expand Down Expand Up @@ -315,7 +321,8 @@ public function mountCollection(Request $request, $databox_id, $collection_id)
'databox_id' => $databox_id,
'mount' => 'ok',
]);
} catch (\Exception $e) {
}
catch (Exception $e) {
$connection->rollBack();

return $this->app->redirectPath('admin_database', [
Expand Down Expand Up @@ -366,7 +373,8 @@ public function sendLogoPdf(Request $request, $databox_id)
'error' => 'file-invalid',
]);
}
} catch (\Exception $e) {
}
catch (Exception $e) {
return $this->app->redirectPath('admin_database', [
'databox_id' => $databox_id,
'success' => '0',
Expand Down Expand Up @@ -395,8 +403,9 @@ public function deleteLogoPdf(Request $request, $databox_id)
\databox::PIC_PDF
);
$success = true;
} catch (\Exception $e) {

}
catch (Exception $e) {
// no-op
}

if ('json' === $request->getRequestFormat()) {
Expand Down Expand Up @@ -428,8 +437,9 @@ public function clearLogs(Request $request, $databox_id)
try {
$this->findDataboxById($databox_id)->clear_logs();
$success = true;
} catch (\Exception $e) {

}
catch (Exception $e) {
// no-op
}

if ('json' === $request->getRequestFormat()) {
Expand Down Expand Up @@ -465,8 +475,9 @@ public function changeViewName(Request $request, $databox_id)
try {
$this->findDataboxById($databox_id)->set_viewname($viewName);
$success = true;
} catch (\Exception $e) {

}
catch (Exception $e) {
// no-op
}

if ('json' === $request->getRequestFormat()) {
Expand Down Expand Up @@ -500,8 +511,9 @@ public function unmountDatabase(Request $request, $databox_id)
$databox->unmount_databox();

$success = true;
} catch (\Exception $e) {

}
catch (Exception $e) {
// no-op
}

if ('json' === $request->getRequestFormat()) {
Expand Down Expand Up @@ -553,8 +565,9 @@ public function emptyDatabase(Request $request, $databox_id)
// if ($taskCreated) {
// $msg = $this->app->trans('A task has been created, please run it to complete empty collection');
// }
} catch (\Exception $e) {

}
catch (Exception $e) {
// no-op
}

if ('json' === $request->getRequestFormat()) {
Expand Down Expand Up @@ -612,8 +625,9 @@ public function progressBarInfos(Request $request, $databox_id)

$ret['success'] = true;
$ret['msg'] = $this->app->trans('Successful update');
} catch (\Exception $e) {

}
catch (Exception $e) {
// no-op
}

return $this->app->json($ret);
Expand Down Expand Up @@ -645,11 +659,12 @@ public function setReorder(Request $request, $databox_id)
{
try {
foreach ($request->request->get('order', []) as $data) {
$collection = \collection::getByBaseId($this->app, $data['id']);
$collection = collection::getByBaseId($this->app, $data['id']);
$collection->set_ord($data['offset']);
}
$success = true;
} catch (\Exception $e) {
}
catch (Exception $e) {
$success = false;
}

Expand Down Expand Up @@ -680,11 +695,11 @@ public function getNewCollection()
/**
* Create a new collection
*
* @param Request $request The current HTTP request
* @param integer $databox_id The requested databox
* @param Request $request The current HTTP request
* @param integer $databox_id The requested databox
* @return Response
*/
public function createCollection(Request $request, $databox_id)
public function createCollection(Request $request, int $databox_id)
{
if (($name = trim($request->request->get('name', ''))) === '') {
return $this->app->redirectPath('admin_database_display_new_collection_form', [
Expand All @@ -695,7 +710,7 @@ public function createCollection(Request $request, $databox_id)

try {
$databox = $this->findDataboxById($databox_id);
$collection = \collection::create(
$collection = collection::create(
$this->app, $databox,
$this->getApplicationBox(),
$name,
Expand All @@ -721,7 +736,8 @@ public function createCollection(Request $request, $databox_id)
'success' => 1,
'reload-tree' => 1,
]);
} catch (\Exception $e) {
}
catch (Exception $e) {
return $this->app->redirectPath('admin_database_submit_collection', [
'databox_id' => $databox_id,
'error' => $e->getMessage(),
Expand Down
29 changes: 23 additions & 6 deletions lib/Alchemy/Phrasea/Controller/Prod/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Alchemy\Phrasea\WorkerManager\Event\WorkerEvents;
use DOMDocument;
use DOMXPath;
use Exception;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -61,8 +62,10 @@ public function displayMultiExport(Request $request)
$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]) ?? []);
$colls_manageable = array_keys($this->getAclForConnectedUser()->get_granted_base([ACL::COLL_MANAGE]) ?? []);
$colls_editable = array_keys($this->getAclForConnectedUser()->get_granted_base([ACL::CANMODIFRECORD]) ?? []);
$colls_imgtoolsable = array_keys($this->getAclForConnectedUser()->get_granted_base([ACL::IMGTOOLS]) ?? []);
$dbox_manageable = array_keys($this->getAclForConnectedUser()->get_granted_sbas([ACL::BAS_MANAGE]) ?? []);

foreach($download->get_elements() as $recordAdapter) {
// check collection only once
Expand Down Expand Up @@ -92,6 +95,16 @@ public function displayMultiExport(Request $request)
$removeable_stamp_by_base[$bid] = $removeable_stamp = true;
}
break;
case 'record_edit':
if (in_array($bid, $colls_editable)) {
$removeable_stamp_by_base[$bid] = $removeable_stamp = true;
}
break;
case 'image_tools':
if (in_array($bid, $colls_imgtoolsable)) {
$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;
Expand Down Expand Up @@ -138,7 +151,9 @@ public function testFtpConnexion(Request $request)
$ftpClient->close();
$msg = $this->app->trans('Connection to FTP succeed');
$success = true;
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}

return $this->app->json([
Expand Down Expand Up @@ -184,7 +199,7 @@ public function exportFtp(Request $request)
\set_export::STAMP_ASYNC,
$request->request->get('stamp_choice') === "REMOVE_STAMP",
false
);
);

$exportFtpId = $download->export_ftp(
$request->request->get('user_dest'),
Expand All @@ -206,7 +221,8 @@ public function exportFtp(Request $request)
'success' => true,
'message' => $this->app->trans('Export saved in the waiting queue')
]);
} catch (\Exception $e) {
}
catch (Exception $e) {
return $this->app->json([
'success' => false,
'message' => $e->getMessage()//$this->app->trans('Something went wrong')
Expand All @@ -217,8 +233,9 @@ public function exportFtp(Request $request)
/**
* Export document by mail
*
* @param Request $request
* @param Request $request
* @return JsonResponse
* @throws Exception
*/
public function exportMail(Request $request)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Alchemy/Phrasea/ControllerProvider/Admin/Databox.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function connect(Application $app)
->before([$this, 'requireManageRightOnSbas'])
->bind('admin_database_submit_collections_order');

/** @uses DataboxController::createCollection */
$controllers->post('/{databox_id}/collection/', 'controller.admin.databox:createCollection')
->before([$this, 'requireManageRightOnSbas'])
->bind('admin_database_submit_collection');
Expand All @@ -97,6 +98,7 @@ public function connect(Application $app)
->before([$this, 'requireManageRightOnSbas'])
->bind('admin_database_display_document_details');

/** @uses DataboxController::mountCollection */
$controllers->post('/{databox_id}/collection/{collection_id}/mount/', 'controller.admin.databox:mountCollection')
->assert('collection_id', '\d+')
->before([$this, 'requireManageRightOnSbas'])
Expand Down
21 changes: 21 additions & 0 deletions lib/Alchemy/Phrasea/Model/Entities/FtpExportElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ class FtpExportElement
*/
private $updated;

/**
* @ORM\Column(type="boolean", options={"default" = 0})
*/
private $toStamp = false;

/**
* Get id
*
Expand Down Expand Up @@ -368,4 +373,20 @@ public function getExport()
{
return $this->export;
}

/**
* @return bool
*/
public function isToStamp(): bool
{
return $this->toStamp;
}

/**
* @param bool $toStamp
*/
public function setToStamp(bool $toStamp)
{
$this->toStamp = $toStamp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function process(array $payload)

foreach($list['files'] as $k_file => $v_file) {
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 {
$record = $this->app->getApplicationBox()->get_databox($v_file['databox_id'])->get_record($v_file['record_id']);
Expand Down
Loading

0 comments on commit 8df3cf5

Please sign in to comment.