PHRAS-3520_stamper-enhance (#4385)

* WIP DO NOT MERGE
add: stamp subdefs of class "preview"
apply watermark on stamped subdef (cache to be fixed)
fix: admin/collection settings (new ux, clean xml)

* WIP DO NOT MERGE
add: stamp subdefs of class "preview"
apply watermark on stamped subdef (cache to be fixed)
fix: admin/collection settings (new ux, clean xml)

* conf.export_stamp_choice now supports 'manage_collection' and 'manage_databox' (and bc true) to restrict right to remove stamp.

* fix test

* WIP DO NOT MERGE
add: stamp subdefs of class "preview"
apply watermark on stamped subdef (cache to be fixed)
fix: admin/collection settings (new ux, clean xml)

* conf.export_stamp_choice now supports 'manage_collection' and 'manage_databox' (and bc true) to restrict right to remove stamp.

* fix test

* fix compatibility with download-async ; add registry/actions/stamp-subdefs=false to conf
This commit is contained in:
jygaulier
2023-11-22 12:30:55 +01:00
committed by GitHub
parent 1ccba2d9a0
commit 07f4462672
11 changed files with 732 additions and 857 deletions

View File

@@ -279,6 +279,7 @@ registry:
api-subdef_service: false api-subdef_service: false
actions: actions:
export-stamp-choice: false export-stamp-choice: false
stamp-subdefs: false
crossdomain: crossdomain:
site-control: 'master-only' site-control: 'master-only'
allow-access-from: allow-access-from:

View File

@@ -803,7 +803,9 @@ class CollectionController extends Controller
try { try {
if ('' !== trim($prefs)) { if ('' !== trim($prefs)) {
$domdoc = new \DOMDocument(); $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); $collection->set_prefs($domdoc);
$success = true; $success = true;
} }

View File

@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
use Alchemy\Phrasea\Core\Event\DownloadAsyncEvent; use Alchemy\Phrasea\Core\Event\DownloadAsyncEvent;
use Alchemy\Phrasea\Core\Event\ExportEvent; use Alchemy\Phrasea\Core\Event\ExportEvent;
use Alchemy\Phrasea\Core\PhraseaEvents; use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Filesystem\PhraseanetFilesystem;
use Alchemy\Phrasea\Model\Manipulator\TokenManipulator; use Alchemy\Phrasea\Model\Manipulator\TokenManipulator;
use set_export; use set_export;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
@@ -42,7 +43,7 @@ class DownloadController extends Controller
$ssttid = $request->request->get('ssttid', ''); $ssttid = $request->request->get('ssttid', '');
$subdefs = $request->request->get('obj', []); $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()) { if (0 === $download->get_total_download()) {
$this->app->abort(403); $this->app->abort(403);
@@ -50,11 +51,13 @@ class DownloadController extends Controller
$list = $download->prepare_export( $list = $download->prepare_export(
$this->getAuthenticatedUser(), $this->getAuthenticatedUser(),
$this->app['filesystem'], $this->getFilesystem(),
$subdefs, $subdefs,
$request->request->get('type') === 'title' ? true : false, $request->request->get('type') === 'title' ? true : false,
$request->request->get('businessfields'), $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()); $list['export_name'] = sprintf('%s.zip', $download->getExportName());
@@ -89,7 +92,7 @@ class DownloadController extends Controller
$ssttid = $request->request->get('ssttid', ''); $ssttid = $request->request->get('ssttid', '');
$subdefs = $request->request->get('obj', []); $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()) { if (0 === $download->get_total_download()) {
$this->app->abort(403); $this->app->abort(403);
@@ -103,12 +106,12 @@ class DownloadController extends Controller
$list = $download->prepare_export( $list = $download->prepare_export(
$this->getAuthenticatedUser(), $this->getAuthenticatedUser(),
$this->app['filesystem'], $this->getFilesystem(),
$subdefs, $subdefs,
$request->request->get('type') === 'title' ? true : false, $request->request->get('type') === 'title' ? true : false,
$request->request->get('businessfields'), $request->request->get('businessfields'),
// do not stamp now, worker will do set_export::STAMP_ASYNC,
$stamp_method, $request->request->get('stamp_choice') === "REMOVE_STAMP",
true true
); );
$list['export_name'] = sprintf('%s.zip', $download->getExportName()); $list['export_name'] = sprintf('%s.zip', $download->getExportName());
@@ -212,4 +215,11 @@ class DownloadController extends Controller
{ {
return $this->app['session']; return $this->app['session'];
} }
/**
* @return PhraseanetFilesystem
*/
private function getFilesystem()
{
return $this->app['filesystem'];
}
} }

View File

@@ -9,6 +9,7 @@
*/ */
namespace Alchemy\Phrasea\Controller\Prod; namespace Alchemy\Phrasea\Controller\Prod;
use ACL;
use Alchemy\Phrasea\Application\Helper\DispatcherAware; use Alchemy\Phrasea\Application\Helper\DispatcherAware;
use Alchemy\Phrasea\Application\Helper\FilesystemAware; use Alchemy\Phrasea\Application\Helper\FilesystemAware;
use Alchemy\Phrasea\Application\Helper\NotifierAware; use Alchemy\Phrasea\Application\Helper\NotifierAware;
@@ -19,6 +20,8 @@ use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Model\Manipulator\TokenManipulator; use Alchemy\Phrasea\Model\Manipulator\TokenManipulator;
use Alchemy\Phrasea\WorkerManager\Event\ExportFtpEvent; use Alchemy\Phrasea\WorkerManager\Event\ExportFtpEvent;
use Alchemy\Phrasea\WorkerManager\Event\WorkerEvents; use Alchemy\Phrasea\WorkerManager\Event\WorkerEvents;
use DOMDocument;
use DOMXPath;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@@ -29,6 +32,15 @@ class ExportController extends Controller
use FilesystemAware; use FilesystemAware;
use NotifierAware; use NotifierAware;
/**
* @return ACL
*/
private function getAclForConnectedUser()
{
return $this->getAclForUser($this->getAuthenticatedUser());
}
/** /**
* Display form to export documents * Display form to export documents
* *
@@ -44,17 +56,63 @@ class ExportController extends Controller
$request->request->get('story') $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('prodExportDownload');
$this->setSessionFormToken('prodExportEmail'); $this->setSessionFormToken('prodExportEmail');
$this->setSessionFormToken('prodExportFTP'); $this->setSessionFormToken('prodExportFTP');
$this->setSessionFormToken('prodExportOrder'); $this->setSessionFormToken('prodExportOrder');
return new Response($this->render('common/dialog_export.html.twig', [ return new Response($this->render('common/dialog_export.html.twig', [
'download' => $download, 'download' => $download,
'ssttid' => $request->request->get('ssel'), 'ssttid' => $request->request->get('ssel'),
'lst' => $download->serialize_list(), 'lst' => $download->serialize_list(),
'default_export_title' => $this->getConf()->get(['registry', 'actions', 'default-export-title']), 'default_export_title' => $this->getConf()->get(['registry', 'actions', 'default-export-title']),
'choose_export_title' => $this->getConf()->get(['registry', 'actions', 'export-title-choice']) 'choose_export_title' => $this->getConf()->get(['registry', 'actions', 'export-title-choice']),
'removeable_stamp' => $removeable_stamp,
'removeable_stamp_by_base' => $removeable_stamp_by_base,
])); ]));
} }
@@ -123,7 +181,9 @@ class ExportController extends Controller
$request->request->get('obj'), $request->request->get('obj'),
false, false,
$request->request->get('businessfields'), $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( $exportFtpId = $download->export_ftp(
@@ -181,7 +241,8 @@ class ExportController extends Controller
(array) $request->request->get('obj'), (array) $request->request->get('obj'),
$request->request->get("type") == "title" ? : false, $request->request->get("type") == "title" ? : false,
$request->request->get('businessfields'), $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 true
); );

View File

@@ -52,10 +52,12 @@ class Collection implements ControllerProviderInterface, ServiceProviderInterfac
->assert('bas_id', '\d+') ->assert('bas_id', '\d+')
->bind('admin_display_collection'); ->bind('admin_display_collection');
/** @uses CollectionController::getSuggestedValues */
$controllers->get('/{bas_id}/suggested-values/', 'controller.admin.collection:getSuggestedValues') $controllers->get('/{bas_id}/suggested-values/', 'controller.admin.collection:getSuggestedValues')
->assert('bas_id', '\d+') ->assert('bas_id', '\d+')
->bind('admin_collection_display_suggested_values'); ->bind('admin_collection_display_suggested_values');
/** @uses CollectionController::submitSuggestedValues */
$controllers->post('/{bas_id}/suggested-values/', 'controller.admin.collection:submitSuggestedValues') $controllers->post('/{bas_id}/suggested-values/', 'controller.admin.collection:submitSuggestedValues')
->assert('bas_id', '\d+') ->assert('bas_id', '\d+')
->bind('admin_collection_submit_suggested_values'); ->bind('admin_collection_submit_suggested_values');

View File

@@ -189,7 +189,16 @@ class ApiOrderController extends BaseOrderController
$subdefs = $this->findDataboxSubdefNames(); $subdefs = $this->findDataboxSubdefNames();
try { 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) { catch (\Exception $e) {
throw new NotFoundHttpException(sprintf('No archive could be downloaded for Order "%d"', $order->getId())); throw new NotFoundHttpException(sprintf('No archive could be downloaded for Order "%d"', $order->getId()));

View File

@@ -218,7 +218,7 @@ class DownloadAsyncWorker implements WorkerInterface
} }
foreach($v_file['subdefs'] as $k_subdef => $v_subdef) { 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 // we must stamp this document
try { try {
if(!$record) { if(!$record) {

View File

@@ -15,6 +15,7 @@ use Imagine\Exception\Exception as ImagineException;
use Imagine\Image\Box; use Imagine\Image\Box;
use Imagine\Image\ImagineInterface; use Imagine\Image\ImagineInterface;
use Imagine\Image\Palette\RGB; use Imagine\Image\Palette\RGB;
use Imagine\Image\Palette\Color\ColorInterface;
use Imagine\Image\Point; use Imagine\Image\Point;
use MediaVorus\Media\Image; use MediaVorus\Media\Image;
use MediaVorus\Media\MediaInterface; use MediaVorus\Media\MediaInterface;
@@ -47,19 +48,22 @@ class recordutils_image
} }
$xmlToColor = function ($attr, $ret = [255, 255, 255]) use ($palette) { $xmlToColor = function ($attr, $ret = [255, 255, 255]) use ($palette) {
try { if($attr !== null) {
$alpha = 100; try {
$attr = explode(',', $attr); $alpha = 100;
if (count($attr) == 4) { $attr = explode(',', $attr);
// 0..127 -> 100..0 if (count($attr) == 4) {
$alpha = (int)((127 - (int)array_pop($attr)) / 1.27); // 0..127 -> 100..0
} $alpha = (int)((127 - (int)array_pop($attr)) / 1.27);
}
return $palette->color($attr, $alpha); return $palette->color($attr, $alpha);
} }
catch (ImagineException $e) { catch (ImagineException $e) {
return $palette->color($ret); return $palette->color($ret);
}
} }
return null;
}; };
$base_id = $subdef->get_record()->getBaseId(); $base_id = $subdef->get_record()->getBaseId();
@@ -287,10 +291,11 @@ class recordutils_image
if ($txtline != '') { if ($txtline != '') {
$wrap = static::wrap($imagine, $fontsize, 0, __DIR__ . '/../../../resources/Fonts/arial.ttf', $txtline, $text_width); $wrap = static::wrap($imagine, $fontsize, 0, __DIR__ . '/../../../resources/Fonts/arial.ttf', $txtline, $text_width);
$txtblock[] = [ $txtblock[] = [
'fontsize' => $fontsize, 'fontsize' => $fontsize,
'fontcolor' => $xmlToColor($texts->item($i)->getAttribute('color'), [0, 0, 0]), 'fontcolor' => $xmlToColor($texts->item($i)->getAttribute('color'), [0, 0, 0]),
'h' => $wrap['toth'], 'shadowcolor' => $xmlToColor($texts->item($i)->getAttribute('shadow'), [0, 0, 0, 127]),
'lines' => $wrap['l'] 'h' => $wrap['toth'],
'lines' => $wrap['l'],
]; ];
$txth += $wrap['toth']; $txth += $wrap['toth'];
} }
@@ -327,10 +332,22 @@ class recordutils_image
$draw = $imfg->draw(); $draw = $imfg->draw();
$txt_ypos = 0; $txt_ypos = 0;
foreach ($txtblock as $block) { foreach ($txtblock as $block) {
$font = $imagine->font(__DIR__ . '/../../../resources/Fonts/arial.ttf', $block['fontsize'], $block['fontcolor']); /** @var ColorInterface $color */
$color = $block['fontcolor'];
$font = $imagine->font(__DIR__ . '/../../../resources/Fonts/arial.ttf', $block['fontsize'], $color);
$shadowFont = null;
$shadowDelta = 0;
if($block['shadowcolor'] !== null) {
$shadowFont = $imagine->font(__DIR__ . '/../../../resources/Fonts/arial.ttf', $block['fontsize'], $block['shadowcolor']);
$shadowDelta = max(2, (int)($block['fontsize'] / 20));
}
foreach ($block['lines'] as $line) { foreach ($block['lines'] as $line) {
if ($line['t'] != '') { if ($line['t'] != '') {
$draw->text($line['t'], $font, new Point($logo_reswidth, $txt_ypos), 0); if($shadowFont) {
$draw->text($line['t'], $shadowFont, new Point($logo_reswidth, $txt_ypos + $shadowDelta), 0);
$draw->text($line['t'], $shadowFont, new Point($logo_reswidth+1, $txt_ypos + $shadowDelta*1.5), 0);
}
$draw->text($line['t'], $font, new Point($logo_reswidth + $shadowDelta, $txt_ypos), 0);
} }
$txt_ypos += $line['h']; $txt_ypos += $line['h'];
} }
@@ -354,7 +371,7 @@ class recordutils_image
$newh = $tables['TOP']['h'] + $image_height + $tables['BOTTOM']['h']; $newh = $tables['TOP']['h'] + $image_height + $tables['BOTTOM']['h'];
// create the output image // create the output image
$image_out = $imagine->create(new Box($image_width, $newh), $palette->color("FFFFFF", 64)); $image_out = $imagine->create(new Box($image_width, $newh), $palette->color("FFFFFF"));
// paste the input image into // paste the input image into
$image_out->paste($image_in, new Point(0, $tables['TOP']['h'])); $image_out->paste($image_in, new Point(0, $tables['TOP']['h']));
@@ -414,7 +431,7 @@ class recordutils_image
* *
* @return boolean|string * @return boolean|string
*/ */
public static function watermark(Application $app, media_subdef $subdef) public static function watermark(Application $app, media_subdef $subdef, $otherPath = null)
{ {
static $palette; static $palette;
@@ -436,7 +453,7 @@ class recordutils_image
return false; return false;
} }
$pathIn = $subdef->getRealPath(); $pathIn = $otherPath ?? $subdef->getRealPath();
if (!is_file($pathIn)) { if (!is_file($pathIn)) {
return false; return false;

View File

@@ -9,6 +9,8 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Authentication\ACLProvider;
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
use Alchemy\Phrasea\Filesystem\PhraseanetFilesystem as Filesystem; use Alchemy\Phrasea\Filesystem\PhraseanetFilesystem as Filesystem;
use Alchemy\Phrasea\Model\Entities\Token; use Alchemy\Phrasea\Model\Entities\Token;
use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Entities\User;
@@ -183,7 +185,7 @@ class set_export extends set_abstract
/** @var record_exportElement $download_element */ /** @var record_exportElement $download_element */
foreach ($this->get_elements() as $download_element) { foreach ($this->get_elements() as $download_element) {
if ($app->getAclForUser($app->getAuthenticatedUser())->has_right_on_base($download_element->getBaseId(), \ACL::CANMODIFRECORD)) { if ($app->getAclForUser($app->getAuthenticatedUser())->has_right_on_base($download_element->getBaseId(), ACL::CANMODIFRECORD)) {
$this->businessFieldsAccess = true; $this->businessFieldsAccess = true;
} }
@@ -235,11 +237,11 @@ class set_export extends set_abstract
$display_ftp = []; $display_ftp = [];
$hasadminright = $app->getAclForUser($app->getAuthenticatedUser())->has_right(\ACL::CANADDRECORD) $hasadminright = $app->getAclForUser($app->getAuthenticatedUser())->has_right(ACL::CANADDRECORD)
|| $app->getAclForUser($app->getAuthenticatedUser())->has_right(\ACL::CANDELETERECORD) || $app->getAclForUser($app->getAuthenticatedUser())->has_right(ACL::CANDELETERECORD)
|| $app->getAclForUser($app->getAuthenticatedUser())->has_right(\ACL::CANMODIFRECORD) || $app->getAclForUser($app->getAuthenticatedUser())->has_right(ACL::CANMODIFRECORD)
|| $app->getAclForUser($app->getAuthenticatedUser())->has_right(\ACL::COLL_MANAGE) || $app->getAclForUser($app->getAuthenticatedUser())->has_right(ACL::COLL_MANAGE)
|| $app->getAclForUser($app->getAuthenticatedUser())->has_right(\ACL::COLL_MODIFY_STRUCT); || $app->getAclForUser($app->getAuthenticatedUser())->has_right(ACL::COLL_MODIFY_STRUCT);
$this->ftp_datas = []; $this->ftp_datas = [];
@@ -391,6 +393,35 @@ class set_export extends set_abstract
return $this->total_ftp; return $this->total_ftp;
} }
/**
* @return ACLProvider
*/
private function getAclProvider()
{
return $this->app['acl'];
}
/**
* Gets ACL for user.
*
* @param User $user
*
* @return ACL
*/
private function getAclForUser(User $user)
{
return $this->getAclProvider()->get($user);
}
/**
* @return PropertyAccess
*/
protected function getConf()
{
return $this->app['conf'];
}
const NO_STAMP = 'NO_STAMP'; const NO_STAMP = 'NO_STAMP';
const STAMP_SYNC = 'STAMP_SYNC'; const STAMP_SYNC = 'STAMP_SYNC';
const STAMP_ASYNC = 'STAMP_ASYNC'; const STAMP_ASYNC = 'STAMP_ASYNC';
@@ -404,7 +435,7 @@ class set_export extends set_abstract
* @return array * @return array
* @throws Exception * @throws Exception
*/ */
public function prepare_export(User $user, Filesystem $filesystem, Array $wantedSubdefs, $rename_title, $includeBusinessFields, $stampMethod, $exportEmail = false) public function prepare_export(User $user, Filesystem $filesystem, Array $wantedSubdefs, $rename_title, $includeBusinessFields, $stampMethod, $removeStamp, $exportEmail = false)
{ {
if (!is_array($wantedSubdefs)) { if (!is_array($wantedSubdefs)) {
throw new Exception('No subdefs given'); throw new Exception('No subdefs given');
@@ -423,6 +454,13 @@ class set_export extends set_abstract
$unicode = $this->app['unicode']; $unicode = $this->app['unicode'];
$hasCgu = false; $hasCgu = false;
// we must propose "do not stamp" when at least one collection is stamped AND the user has right to
// remove stamp on this collection
$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]) ?? []);
$dbox_manageable = array_keys($this->getAclForUser($user)->get_granted_sbas([ACL::BAS_MANAGE]) ?? []);
/** @var record_exportElement $download_element */ /** @var record_exportElement $download_element */
foreach ($this->elements as $download_element) { foreach ($this->elements as $download_element) {
@@ -443,10 +481,49 @@ class set_export extends set_abstract
$BF = false; $BF = false;
if ($includeBusinessFields && $this->app->getAclForUser($user)->has_right_on_base($download_element->getBaseId(), \ACL::CANMODIFRECORD)) { if ($includeBusinessFields && $this->app->getAclForUser($user)->has_right_on_base($download_element->getBaseId(), ACL::CANMODIFRECORD)) {
$BF = true; $BF = true;
} }
// check if stamp can be removed
// check collection only once
if(!array_key_exists($bid = $download_element->getCollection()->get_base_id(), $stamp_by_base)) {
// check stamp
$stamp_by_base[$bid] = self::NO_STAMP;
$domprefs = new DOMDocument();
if ($domprefs->loadXML($download_element->getCollection()->get_prefs())) {
$xpprefs = new DOMXPath($domprefs);
if ($xpprefs->query('/baseprefs/stamp')->length != 0) {
// the collection has stamp settings
unset($domprefs);
// the collection has stamp, check user's right to remove it
$stamp_by_base[$bid] = $stampMethod;
if($removeStamp) { // user asked to remove stamp
switch ((string)$this->getConf()->get(['registry', 'actions', 'export-stamp-choice'], false)) {
case '1': // == (string)true
// everybody can remove stamp (bc)
$stamp_by_base[$bid] = self::NO_STAMP;
break;
case 'manage_collection':
if (in_array($bid, $colls_manageable)) {
$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;
}
break;
}
}
}
}
}
$files[$id]['to_stamp'] = $stamp_by_base[$bid];
// $original_name : the original_name WITHOUT extension (ex. "DSC_1234") // $original_name : the original_name WITHOUT extension (ex. "DSC_1234")
// $extension : the extension WITHOUT DOT (ex. "jpg") // $extension : the extension WITHOUT DOT (ex. "jpg")
// $export_name : the export name WITHOUT extension, (ex. "Hollydays_2016_DSC_1234") // $export_name : the export name WITHOUT extension, (ex. "Hollydays_2016_DSC_1234")
@@ -539,9 +616,9 @@ class set_export extends set_abstract
'to_watermark' => false 'to_watermark' => false
]; ];
if($this->app['conf']->get(['registry', 'actions', 'export-stamp-choice']) !== true || $stampMethod !== self::NO_STAMP ){ if($files[$id]['to_stamp'] !== self::NO_STAMP){
// stamp is mandatory, or user did not check "no stamp" : we must apply stamp // stamp is mandatory, or user did not check "no stamp" : we must apply stamp
if($stampMethod === self::STAMP_SYNC) { if($files[$id]['to_stamp'] === self::STAMP_SYNC) {
// we prepare a direct download, we must stamp now // we prepare a direct download, we must stamp now
$path = \recordutils_image::stamp($this->app, $sd[$subdefName]); $path = \recordutils_image::stamp($this->app, $sd[$subdefName]);
if ($path && file_exists($path)) { if ($path && file_exists($path)) {
@@ -568,18 +645,32 @@ class set_export extends set_abstract
'to_watermark' => false 'to_watermark' => false
]; ];
if (!$this->app->getAclForUser($user)->has_right_on_base($download_element->getBaseId(), \ACL::NOWATERMARK) $stampedPath = null;
if($files[$id]['to_stamp'] !== self::NO_STAMP && $this->getConf()->get(['registry', 'actions', 'stamp-subdefs'], false) === true){
// stamp is mandatory, or user did not check "no stamp" : we must apply stamp
if($files[$id]['to_stamp'] === self::STAMP_SYNC) {
// we prepare a direct download, we must stamp now
$path = \recordutils_image::stamp($this->app, $sd[$subdefName]);
if ($path && file_exists($path)) {
$stampedPath = $path;
$tmp_pathfile['path'] = dirname($path);
$tmp_pathfile['file'] = basename($path);
}
}
else {
// we prepare an email or ftp download : the worker will apply stamp
$tmp_pathfile ['to_stamp'] = true;
}
}
if (!$this->app->getAclForUser($user)->has_right_on_base($download_element->getBaseId(), ACL::NOWATERMARK)
&& !$this->app->getAclForUser($user)->has_preview_grant($download_element) && !$this->app->getAclForUser($user)->has_preview_grant($download_element)
&& $sd[$subdefName]->get_type() == media_subdef::TYPE_IMAGE ) && $sd[$subdefName]->get_type() == media_subdef::TYPE_IMAGE )
{ {
$path = recordutils_image::watermark($this->app, $sd[$subdefName]); $path = recordutils_image::watermark($this->app, $sd[$subdefName], $stampedPath);
if (file_exists($path)) { if (file_exists($path)) {
$tmp_pathfile = [ $tmp_pathfile['path'] = dirname($path);
'path' => dirname($path), $tmp_pathfile['file'] = basename($path);
'file' => basename($path),
'to_stamp' => false,
'to_watermark' => false
];
$subdef_ok = true; $subdef_ok = true;
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -170,8 +170,8 @@
</label> </label>
</div> </div>
{% endif %} {% endif %}
{% if app['conf'].get(['registry', 'actions', 'export-stamp-choice']) == true and download.has_stamp_option() == true %} {% if removeable_stamp and download.has_stamp_option() == true %}
<div id="stamp_choice" class="well-small hide" style="margin-left: 20px;" > <div id="stamp_choice" class="well-small" style="margin-left: 20px;" >
<label for="option_stamp" class="checkbox"> <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="NO_STAMP" />
{{ 'prod::download: delete-marking-stamp' | trans }} {{ 'prod::download: delete-marking-stamp' | trans }}
@@ -540,14 +540,6 @@
$(document).find(".tagsinput").tagsinput('add', $(this).val()); $(document).find(".tagsinput").tagsinput('add', $(this).val());
$(this).val(''); $(this).val('');
}); });
$('#download_document').click(function(){
if($(this).is(':checked')){
$('#download_stamp_choice').show();
} else{
$('#download_stamp_choice').hide();
}
});
</script> </script>
{% endif %} {% endif %}