mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
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:
@@ -9,6 +9,8 @@
|
||||
*/
|
||||
|
||||
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\Model\Entities\Token;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
@@ -183,7 +185,7 @@ class set_export extends set_abstract
|
||||
|
||||
/** @var record_exportElement $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;
|
||||
}
|
||||
|
||||
@@ -235,11 +237,11 @@ class set_export extends set_abstract
|
||||
|
||||
$display_ftp = [];
|
||||
|
||||
$hasadminright = $app->getAclForUser($app->getAuthenticatedUser())->has_right(\ACL::CANADDRECORD)
|
||||
|| $app->getAclForUser($app->getAuthenticatedUser())->has_right(\ACL::CANDELETERECORD)
|
||||
|| $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_MODIFY_STRUCT);
|
||||
$hasadminright = $app->getAclForUser($app->getAuthenticatedUser())->has_right(ACL::CANADDRECORD)
|
||||
|| $app->getAclForUser($app->getAuthenticatedUser())->has_right(ACL::CANDELETERECORD)
|
||||
|| $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_MODIFY_STRUCT);
|
||||
|
||||
$this->ftp_datas = [];
|
||||
|
||||
@@ -391,6 +393,35 @@ class set_export extends set_abstract
|
||||
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 STAMP_SYNC = 'STAMP_SYNC';
|
||||
const STAMP_ASYNC = 'STAMP_ASYNC';
|
||||
@@ -404,7 +435,7 @@ class set_export extends set_abstract
|
||||
* @return array
|
||||
* @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)) {
|
||||
throw new Exception('No subdefs given');
|
||||
@@ -423,6 +454,13 @@ class set_export extends set_abstract
|
||||
$unicode = $this->app['unicode'];
|
||||
$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 */
|
||||
foreach ($this->elements as $download_element) {
|
||||
|
||||
@@ -443,10 +481,49 @@ class set_export extends set_abstract
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
// 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")
|
||||
// $extension : the extension WITHOUT DOT (ex. "jpg")
|
||||
// $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
|
||||
];
|
||||
|
||||
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
|
||||
if($stampMethod === self::STAMP_SYNC) {
|
||||
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)) {
|
||||
@@ -568,18 +645,32 @@ class set_export extends set_abstract
|
||||
'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)
|
||||
&& $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)) {
|
||||
$tmp_pathfile = [
|
||||
'path' => dirname($path),
|
||||
'file' => basename($path),
|
||||
'to_stamp' => false,
|
||||
'to_watermark' => false
|
||||
];
|
||||
$tmp_pathfile['path'] = dirname($path);
|
||||
$tmp_pathfile['file'] = basename($path);
|
||||
$subdef_ok = true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user