add stamp / no-stamp to export-by-email and export-by-ftp (#4437)

add default (disabled) stamp settings on new collections
add "record_edit" & "image_tools" to conf / export-stamp-choice privilege
This commit is contained in:
jygaulier
2023-12-14 17:20:53 +01:00
committed by GitHub
parent e97751be96
commit 8df3cf55b7
12 changed files with 210 additions and 66 deletions

View File

@@ -15,10 +15,11 @@ use Alchemy\Phrasea\Authentication\ACLProvider;
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;
@@ -103,7 +104,8 @@ class DataboxController extends Controller
$success = true;
$msg = $this->app->trans('Successful removal');
}
} catch (\Exception $e) {
}
catch (Exception $e) {
}
if (!$databox) {
@@ -150,7 +152,8 @@ class DataboxController extends Controller
$value = $labels[$code] ?: null;
$databox->set_label($code, $value);
}
} catch (\Exception $e) {
}
catch (Exception $e) {
$success = false;
}
@@ -190,7 +193,9 @@ class DataboxController extends Controller
try {
$this->getDispatcher()->dispatch(WorkerEvents::POPULATE_INDEX, new PopulateIndexEvent($populateInfo));
$success = true;
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
if ('json' === $request->getRequestFormat()) {
@@ -222,8 +227,8 @@ class DataboxController extends Controller
$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()) {
@@ -255,7 +260,8 @@ class DataboxController extends Controller
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,
@@ -283,7 +289,7 @@ class DataboxController extends Controller
try {
/** @var Authenticator $authenticator */
$authenticator = $this->app->getAuthenticator();
$baseId = \collection::mount_collection(
$baseId = collection::mount_collection(
$this->app,
$this->findDataboxById($databox_id),
$collection_id,
@@ -315,7 +321,8 @@ class DataboxController extends Controller
'databox_id' => $databox_id,
'mount' => 'ok',
]);
} catch (\Exception $e) {
}
catch (Exception $e) {
$connection->rollBack();
return $this->app->redirectPath('admin_database', [
@@ -366,7 +373,8 @@ class DataboxController extends Controller
'error' => 'file-invalid',
]);
}
} catch (\Exception $e) {
}
catch (Exception $e) {
return $this->app->redirectPath('admin_database', [
'databox_id' => $databox_id,
'success' => '0',
@@ -395,8 +403,9 @@ class DataboxController extends Controller
\databox::PIC_PDF
);
$success = true;
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
if ('json' === $request->getRequestFormat()) {
@@ -428,8 +437,9 @@ class DataboxController extends Controller
try {
$this->findDataboxById($databox_id)->clear_logs();
$success = true;
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
if ('json' === $request->getRequestFormat()) {
@@ -465,8 +475,9 @@ class DataboxController extends Controller
try {
$this->findDataboxById($databox_id)->set_viewname($viewName);
$success = true;
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
if ('json' === $request->getRequestFormat()) {
@@ -500,8 +511,9 @@ class DataboxController extends Controller
$databox->unmount_databox();
$success = true;
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
if ('json' === $request->getRequestFormat()) {
@@ -553,8 +565,9 @@ class DataboxController extends Controller
// 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()) {
@@ -612,8 +625,9 @@ class DataboxController extends Controller
$ret['success'] = true;
$ret['msg'] = $this->app->trans('Successful update');
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
return $this->app->json($ret);
@@ -645,11 +659,12 @@ class DataboxController extends Controller
{
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;
}
@@ -684,7 +699,7 @@ class DataboxController extends Controller
* @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', [
@@ -695,7 +710,7 @@ class DataboxController extends Controller
try {
$databox = $this->findDataboxById($databox_id);
$collection = \collection::create(
$collection = collection::create(
$this->app, $databox,
$this->getApplicationBox(),
$name,
@@ -721,7 +736,8 @@ class DataboxController extends Controller
'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(),

View File

@@ -22,6 +22,7 @@ use Alchemy\Phrasea\WorkerManager\Event\ExportFtpEvent;
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;
@@ -62,6 +63,8 @@ class ExportController extends Controller
$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]) ?? []);
$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) {
@@ -92,6 +95,16 @@ class ExportController extends Controller
$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;
@@ -138,7 +151,9 @@ class ExportController extends Controller
$ftpClient->close();
$msg = $this->app->trans('Connection to FTP succeed');
$success = true;
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
return $this->app->json([
@@ -206,7 +221,8 @@ class ExportController extends Controller
'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')
@@ -219,6 +235,7 @@ class ExportController extends Controller
*
* @param Request $request
* @return JsonResponse
* @throws Exception
*/
public function exportMail(Request $request)
{

View File

@@ -72,6 +72,7 @@ class Databox implements ControllerProviderInterface, ServiceProviderInterface
->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');
@@ -97,6 +98,7 @@ class Databox implements ControllerProviderInterface, ServiceProviderInterface
->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'])

View File

@@ -95,6 +95,11 @@ class FtpExportElement
*/
private $updated;
/**
* @ORM\Column(type="boolean", options={"default" = 0})
*/
private $toStamp = false;
/**
* Get id
*
@@ -368,4 +373,20 @@ class FtpExportElement
{
return $this->export;
}
/**
* @return bool
*/
public function isToStamp(): bool
{
return $this->toStamp;
}
/**
* @param bool $toStamp
*/
public function setToStamp(bool $toStamp)
{
$this->toStamp = $toStamp;
}
}

View File

@@ -88,7 +88,7 @@ class ExportMailWorker implements WorkerInterface
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']);

View File

@@ -15,6 +15,8 @@ use Alchemy\Phrasea\Notification\Mail\MailSuccessFTPReceiver;
use Alchemy\Phrasea\Notification\Mail\MailSuccessFTPSender;
use Alchemy\Phrasea\Notification\Receiver;
use Alchemy\Phrasea\WorkerManager\Queue\MessagePublisher;
use Exception;
use ftpClient;
use Psr\Log\LoggerInterface;
use Symfony\Component\Translation\TranslatorInterface;
@@ -83,7 +85,8 @@ class FtpWorker implements WorkerInterface
$em->flush();
$em->commit();
} catch (\Exception $e) {
}
catch (Exception $e) {
$em->rollback();
}
} else {
@@ -101,7 +104,8 @@ class FtpWorker implements WorkerInterface
$em->flush();
$em->commit();
} catch (\Exception $e) {
}
catch (Exception $e) {
$em->rollback();
}
}
@@ -146,7 +150,7 @@ class FtpWorker implements WorkerInterface
try {
$ssl = $export->isSsl();
/** @var \ftpClient $ftp_client */
/** @var ftpClient $ftp_client */
$ftp_client = $this->app['phraseanet.ftp.client'](
$ftp_server, 21, 300, $ssl, $proxy, $proxyport,
$proxyuser, $proxypwd
@@ -156,7 +160,8 @@ class FtpWorker implements WorkerInterface
if ($export->isPassif()) {
try {
$ftp_client->passive(true);
} catch (\Exception $e) {
}
catch (Exception $e) {
$this->logger->debug($e->getMessage());
}
}
@@ -165,7 +170,8 @@ class FtpWorker implements WorkerInterface
try {
$ftp_client->chdir($export->getDestFolder());
$export->setDestfolder('/' . $export->getDestfolder());
} catch (\Exception $e) {
}
catch (Exception $e) {
$this->logger->debug($e->getMessage());
}
} else {
@@ -175,14 +181,16 @@ class FtpWorker implements WorkerInterface
if (trim($export->getFoldertocreate()) != '') {
try {
$ftp_client->mkdir($export->getFoldertocreate());
} catch (\Exception $e) {
}
catch (Exception $e) {
$this->logger->debug($e->getMessage());
}
try {
$new_dir = $ftp_client->add_end_slash($export->getDestfolder())
. $export->getFoldertocreate();
$ftp_client->chdir($new_dir);
} catch (\Exception $e) {
}
catch (Exception $e) {
$this->logger->debug($e->getMessage());
}
}
@@ -223,25 +231,35 @@ class FtpWorker implements WorkerInterface
$localfile = sys_get_temp_dir().'/' . md5($desc . time() . mt_rand());
if (file_put_contents($localfile, $desc) === false) {
throw new \Exception('Impossible de creer un fichier temporaire');
throw new Exception('Impossible de creer un fichier temporaire');
}
} elseif ($subdef == 'caption-yaml') {
}
elseif ($subdef == 'caption-yaml') {
$desc = $this->app['serializer.caption']->serialize($record->get_caption(), CaptionSerializer::SERIALIZE_YAML, $exportElement->isBusinessfields());
$localfile = sys_get_temp_dir().'/' . md5($desc . time() . mt_rand());
if (file_put_contents($localfile, $desc) === false) {
throw new \Exception('Impossible de creer un fichier temporaire');
throw new Exception('Impossible de creer un fichier temporaire');
}
} else {
}
else {
try {
$sd = $record->get_subdef($subdef);
} catch (\Exception_Media_SubdefNotFound $notFount) {
$localfile = $sd->getRealPath();
if($exportElement->isToStamp()) {
if (!is_null($path = \recordutils_image::stamp($this->app, $sd))) {
// stamped !
$localfile = $path;
}
}
}
catch (\Exception_Media_SubdefNotFound $notFound) {
continue;
}
$localfile = $sd->getRealPath();
if (!file_exists($localfile)) {
throw new \Exception('Le fichier local n\'existe pas');
if (!$localfile || !file_exists($localfile)) {
throw new Exception('Le fichier local n\'existe pas');
}
}
@@ -250,7 +268,8 @@ class FtpWorker implements WorkerInterface
if ($ftp_client->pwd() != $current_folder) {
try {
$ftp_client->chdir($current_folder);
} catch (\Exception $e) {
}
catch (Exception $e) {
$this->logger->debug($e->getMessage());
}
}
@@ -272,7 +291,8 @@ class FtpWorker implements WorkerInterface
$this->app['orm.em']->persist($exportElement);
$this->app['orm.em']->flush();
$this->logexport($this->app, $record, $obj, $ftpLog);
} catch (\Exception $e) {
}
catch (Exception $e) {
$state .= $line = $this->translator->trans('task::ftp:File "%file%" (record %record_id%) de la base "%basename%" (Export du Document) : Transfert cancelled (le document n\'existe plus)', ['%file%' => basename($localfile), '%record_id%' => $record_id, '%basename%' => \phrasea::sbas_labels(\phrasea::sbasFromBas($this->app, $base_id), $this->app)]) . "\n<br/>";
$this->logger->debug($line);
@@ -317,7 +337,8 @@ class FtpWorker implements WorkerInterface
}
$ftp_client->close();
} catch (\Exception $e) {
}
catch (Exception $e) {
$state .= $line = $e . "\n";
$this->logger->debug($line);
@@ -342,7 +363,8 @@ class FtpWorker implements WorkerInterface
$em->persist($workerRunningJob);
$em->flush();
$em->commit();
} catch (\Exception $e) {
}
catch (Exception $e) {
$em->rollback();
}
} else {
@@ -360,7 +382,8 @@ class FtpWorker implements WorkerInterface
$em->persist($workerRunningJob);
$em->flush();
$em->commit();
} catch (\Exception $e) {
}
catch (Exception $e) {
$em->rollback();
}
@@ -472,7 +495,9 @@ class FtpWorker implements WorkerInterface
$mail = MailSuccessFTPSender::create($app, $receiver, null, $sender_message);
$mail->setServer($ftp_server);
$this->deliver($mail);
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
try {
@@ -480,7 +505,8 @@ class FtpWorker implements WorkerInterface
$mail = MailSuccessFTPReceiver::create($app, $receiver, null, $receiver_message);
$mail->setServer($ftp_server);
$this->deliver($mail);
} catch (\Exception $e) {
}
catch (Exception $e) {
$this->logger->debug(sprintf('Unable to deliver success message : %s', $e->getMessage()));
}
}

View File

@@ -66,6 +66,19 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
$repository = self::getRepository($app, $databoxId);
$collection = new CollectionVO($databoxId, 0, $name);
$dom = new \DOMDocument();
try {
if(!@$dom->load($app['root.path'] . '/lib/conf.d/collection_settings.xml')) {
$dom = null;
}
}
catch (Exception $e) {
$dom = null;
}
if($dom) {
$collection->setPreferences($dom->saveXML());
}
$repository->save($collection);
$repository = $app['repo.collection-references'];

View File

@@ -1339,9 +1339,9 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
/**
* @param $metadatas
* @throws Exception
* @throws Exception|Exception_InvalidArgument
*
* nb : use of "silent" @ operator on stdClass member access (equals null in not defined) is more simple than "iseet()" or "empty()"
* nb : use of "silent" @ operator on stdClass member access (equals null if not defined) is more simple than "isset()" or "empty()"
*/
private function do_metadatas(array $metadatas)
{

View File

@@ -459,6 +459,8 @@ class set_export extends set_abstract
$stamp_by_base = []; // unset: no stamp ; false: stamp not "unstampable" ; true: stamp "unstampable"
$colls_manageable = array_keys($this->getAclForUser($user)->get_granted_base([ACL::COLL_MANAGE]) ?? []);
$colls_editable = array_keys($this->getAclForUser($user)->get_granted_base([ACL::CANMODIFRECORD]) ?? []);
$colls_imgtoolsable = array_keys($this->getAclForUser($user)->get_granted_base([ACL::IMGTOOLS]) ?? []);
$dbox_manageable = array_keys($this->getAclForUser($user)->get_granted_sbas([ACL::BAS_MANAGE]) ?? []);
/** @var record_exportElement $download_element */
@@ -511,6 +513,16 @@ class set_export extends set_abstract
$stamp_by_base[$bid] = self::NO_STAMP;
}
break;
case 'record_edit':
if (in_array($bid, $colls_editable)) {
$stamp_by_base[$bid] = self::NO_STAMP;
}
break;
case 'image_tools':
if (in_array($bid, $colls_imgtoolsable)) {
$stamp_by_base[$bid] = self::NO_STAMP;
}
break;
case 'manage_databox':
if (in_array($download_element->getDatabox()->get_sbas_id(), $dbox_manageable)) {
$stamp_by_base[$bid] = self::NO_STAMP;

View File

@@ -83,7 +83,8 @@ class set_exportftp extends set_export
->setFilename($filename)
->setFolder($properties['folder'])
->setRecordId($file['record_id'])
->setSubdef($subdef);
->setSubdef($subdef)
->setToStamp($file['to_stamp'] !== set_export::NO_STAMP);
$export->addElement($element);
$this->app['orm.em']->persist($element);

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<baseprefs>
<!--
<status>0</status>
<caninscript>0</caninscript>
-->
<!-- stamper settings -->
<!-- color = "R,G,B,t" with R,G,B: [0...255] ; trancparency: [0 (opaque)...127 (transparent)] -->
<!--
<stamp position="top-over" background="255,255,255,40">
<text size="250%" color="255,255,0,32" shadow="0,0,0,64">Record-id : <var name="RECORD_ID"/></text>
<text size="120%" color="255,255,255,0" shadow="0,0,0,0">Title : <field name="Title"/></text>
<text size="100%" color="255,255,255,0" shadow="0,0,0,0">Creator : <field name="Creator"/></text>
</stamp>
<stamp position="bottom-over" background="255,255,255,127">
<logo position="left" width="25%"/>
<text size="100%" color="255,255,255,0" shadow="0,0,0,50">Date export : <var name="DATE"/></text>
</stamp>
-->
</baseprefs>

View File

@@ -171,9 +171,9 @@
</div>
{% endif %}
{% 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="REMOVE_STAMP" />
<div class="well-small" style="margin-left: 20px;" >
<label for="export_stamp_choice" class="checkbox">
<input class="stamp_choice" type="checkbox" id="export_stamp_choice" name="stamp_choice" value="REMOVE_STAMP" />
{{ 'prod::download: delete-marking-stamp' | trans }}
</label>
</div>
@@ -249,6 +249,14 @@
{% endif %}
{% endfor %}
</div>
{% if removeable_stamp and download.has_stamp_option() == true %}
<div class="well-small" style="margin-left: 20px;" >
<label for="email_stamp_choice" class="checkbox">
<input class="stamp_choice" type="checkbox" id="email_stamp_choice" name="stamp_choice" value="REMOVE_STAMP" />
{{ 'prod::download: delete-marking-stamp' | trans }}
</label>
</div>
{% endif %}
{% if download.has_business_fields_access() %}
<div class="businessfields well-small" style="margin-left:20px;display:none;">
<label for="business_sendmail" class="checkbox">
@@ -478,6 +486,14 @@
</div>
{% endif %}
{% endfor %}
{% if removeable_stamp and download.has_stamp_option() == true %}
<div class="well-small" style="margin-left: 20px;" >
<label for="ftp_stamp_choice" class="checkbox">
<input class="stamp_choice" type="checkbox" id="ftp_stamp_choice" name="stamp_choice" value="REMOVE_STAMP" />
{{ 'prod::download: delete-marking-stamp' | trans }}
</label>
</div>
{% endif %}
</div>
{% if download.has_business_fields_access() %}
<div class="businessfields" style="margin-left:20px;display:none;">