From 199b5b1c461d0fd569d35a50b22c20b64c0eb241 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Tue, 25 Oct 2016 13:55:34 +0200 Subject: [PATCH 01/42] Inject base order controller dependencies --- .../Phrasea/ControllerProvider/Api/V2.php | 11 ++++- .../Phrasea/ControllerProvider/Prod/Order.php | 10 ++++- .../Order/Controller/ApiOrderController.php | 10 ++--- .../Order/Controller/BaseOrderController.php | 43 +++++++++++++++++-- 4 files changed, 62 insertions(+), 12 deletions(-) diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php index 53eee150b5..5ba73d2a11 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php @@ -54,12 +54,21 @@ class V2 extends Api implements ControllerProviderInterface, ServiceProviderInte $app['controller.api.v2.orders'] = $app->share( function (PhraseaApplication $app) { - return (new ApiOrderController($app)) + $controller = new ApiOrderController( + $app, + $app['repo.orders'], + $app['repo.order-elements'], + $app['provider.order_basket'] + ); + + $controller ->setDispatcher($app['dispatcher']) ->setEntityManagerLocator(new LazyLocator($app, 'orm.em')) ->setDelivererLocator(new LazyLocator($app, 'phraseanet.file-serve')) ->setFileSystemLocator(new LazyLocator($app, 'filesystem')) ->setJsonBodyHelper($app['json.body_helper']); + + return $controller; } ); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Order.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Order.php index 983bacdbad..53db922c72 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Order.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Order.php @@ -12,8 +12,8 @@ namespace Alchemy\Phrasea\ControllerProvider\Prod; use Alchemy\Phrasea\Application as PhraseaApplication; -use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; +use Alchemy\Phrasea\Core\LazyLocator; use Alchemy\Phrasea\Order\Controller\ProdOrderController; use Alchemy\Phrasea\Order\OrderBasketProvider; use Alchemy\Phrasea\Order\OrderValidator; @@ -39,7 +39,13 @@ class Order implements ControllerProviderInterface, ServiceProviderInterface }); $app['controller.prod.order'] = $app->share(function (PhraseaApplication $app) { - return (new ProdOrderController($app)) + $controller = new ProdOrderController($app, + $app['repo.orders'], + $app['repo.order-elements'], + $app['provider.order_basket'] + ); + + $controller ->setDispatcher($app['dispatcher']) ->setEntityManagerLocator(new LazyLocator($app, 'orm.em')) ->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query')) diff --git a/lib/Alchemy/Phrasea/Order/Controller/ApiOrderController.php b/lib/Alchemy/Phrasea/Order/Controller/ApiOrderController.php index 61c6a2172f..07ead44974 100644 --- a/lib/Alchemy/Phrasea/Order/Controller/ApiOrderController.php +++ b/lib/Alchemy/Phrasea/Order/Controller/ApiOrderController.php @@ -22,6 +22,7 @@ use Alchemy\Phrasea\Http\DeliverDataInterface; use Alchemy\Phrasea\Model\Entities\Basket; use Alchemy\Phrasea\Model\Entities\BasketElement; use Alchemy\Phrasea\Model\Entities\Order; +use Alchemy\Phrasea\Model\Entities\Token; use Alchemy\Phrasea\Order\OrderElementTransformer; use Alchemy\Phrasea\Order\OrderFiller; use Alchemy\Phrasea\Order\OrderTransformer; @@ -88,7 +89,7 @@ class ApiOrderController extends BaseOrderController ]); }; - $builder = $this->app['repo.orders']->createQueryBuilder('o'); + $builder = $this->getOrderRepository()->createQueryBuilder('o'); $builder ->where($builder->expr()->eq('o.user', $this->getAuthenticatedUser()->getId())) ; @@ -138,11 +139,10 @@ class ApiOrderController extends BaseOrderController } /** - * @param Request $request * @param int $orderId * @return Response */ - public function getArchiveAction(Request $request, $orderId) + public function getArchiveAction($orderId) { $order = $this->findOr404($orderId); @@ -166,6 +166,7 @@ class ApiOrderController extends BaseOrderController $exportData = $export->prepare_export($user, $this->getFilesystem(), $subdefs, true, true); $exportData['export_name'] = $exportName; + /** @var Token $token */ $token = $this->app['manipulator.token']->createDownloadToken($user, serialize($exportData)); $lst = []; @@ -180,7 +181,7 @@ class ApiOrderController extends BaseOrderController set_time_limit(0); ignore_user_abort(true); - $file = \set_export::build_zip($this->app, $token, $exportData, $exportName); + $file = \set_export::build_zip($this->app, $token, $exportData, $token->getValue() . '.zip'); return $this->deliverFile($file, $exportName, DeliverDataInterface::DISPOSITION_INLINE, 'application/zip'); } @@ -188,7 +189,6 @@ class ApiOrderController extends BaseOrderController public function acceptElementsAction(Request $request, $orderId) { $elementIds = $this->fetchElementIdsFromRequest($request); - $elements = $this->doAcceptElements($orderId, $elementIds, $this->getAuthenticatedUser()); $resource = new Collection($elements, function (BasketElement $element) { diff --git a/lib/Alchemy/Phrasea/Order/Controller/BaseOrderController.php b/lib/Alchemy/Phrasea/Order/Controller/BaseOrderController.php index f297006ab9..5b2e90d4cb 100644 --- a/lib/Alchemy/Phrasea/Order/Controller/BaseOrderController.php +++ b/lib/Alchemy/Phrasea/Order/Controller/BaseOrderController.php @@ -10,6 +10,7 @@ namespace Alchemy\Phrasea\Order\Controller; +use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application\Helper\DispatcherAware; use Alchemy\Phrasea\Application\Helper\EntityManagerAware; use Alchemy\Phrasea\Controller\Controller; @@ -22,10 +23,10 @@ use Alchemy\Phrasea\Model\Entities\OrderElement; use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Repositories\OrderElementRepository; use Alchemy\Phrasea\Model\Repositories\OrderRepository; +use Alchemy\Phrasea\Order\OrderBasketProvider; use Alchemy\Phrasea\Order\OrderDelivery; use Alchemy\Phrasea\Order\OrderValidator; use Alchemy\Phrasea\Order\PartialOrder; -use Alchemy\Phrasea\Record\RecordReference; use Alchemy\Phrasea\Record\RecordReferenceCollection; use Assert\Assertion; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; @@ -38,12 +39,46 @@ class BaseOrderController extends Controller use DispatcherAware; use EntityManagerAware; + /** + * @var OrderRepository + */ + private $orderRepository; + + /** + * @var OrderElementRepository + */ + private $orderElementRepository; + + /** + * @var OrderBasketProvider + */ + private $orderBasketProvider; + + /** + * @param Application $app + * @param OrderRepository $orderRepository + * @param OrderElementRepository $orderElementRepository + * @param OrderBasketProvider $orderBasketProvider + */ + public function __construct( + Application $app, + OrderRepository $orderRepository, + OrderElementRepository $orderElementRepository, + OrderBasketProvider $orderBasketProvider + ) { + parent::__construct($app); + + $this->orderRepository = $orderRepository; + $this->orderElementRepository = $orderElementRepository; + $this->orderBasketProvider = $orderBasketProvider; + } + /** * @return OrderRepository */ protected function getOrderRepository() { - return $this->app['repo.orders']; + return $this->orderRepository; } /** @@ -51,7 +86,7 @@ class BaseOrderController extends Controller */ protected function getOrderElementRepository() { - return $this->app['repo.order-elements']; + return $this->orderElementRepository; } /** @@ -116,7 +151,7 @@ class BaseOrderController extends Controller $elements = $this->findRequestedElements($order_id, $elementIds, $acceptor); $order = $this->findOr404($order_id); - $basket = $this->app['provider.order_basket']->provideBasketForOrderAndUser($order, $acceptor); + $basket = $this->orderBasketProvider->provideBasketForOrderAndUser($order, $acceptor); $partialOrder = new PartialOrder($order, $elements); From 13c71fd38da1ae81c7513b640f5bfbdddd51cfcc Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Tue, 25 Oct 2016 13:58:55 +0200 Subject: [PATCH 02/42] PHRAS-1275 Fix temporary order archive name --- lib/Alchemy/Phrasea/Order/Controller/ApiOrderController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Alchemy/Phrasea/Order/Controller/ApiOrderController.php b/lib/Alchemy/Phrasea/Order/Controller/ApiOrderController.php index 07ead44974..999c575e76 100644 --- a/lib/Alchemy/Phrasea/Order/Controller/ApiOrderController.php +++ b/lib/Alchemy/Phrasea/Order/Controller/ApiOrderController.php @@ -160,11 +160,9 @@ class ApiOrderController extends BaseOrderController $exportName = sprintf('%s/%s.zip', $this->app['tmp.download.path'], $export->getExportName()); $user = $this->getAuthenticatedUser(); - $subdefs = $this->findDataboxSubdefNames(); $exportData = $export->prepare_export($user, $this->getFilesystem(), $subdefs, true, true); - $exportData['export_name'] = $exportName; /** @var Token $token */ $token = $this->app['manipulator.token']->createDownloadToken($user, serialize($exportData)); From a7028991267f62f70c17ecff929485c685249dd9 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Tue, 25 Oct 2016 14:20:36 +0200 Subject: [PATCH 03/42] Fix missing return statement --- lib/Alchemy/Phrasea/ControllerProvider/Prod/Order.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Order.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Order.php index 53db922c72..c66c53956a 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Order.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Order.php @@ -39,7 +39,8 @@ class Order implements ControllerProviderInterface, ServiceProviderInterface }); $app['controller.prod.order'] = $app->share(function (PhraseaApplication $app) { - $controller = new ProdOrderController($app, + $controller = new ProdOrderController( + $app, $app['repo.orders'], $app['repo.order-elements'], $app['provider.order_basket'] @@ -48,8 +49,9 @@ class Order implements ControllerProviderInterface, ServiceProviderInterface $controller ->setDispatcher($app['dispatcher']) ->setEntityManagerLocator(new LazyLocator($app, 'orm.em')) - ->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query')) - ; + ->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query')); + + return $controller; }); } From f9d496f6c5010f94a9b09e0e1b84446cf0f3d745 Mon Sep 17 00:00:00 2001 From: Xavier Rousset Date: Wed, 26 Oct 2016 12:09:24 +0200 Subject: [PATCH 04/42] Align menu icons on prod view --- resources/www/prod/js/jquery.main-prod.js | 22 +++++++++---------- .../prod/skins/ui-components/_workzone.scss | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/resources/www/prod/js/jquery.main-prod.js b/resources/www/prod/js/jquery.main-prod.js index 015482f247..2107c4e4f0 100644 --- a/resources/www/prod/js/jquery.main-prod.js +++ b/resources/www/prod/js/jquery.main-prod.js @@ -347,7 +347,7 @@ function resize() { if ($('#idFrameC').data('ui-resizable')) { $('#idFrameC').resizable('option', 'maxWidth', (480)); - $('#idFrameC').resizable('option', 'minWidth', 300); + $('#idFrameC').resizable('option', 'minWidth', 360); } answerSizer(); @@ -1166,7 +1166,7 @@ $(document).ready(function () { $('#idFrameC').stop().animate({ width: nwidth }, - 300, + 360, 'linear', function () { answerSizer(); @@ -1178,9 +1178,9 @@ $(document).ready(function () { $('#idFrameC .ui-tabs-nav li').on('click', function (event) { if($('#idFrameC').attr('data-status') == 'closed'){ - $('#idFrameC').width(300); - $('#rightFrame').css('left', 300); - $('#rightFrame').width($(window).width()-300); + $('#idFrameC').width(360); + $('#rightFrame').css('left', 360); + $('#rightFrame').width($(window).width()-360); $('#baskets, #proposals, #thesaurus_tab').hide(); $('.ui-resizable-handle, #basket_menu_trigger').show(); var IDname = $(this).attr('aria-controls'); @@ -1188,7 +1188,7 @@ $(document).ready(function () { } $('#idFrameC').attr('data-status', 'open'); - $('.WZbasketTab').css('background-position', '9px 21px'); + $('.WZbasketTab').css('background-position', '9px 25px'); $('#idFrameC').removeClass('closed'); }); @@ -1204,17 +1204,17 @@ $(document).ready(function () { $('#idFrameC').attr('data-status', 'closed'); $('#baskets, #proposals, #thesaurus_tab, .ui-resizable-handle, #basket_menu_trigger').hide(); $('#idFrameC .ui-tabs-nav li').removeClass('ui-state-active'); - $('.WZbasketTab').css('background-position', '15px 16px'); + $('.WZbasketTab').css('background-position', '15px 25px'); $('#idFrameC').addClass('closed'); previousTab = $('#idFrameC .icon-menu').find('li.ui-tabs-active'); }else{ $(this).find('i').removeClass('icon-double-angle-right').addClass('icon-double-angle-left') - $('#idFrameC').width(300); - $('#rightFrame').css('left', 300); - $('#rightFrame').width($(window).width()-300); + $('#idFrameC').width(360); + $('#rightFrame').css('left', 360); + $('#rightFrame').width($(window).width()-360); $('#idFrameC').attr('data-status', 'open'); $('.ui-resizable-handle, #basket_menu_trigger').show(); - $('.WZbasketTab').css('background-position', '9px 16px'); + $('.WZbasketTab').css('background-position', '9px 25px'); $('#idFrameC').removeClass('closed'); $('#idFrameC .icon-menu li').last().find('a').trigger('click'); $('#idFrameC .icon-menu li').first().find('a').trigger('click'); diff --git a/resources/www/prod/skins/ui-components/_workzone.scss b/resources/www/prod/skins/ui-components/_workzone.scss index 5543055ad9..36c0f8e750 100644 --- a/resources/www/prod/skins/ui-components/_workzone.scss +++ b/resources/www/prod/skins/ui-components/_workzone.scss @@ -23,7 +23,7 @@ $workzoneTabDisabledTextColor: $mediumTextActiveColor !default; */ #idFrameC { top: 0 !important; - min-width: 300px; + min-width: 360px; bottom: 0 !important; &.closed { min-width: 0; @@ -153,7 +153,7 @@ $workzoneTabDisabledTextColor: $mediumTextActiveColor !default; display: block; background-image: url('#{$iconsPath}workzone32.png'); background-repeat: no-repeat; - background-position: 9px 21px; + background-position: 9px 25px; width: 70px; height: 82px; } From 6a2285f66d8cda51a90d0e0b3aa7432602fb05cd Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Thu, 20 Oct 2016 19:36:26 +0200 Subject: [PATCH 05/42] PHRAS-508_acl-cache - wip --- .../Phrasea/Collection/CollectionService.php | 50 +- .../Controller/Admin/CollectionController.php | 4 +- .../Controller/Admin/UserController.php | 8 +- .../Phrasea/Controller/Api/V1Controller.php | 20 +- .../Controller/Prod/EditController.php | 8 +- .../Controller/Prod/PropertyController.php | 8 +- .../Controller/Prod/PushController.php | 2 +- .../Controller/Prod/RecordController.php | 17 +- .../Controller/Prod/StoryController.php | 6 +- .../Controller/Prod/ToolsController.php | 14 +- .../ControllerProvider/Admin/Collection.php | 2 +- .../ControllerProvider/Admin/Users.php | 2 +- .../Phrasea/ControllerProvider/Prod/Edit.php | 2 +- .../ControllerProvider/Prod/Lazaret.php | 2 +- .../Prod/MoveCollection.php | 4 +- .../Phrasea/ControllerProvider/Prod/Tools.php | 2 +- .../ControllerProvider/Prod/Upload.php | 2 +- .../Core/Event/Subscriber/OrderSubscriber.php | 2 +- lib/Alchemy/Phrasea/Helper/User/Edit.php | 44 +- lib/Alchemy/Phrasea/Helper/User/Manage.php | 4 +- .../Model/Manipulator/ACLManipulator.php | 30 +- .../Manipulator/RegistrationManipulator.php | 10 +- .../Phrasea/Model/NativeQueryProvider.php | 50 +- .../Order/Controller/ProdOrderController.php | 2 +- lib/Alchemy/Phrasea/Order/OrderValidator.php | 2 +- .../Phrasea/Search/SubdefTransformer.php | 2 +- .../SearchEngine/SearchEngineOptions.php | 4 +- lib/Alchemy/Phrasea/Security/Firewall.php | 2 +- lib/Alchemy/Phrasea/Setup/Installer.php | 27 +- .../Phrasea/Twig/PhraseanetExtension.php | 2 +- .../ControlProvider/UserProvider.php | 2 +- lib/classes/ACL.php | 433 ++++++++---------- lib/classes/databox.php | 32 +- lib/classes/databox/status.php | 2 +- .../eventsmanager/notify/autoregister.php | 2 +- lib/classes/eventsmanager/notify/order.php | 2 +- lib/classes/eventsmanager/notify/register.php | 2 +- .../eventsmanager/notify/uploadquarantine.php | 2 +- lib/classes/record/exportElement.php | 6 +- lib/classes/set/export.php | 14 +- .../web/admin/collection/collection.html.twig | 14 +- .../web/admin/collection/create.html.twig | 4 +- templates/web/admin/databox/databox.html.twig | 2 +- templates/web/admin/editusers.html.twig | 26 +- templates/web/admin/tree.html.twig | 14 +- templates/web/common/caption.html.twig | 2 +- templates/web/common/menubar.html.twig | 2 +- templates/web/lightbox/IE6/feed.html.twig | 2 +- templates/web/lightbox/IE6/validate.html.twig | 2 +- templates/web/lightbox/feed.html.twig | 2 +- templates/web/lightbox/validate.html.twig | 2 +- templates/web/prod/WorkZone/Basket.html.twig | 8 +- templates/web/prod/WorkZone/Macros.html.twig | 4 +- templates/web/prod/WorkZone/Story.html.twig | 8 +- templates/web/prod/actions/Push.html.twig | 2 +- .../web/prod/actions/edit_default.html.twig | 2 +- templates/web/prod/index.html.twig | 2 +- templates/web/prod/preview/caption.html.twig | 2 +- templates/web/prod/preview/tools.html.twig | 4 +- templates/web/prod/results/list.html.twig | 2 +- templates/web/prod/results/record.html.twig | 6 +- templates/web/prod/toolbar.html.twig | 10 +- templates/web/prod/upload/lazaret.html.twig | 4 +- .../Controller/Admin/AdminCollectionTest.php | 2 +- .../Phrasea/Controller/Admin/UsersTest.php | 14 +- .../Phrasea/Controller/Api/ApiJsonTest.php | 25 +- .../Phrasea/Controller/Prod/PropertyTest.php | 4 +- .../Phrasea/Controller/RecordsRequestTest.php | 7 +- .../Model/Manipulator/ACLManipulatorTest.php | 60 +-- .../RegistrationManipulatorTest.php | 10 +- tests/classes/ACLTest.php | 53 ++- tests/classes/PhraseanetTestCase.php | 38 +- 72 files changed, 571 insertions(+), 599 deletions(-) diff --git a/lib/Alchemy/Phrasea/Collection/CollectionService.php b/lib/Alchemy/Phrasea/Collection/CollectionService.php index 8a2a8bc2f1..4f67046371 100644 --- a/lib/Alchemy/Phrasea/Collection/CollectionService.php +++ b/lib/Alchemy/Phrasea/Collection/CollectionService.php @@ -269,23 +269,23 @@ class CollectionService public function grantAdminRights(CollectionReference $reference, User $user) { $rights = [ - "canputinalbum" => "1", - "candwnldhd" => "1", - "nowatermark" => "1", - "candwnldpreview" => "1", - "cancmd" => "1", - "canadmin" => "1", - "actif" => "1", - "canreport" => "1", - "canpush" => "1", - "basusr_infousr" => "", - "canaddrecord" => "1", - "canmodifrecord" => "1", - "candeleterecord" => "1", - "chgstatus" => "1", - "imgtools" => "1", - "manage" => "1", - "modify_struct" => "1" + \ACL::CANPUTINALBUM => "1", + \ACL::CANDWNLDHD => "1", + \ACL::NOWATERMARK => "1", + \ACL::CANDWNLDPREVIEW => "1", + \ACL::CANCMD => "1", + \ACL::CANADMIN => "1", + \ACL::ACTIF => "1", + \ACL::CANREPORT => "1", + \ACL::CANPUSH => "1", + "basusr_infousr" => "", + \ACL::CANADDRECORD => "1", + \ACL::CANMODIFRECORD => "1", + \ACL::CANDELETERECORD => "1", + \ACL::CHGSTATUS => "1", + \ACL::IMGTOOLS => "1", + \ACL::MANAGE => "1", + \ACL::MODIFY_STRUCT => "1" ]; $this->app->getAclForUser($user)->update_rights_to_base($reference->getBaseId(), $rights); @@ -318,18 +318,28 @@ class CollectionService $userQuery = $factory(); $result = $userQuery->on_base_ids([ $reference->getBaseId()] ) - ->who_have_right(['order_master']) + ->who_have_right([\ACL::ORDER_MASTER]) ->execute()->get_results(); /** @var ACLProvider $acl */ $acl = $this->app['acl']; foreach ($result as $user) { - $acl->get($user)->update_rights_to_base($reference->getBaseId(), ['order_master' => false]); + $acl->get($user)->update_rights_to_base( + $reference->getBaseId(), + [ + \ACL::ORDER_MASTER => false + ] + ); } foreach ($admins as $admin) { - $acl->get($admin)->update_rights_to_base($reference->getBaseId(), ['order_master' => true]); + $acl->get($admin)->update_rights_to_base( + $reference->getBaseId(), + [ + \ACL::ORDER_MASTER => true + ] + ); } $conn->commit(); diff --git a/lib/Alchemy/Phrasea/Controller/Admin/CollectionController.php b/lib/Alchemy/Phrasea/Controller/Admin/CollectionController.php index 2ebe77a408..3304a19de8 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/CollectionController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/CollectionController.php @@ -46,10 +46,10 @@ class CollectionController extends Controller $admins = []; - if ($this->getAclForUser()->has_right_on_base($bas_id, 'manage')) { + if ($this->getAclForUser()->has_right_on_base($bas_id, \ACL::COLL_MANAGE)) { $query = $this->createUserQuery(); $admins = $query->on_base_ids([$bas_id]) - ->who_have_right(['order_master']) + ->who_have_right([\ACL::ORDER_MASTER]) ->execute() ->get_results(); } diff --git a/lib/Alchemy/Phrasea/Controller/Admin/UserController.php b/lib/Alchemy/Phrasea/Controller/Admin/UserController.php index 606f72abaf..65da919edd 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/UserController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/UserController.php @@ -285,7 +285,7 @@ class UserController extends Controller $on_base = $request->request->get('base_id') ? : null; $on_sbas = $request->request->get('sbas_id') ? : null; - $eligible_users = $user_query->on_bases_where_i_am($this->getAclForConnectedUser(), ['canadmin']) + $eligible_users = $user_query->on_bases_where_i_am($this->getAclForConnectedUser(), [\ACL::CANADMIN]) ->like($like_field, $like_value) ->on_base_ids($on_base) ->on_sbas_ids($on_sbas); @@ -357,7 +357,7 @@ class UserController extends Controller $userRegistrations = []; /** @var RegistrationRepository $registrationRepository */ $registrationRepository = $this->app['repo.registrations']; - $collections = $this->getAclForConnectedUser()->get_granted_base(['canadmin']); + $collections = $this->getAclForConnectedUser()->get_granted_base([\ACL::CANADMIN]); $authenticatedUserId = $authenticatedUser->getId(); foreach ($registrationRepository->getPendingRegistrations($collections) as $registration) { $user = $registration->getUser(); @@ -689,7 +689,7 @@ class UserController extends Controller ]); } - $basList = array_keys($this->getAclForConnectedUser()->get_granted_base(['manage'])); + $basList = array_keys($this->getAclForConnectedUser()->get_granted_base([\ACL::COLL_MANAGE])); /** @var NativeQueryProvider $query */ $query = $this->app['orm.em.native-query']; $models = $query->getModelForUser($this->getAuthenticatedUser(), $basList); @@ -832,7 +832,7 @@ class UserController extends Controller $this->getAclForUser($newUser)->apply_model( $userRepository->find($model), - array_keys($this->getAclForConnectedUser()->get_granted_base(['manage'])) + array_keys($this->getAclForConnectedUser()->get_granted_base([\ACL::COLL_MANAGE])) ); $nbCreation++; diff --git a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php index cafb22a062..a1a2ad04a2 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php @@ -485,7 +485,7 @@ class V1Controller extends Controller { $userQuery = new \User_Query($this->app); $orderMasters = $userQuery->on_base_ids([ $collection->get_base_id() ] ) - ->who_have_right(['order_master']) + ->who_have_right([\ACL::ORDER_MASTER]) ->execute() ->get_results() ->map(function (User $user) { @@ -1034,7 +1034,7 @@ class V1Controller extends Controller return null; } if ($media->get_name() === 'document' - && !$acl->has_right_on_base($record->getBaseId(), 'candwnldhd') + && !$acl->has_right_on_base($record->getBaseId(), \ACL::CANDWNLDHD) && !$acl->has_hd_grant($record) ) { return null; @@ -2769,9 +2769,11 @@ class V1Controller extends Controller $user = $this->getApiAuthenticatedUser(); $acl = $this->getAclForUser($user); - if (! $acl->has_access_to_module('admin') || ! $acl->has_right('manageusers')) { + if (! $acl->has_access_to_module('admin') || ! $acl->has_right(\ACL::CANADMIN)) { return Result::createError($request, 401, 'You are not authorized')->createResponse(); } + + return null; } public function ensureAccessToDatabox(Request $request) @@ -2813,7 +2815,7 @@ class V1Controller extends Controller public function ensureCanModifyRecord(Request $request) { $user = $this->getApiAuthenticatedUser(); - if (!$this->getAclForUser($user)->has_right('modifyrecord')) { + if (!$this->getAclForUser($user)->has_right(\ACL::CANMODIFRECORD)) { return Result::createError($request, 401, 'You are not authorized')->createResponse(); } @@ -2825,7 +2827,7 @@ class V1Controller extends Controller $user = $this->getApiAuthenticatedUser(); $record = $this->findDataboxById($request->attributes->get('databox_id')) ->get_record($request->attributes->get('record_id')); - if (!$this->getAclForUser($user)->has_right_on_base($record->getBaseId(), 'chgstatus')) { + if (!$this->getAclForUser($user)->has_right_on_base($record->getBaseId(), \ACL::CHGSTATUS)) { return Result::createError($request, 401, 'You are not authorized')->createResponse(); } @@ -2849,9 +2851,9 @@ class V1Controller extends Controller $record = $this->findDataboxById($request->attributes->get('databox_id')) ->get_record($request->attributes->get('record_id')); // TODO: Check comparison. seems to be a mismatch - if ((!$this->getAclForUser($user)->has_right('addrecord') - && !$this->getAclForUser($user)->has_right('deleterecord')) - || !$this->getAclForUser($user)->has_right_on_base($record->getBaseId(), 'candeleterecord') + if ((!$this->getAclForUser($user)->has_right(\ACL::CANADDRECORD) + && !$this->getAclForUser($user)->has_right(\ACL::CANDELETERECORD)) + || !$this->getAclForUser($user)->has_right_on_base($record->getBaseId(), \ACL::CANDELETERECORD) ) { return Result::createError($request, 401, 'You are not authorized')->createResponse(); } @@ -2865,7 +2867,7 @@ class V1Controller extends Controller $record = $this->findDataboxById($request->attributes->get('databox_id')) ->get_record($request->attributes->get('record_id')); - if (!$this->getAclForUser($user)->has_right_on_base($record->getBaseId(), 'candeleterecord')) { + if (!$this->getAclForUser($user)->has_right_on_base($record->getBaseId(), \ACL::CANDELETERECORD)) { return Result::createError($request, 401, 'You are not authorized')->createResponse(); } diff --git a/lib/Alchemy/Phrasea/Controller/Prod/EditController.php b/lib/Alchemy/Phrasea/Controller/Prod/EditController.php index d0730f9b03..9f91c372a3 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/EditController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/EditController.php @@ -38,7 +38,7 @@ class EditController extends Controller $this->app, $request, RecordsRequest::FLATTEN_YES_PRESERVE_STORIES, - ['canmodifrecord'] + [\ACL::CANMODIFRECORD] ); $thesaurus = false; @@ -120,7 +120,7 @@ class EditController extends Controller } // generate javascript status - if ($this->getAclForUser()->has_right('changestatus')) { + if ($this->getAclForUser()->has_right(\ACL::CHGSTATUS)) { $statusStructure = $databox->getStatusStructure(); foreach ($statusStructure as $statbit) { $bit = $statbit['bit']; @@ -156,7 +156,7 @@ class EditController extends Controller ]; $elements[$indice]['statbits'] = []; - if ($this->getAclForUser()->has_right_on_base($record->getBaseId(), 'chgstatus')) { + if ($this->getAclForUser()->has_right_on_base($record->getBaseId(), \ACL::CHGSTATUS)) { foreach ($status as $n => $s) { $tmp_val = substr(strrev($record->getStatus()), $n, 1); $elements[$indice]['statbits'][$n]['value'] = ($tmp_val == '1') ? '1' : '0'; @@ -273,7 +273,7 @@ class EditController extends Controller public function applyAction(Request $request) { - $records = RecordsRequest::fromRequest($this->app, $request, RecordsRequest::FLATTEN_YES_PRESERVE_STORIES, ['canmodifrecord']); + $records = RecordsRequest::fromRequest($this->app, $request, RecordsRequest::FLATTEN_YES_PRESERVE_STORIES, [\ACL::CANMODIFRECORD]); $databoxes = $records->databoxes(); if (count($databoxes) !== 1) { diff --git a/lib/Alchemy/Phrasea/Controller/Prod/PropertyController.php b/lib/Alchemy/Phrasea/Controller/Prod/PropertyController.php index 317aeb7cb7..ff834ab119 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/PropertyController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/PropertyController.php @@ -28,7 +28,7 @@ class PropertyController extends Controller $this->app->abort(400); } - $records = RecordsRequest::fromRequest($this->app, $request, false, ['chgstatus']); + $records = RecordsRequest::fromRequest($this->app, $request, false, [\ACL::CHGSTATUS]); $databoxes = $records->databoxes(); if (count($databoxes) > 1) { @@ -81,7 +81,7 @@ class PropertyController extends Controller $this->app->abort(400); } - $records = RecordsRequest::fromRequest($this->app, $request, false, ['canmodifrecord']); + $records = RecordsRequest::fromRequest($this->app, $request, false, [\ACL::CANMODIFRECORD]); $recordsType = []; @@ -115,7 +115,7 @@ class PropertyController extends Controller public function changeStatus(Request $request) { $applyStatusToChildren = $request->request->get('apply_to_children', []); - $records = RecordsRequest::fromRequest($this->app, $request, false, ['chgstatus']); + $records = RecordsRequest::fromRequest($this->app, $request, false, [\ACL::CHGSTATUS]); $updated = []; $postStatus = (array) $request->request->get('status'); @@ -149,7 +149,7 @@ class PropertyController extends Controller public function changeType(Request $request) { $typeLst = $request->request->get('types', []); - $records = RecordsRequest::fromRequest($this->app, $request, false, ['canmodifrecord']); + $records = RecordsRequest::fromRequest($this->app, $request, false, [\ACL::CANMODIFRECORD]); $mimeLst = $request->request->get('mimes', []); $forceType = $request->request->get('force_types', ''); $updated = []; diff --git a/lib/Alchemy/Phrasea/Controller/Prod/PushController.php b/lib/Alchemy/Phrasea/Controller/Prod/PushController.php index 60feb34658..59f443e90e 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/PushController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/PushController.php @@ -431,7 +431,7 @@ class PushController extends Controller $result = ['success' => false, 'message' => '', 'user' => null]; try { - if (!$this->getAclForUser($this->getAuthenticatedUser())->has_right('manageusers')) + if (!$this->getAclForUser($this->getAuthenticatedUser())->has_right(\ACL::CANADMIN)) throw new ControllerException($this->app->trans('You are not allowed to add users')); if (!$request->request->get('firstname')) diff --git a/lib/Alchemy/Phrasea/Controller/Prod/RecordController.php b/lib/Alchemy/Phrasea/Controller/Prod/RecordController.php index dece366e83..9765a1134b 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/RecordController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/RecordController.php @@ -121,9 +121,11 @@ class RecordController extends Controller public function doDeleteRecords(Request $request) { $flatten = (bool)($request->request->get('del_children')) ? RecordsRequest::FLATTEN_YES_PRESERVE_STORIES : RecordsRequest::FLATTEN_NO; - $records = RecordsRequest::fromRequest($this->app, $request, $flatten, [ - 'candeleterecord' - ]); + $records = RecordsRequest::fromRequest( + $this->app, + $request,$flatten, + [\ACL::CANDELETERECORD] + ); $basketElementsRepository = $this->getBasketElementRepository(); $StoryWZRepository = $this->getStoryWorkZoneRepository(); @@ -166,9 +168,12 @@ class RecordController extends Controller */ public function whatCanIDelete(Request $request) { - $records = RecordsRequest::fromRequest($this->app, $request, !!$request->request->get('del_children'), [ - 'candeleterecord', - ]); + $records = RecordsRequest::fromRequest( + $this->app, + $request, + !!$request->request->get('del_children'), + [\ACL::CANDELETERECORD] + ); return $this->render('prod/actions/delete_records_confirm.html.twig', [ 'records' => $records, diff --git a/lib/Alchemy/Phrasea/Controller/Prod/StoryController.php b/lib/Alchemy/Phrasea/Controller/Prod/StoryController.php index 39ffb95bf9..96d3d5e537 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/StoryController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/StoryController.php @@ -109,7 +109,7 @@ class StoryController extends Controller { $Story = new \record_adapter($this->app, $sbas_id, $record_id); - if (!$this->getAclForUser()->has_right_on_base($Story->getBaseId(), 'canmodifrecord')) { + if (!$this->getAclForUser()->has_right_on_base($Story->getBaseId(), \ACL::CANMODIFRECORD)) { throw new AccessDeniedHttpException('You can not add document to this Story'); } @@ -145,7 +145,7 @@ class StoryController extends Controller $story = new \record_adapter($this->app, $sbas_id, $record_id); $record = new \record_adapter($this->app, $child_sbas_id, $child_record_id); - if (!$this->getAclForUser()->has_right_on_base($story->getBaseId(), 'canmodifrecord')) { + if (!$this->getAclForUser()->has_right_on_base($story->getBaseId(), \ACL::CANMODIFRECORD)) { throw new AccessDeniedHttpException('You can not add document to this Story'); } @@ -188,7 +188,7 @@ class StoryController extends Controller throw new \Exception('This is not a story'); } - if (!$this->getAclForUser()->has_right_on_base($story->getBaseId(), 'canmodifrecord')) { + if (!$this->getAclForUser()->has_right_on_base($story->getBaseId(), \ACL::CANMODIFRECORD)) { throw new ControllerException($this->app->trans('You can not edit this story')); } diff --git a/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php b/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php index cd22dc8740..c8d4f44fa4 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php @@ -52,8 +52,8 @@ class ToolsController extends Controller $acl = $this->getAclForUser(); if ($acl->has_right('bas_chupub') - && $acl->has_right_on_base($record->getBaseId(), 'canmodifrecord') - && $acl->has_right_on_base($record->getBaseId(), 'imgtools') + && $acl->has_right_on_base($record->getBaseId(), \ACL::CANMODIFRECORD) + && $acl->has_right_on_base($record->getBaseId(), \ACL::IMGTOOLS) ) { $databoxSubdefs = $record->getDatabox()->get_subdef_structure()->getSubdefGroup($record->getType()); @@ -64,7 +64,7 @@ class ToolsController extends Controller } if ('document' == $subdefName) { - if (!$acl->has_right_on_base($record->getBaseId(), 'candwnldhd')) { + if (!$acl->has_right_on_base($record->getBaseId(), \ACL::CANDWNLDHD)) { continue; } $label = $this->app->trans('prod::tools: document'); @@ -147,7 +147,7 @@ class ToolsController extends Controller $force = $request->request->get('force_substitution') == '1'; - $selection = RecordsRequest::fromRequest($this->app, $request, false, array('canmodifrecord')); + $selection = RecordsRequest::fromRequest($this->app, $request, false, [\ACL::CANMODIFRECORD]); foreach ($selection as $record) { $substituted = false; @@ -341,9 +341,9 @@ class ToolsController extends Controller $acl = $this->getAclForUser(); if (!$acl->has_right('bas_chupub') - || !$acl->has_right_on_base($record->getBaseId(), 'canmodifrecord') - || !$acl->has_right_on_base($record->getBaseId(), 'imgtools') - || ('document' == $subdefName && !$acl->has_right_on_base($record->getBaseId(), 'candwnldhd')) + || !$acl->has_right_on_base($record->getBaseId(), \ACL::CANMODIFRECORD) + || !$acl->has_right_on_base($record->getBaseId(), \ACL::IMGTOOLS) + || ('document' == $subdefName && !$acl->has_right_on_base($record->getBaseId(), \ACL::CANDWNLDHD)) || ('document' != $subdefName && !$acl->has_access_to_subdef($record, $subdefName)) ) { $this->app->abort(403); diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Collection.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Collection.php index 915f1cd0d3..c92a16c4e8 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Collection.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Collection.php @@ -45,7 +45,7 @@ class Collection implements ControllerProviderInterface, ServiceProviderInterfac $controllers->before(function (Request $request) use ($firewall) { $firewall ->requireAccessToModule('admin') - ->requireRightOnBase($request->attributes->get('bas_id'), 'canadmin'); + ->requireRightOnBase($request->attributes->get('bas_id'), \ACL::CANADMIN); }); $controllers->get('/{bas_id}/', 'controller.admin.collection:getCollection') diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Users.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Users.php index 23ffe894ba..39a5afa0aa 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Users.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Users.php @@ -43,7 +43,7 @@ class Users implements ControllerProviderInterface, ServiceProviderInterface $controllers->before(function () use ($firewall) { $firewall->requireAccessToModule('admin') - ->requireRight('manageusers'); + ->requireRight(\ACL::CANADMIN); }); $controllers->match('/rights/', 'controller.admin.users:editRightsAction') diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Edit.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Edit.php index a9ed65e354..8fb6861088 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Edit.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Edit.php @@ -47,7 +47,7 @@ class Edit implements ControllerProviderInterface, ServiceProviderInterface $controllers->before(function () use ($firewall) { $firewall ->requireNotGuest() - ->requireRight('modifyrecord'); + ->requireRight(\ACL::CANMODIFRECORD); }); $controllers->post('/', 'controller.prod.edit:submitAction'); diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php index 011dbd8ab3..96d454439b 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php @@ -53,7 +53,7 @@ class Lazaret implements ControllerProviderInterface, ServiceProviderInterface $firewall = $this->getFirewall($app); $controllers->before(function () use ($firewall) { - $firewall->requireRight('addrecord'); + $firewall->requireRight(\ACL::CANADDRECORD); }); $controllers->get('/', 'controller.prod.lazaret:listElement') diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/MoveCollection.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/MoveCollection.php index a8c80e49bd..e6a835afaf 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/MoveCollection.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/MoveCollection.php @@ -41,8 +41,8 @@ class MoveCollection implements ControllerProviderInterface, ServiceProviderInte $controllers->before(function () use ($firewall) { $firewall - ->requireRight('addrecord') - ->requireRight('deleterecord'); + ->requireRight(\ACL::CANADDRECORD) + ->requireRight(\ACL::CANDELETERECORD); }); $controllers->post('/', 'controller.prod.move-collection:displayForm') diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tools.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tools.php index 103e9aad51..de63ae1375 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tools.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tools.php @@ -46,7 +46,7 @@ class Tools implements ControllerProviderInterface, ServiceProviderInterface $firewall = $this->getFirewall($app); $controllers->before(function () use ($firewall) { - $firewall->requireRight('doctools'); + $firewall->requireRight(\ACL::IMGTOOLS); }); $controllers->get('/', 'controller.prod.tools:indexAction'); diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Upload.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Upload.php index 1982ac8b73..985944957d 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Upload.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Upload.php @@ -55,7 +55,7 @@ class Upload implements ControllerProviderInterface, ServiceProviderInterface $firewall = $this->getFirewall($app); $controllers->before(function () use ($firewall) { - $firewall->requireRight('addrecord'); + $firewall->requireRight(\ACL::CANADDRECORD); }); $controllers->get('/', 'controller.prod.upload:getUploadForm') diff --git a/lib/Alchemy/Phrasea/Core/Event/Subscriber/OrderSubscriber.php b/lib/Alchemy/Phrasea/Core/Event/Subscriber/OrderSubscriber.php index d17c725cd1..142537f418 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Subscriber/OrderSubscriber.php +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/OrderSubscriber.php @@ -48,7 +48,7 @@ class OrderSubscriber extends AbstractNotificationSubscriber $query = $this->app['phraseanet.user-query']; /** @var User[] $users */ $users = $query->on_base_ids($base_ids) - ->who_have_right(['order_master']) + ->who_have_right([\ACL::ORDER_MASTER]) ->execute()->get_results(); if (count($users) == 0) { diff --git a/lib/Alchemy/Phrasea/Helper/User/Edit.php b/lib/Alchemy/Phrasea/Helper/User/Edit.php index e8d0381dd2..8b9b292246 100644 --- a/lib/Alchemy/Phrasea/Helper/User/Edit.php +++ b/lib/Alchemy/Phrasea/Helper/User/Edit.php @@ -71,7 +71,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper protected function delete_user(User $user) { - $list = array_keys($this->app->getAclForUser($this->app->getAuthenticatedUser())->get_granted_base(['canadmin'])); + $list = array_keys($this->app->getAclForUser($this->app->getAuthenticatedUser())->get_granted_base([\ACL::CANADMIN])); $this->app->getAclForUser($user)->revoke_access_from_bases($list); @@ -84,7 +84,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper public function get_users_rights() { - $list = array_keys($this->app->getAclForUser($this->app->getAuthenticatedUser())->get_granted_base(['canadmin'])); + $list = array_keys($this->app->getAclForUser($this->app->getAuthenticatedUser())->get_granted_base([\ACL::CANADMIN])); $sql = "SELECT b.sbas_id, @@ -477,29 +477,29 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper public function apply_rights() { $ACL = $this->app->getAclForUser($this->app->getAuthenticatedUser()); - $base_ids = array_keys($ACL->get_granted_base(['canadmin'])); + $base_ids = array_keys($ACL->get_granted_base([\ACL::CANADMIN])); $update = $create = $delete = $create_sbas = $update_sbas = []; foreach ($base_ids as $base_id) { $rights = [ 'access', - 'actif', - 'canputinalbum', - 'nowatermark', - 'candwnldpreview', - 'candwnldhd', - 'cancmd', - 'canaddrecord', - 'canmodifrecord', - 'chgstatus', - 'candeleterecord', - 'imgtools', - 'canadmin', - 'canreport', - 'canpush', - 'manage', - 'modify_struct' + \ACL::ACTIF, + \ACL::CANPUTINALBUM, + \ACL::NOWATERMARK, + \ACL::CANDWNLDPREVIEW, + \ACL::CANDWNLDHD, + \ACL::CANCMD, + \ACL::CANADDRECORD, + \ACL::CANMODIFRECORD, + \ACL::CHGSTATUS, + \ACL::CANDELETERECORD, + \ACL::IMGTOOLS, + \ACL::CANADMIN, + \ACL::CANREPORT, + \ACL::CANPUSH, + \ACL::MANAGE, + \ACL::MODIFY_STRUCT ]; foreach ($rights as $k => $right) { if (($right == 'access' && !$ACL->has_access_to_base($base_id)) @@ -688,7 +688,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper throw new AccessDeniedHttpException('You are not the owner of the template'); } - $base_ids = array_keys($this->app->getAclForUser($this->app->getAuthenticatedUser())->get_granted_base(['canadmin'])); + $base_ids = array_keys($this->app->getAclForUser($this->app->getAuthenticatedUser())->get_granted_base([\ACL::CANADMIN])); foreach ($this->users as $usr_id) { $user = $this->app['repo.users']->find($usr_id); @@ -744,7 +744,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper $activate = !!$this->request->get('limit'); - $base_ids = array_keys($this->app->getAclForUser($this->app->getAuthenticatedUser())->get_granted_base(['canadmin'])); + $base_ids = array_keys($this->app->getAclForUser($this->app->getAuthenticatedUser())->get_granted_base([\ACL::CANADMIN])); foreach ($this->users as $usr_id) { $user = $this->app['repo.users']->find($usr_id); @@ -763,7 +763,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper public function resetRights() { - $base_ids = array_keys($this->app->getAclForUser($this->app->getAuthenticatedUser())->get_granted_base(['canadmin'])); + $base_ids = array_keys($this->app->getAclForUser($this->app->getAuthenticatedUser())->get_granted_base([\ACL::CANADMIN])); foreach ($this->users as $usr_id) { $user = $this->app['repo.users']->find($usr_id); diff --git a/lib/Alchemy/Phrasea/Helper/User/Manage.php b/lib/Alchemy/Phrasea/Helper/User/Manage.php index 979195fb10..bea053f56c 100644 --- a/lib/Alchemy/Phrasea/Helper/User/Manage.php +++ b/lib/Alchemy/Phrasea/Helper/User/Manage.php @@ -71,7 +71,7 @@ class Manage extends Helper ->last_model_is($this->query_parms['last_model']) ->get_inactives($this->query_parms['inactives']) ->include_templates(false) - ->on_bases_where_i_am($this->app->getAclForUser($this->app->getAuthenticatedUser()), ['canadmin']) + ->on_bases_where_i_am($this->app->getAclForUser($this->app->getAuthenticatedUser()), [\ACL::CANADMIN]) ->execute(); return $results->get_results(); @@ -109,7 +109,7 @@ class Manage extends Helper ->last_model_is($this->query_parms['last_model']) ->get_inactives($this->query_parms['inactives']) ->include_templates(true) - ->on_bases_where_i_am($this->app->getAclForUser($this->app->getAuthenticatedUser()), ['canadmin']) + ->on_bases_where_i_am($this->app->getAclForUser($this->app->getAuthenticatedUser()), [\ACL::CANADMIN]) ->limit($offset_start, $results_quantity) ->execute(); diff --git a/lib/Alchemy/Phrasea/Model/Manipulator/ACLManipulator.php b/lib/Alchemy/Phrasea/Model/Manipulator/ACLManipulator.php index 4a07f69524..4e6f87907b 100644 --- a/lib/Alchemy/Phrasea/Model/Manipulator/ACLManipulator.php +++ b/lib/Alchemy/Phrasea/Model/Manipulator/ACLManipulator.php @@ -101,23 +101,23 @@ class ACLManipulator implements ManipulatorInterface $acl->remove_quotas_on_base($baseId); $acl->set_masks_on_base($baseId, '0', '0', '0', '0'); $acl->update_rights_to_base($baseId, [ - 'canputinalbum' => '1', - 'candwnldhd' => '1', + \ACL::CANPUTINALBUM => '1', + \ACL::CANDWNLDHD => '1', 'candwnldsubdef' => '1', - 'nowatermark' => '1', - 'candwnldpreview' => '1', - 'cancmd' => '1', - 'canadmin' => '1', - 'canreport' => '1', - 'canpush' => '1', + \ACL::NOWATERMARK => '1', + \ACL::CANDWNLDPREVIEW => '1', + \ACL::CANCMD => '1', + \ACL::CANADMIN => '1', + \ACL::CANREPORT => '1', + \ACL::CANPUSH => '1', 'creationdate' => '1', - 'canaddrecord' => '1', - 'canmodifrecord' => '1', - 'candeleterecord' => '1', - 'chgstatus' => '1', - 'imgtools' => '1', - 'manage' => '1', - 'modify_struct' => '1', + \ACL::CANADDRECORD => '1', + \ACL::CANMODIFRECORD => '1', + \ACL::CANDELETERECORD => '1', + \ACL::CHGSTATUS => '1', + \ACL::IMGTOOLS => '1', + \ACL::MANAGE => '1', + \ACL::MODIFY_STRUCT => '1', 'bas_modify_struct' => '1' ]); } diff --git a/lib/Alchemy/Phrasea/Model/Manipulator/RegistrationManipulator.php b/lib/Alchemy/Phrasea/Model/Manipulator/RegistrationManipulator.php index ad85eef361..c40cbf2c18 100644 --- a/lib/Alchemy/Phrasea/Model/Manipulator/RegistrationManipulator.php +++ b/lib/Alchemy/Phrasea/Model/Manipulator/RegistrationManipulator.php @@ -82,11 +82,11 @@ class RegistrationManipulator implements ManipulatorInterface $this->aclProvider->get($user)->give_access_to_sbas([$collection->get_sbas_id()]); $this->aclProvider->get($user)->give_access_to_base([$collection->get_base_id()]); $this->aclProvider->get($user)->update_rights_to_base($collection->get_base_id(), [ - 'canputinalbum' => '1', - 'candwnldhd' => (string) (int) $grantHd, - 'nowatermark' => (string) (int) $grantWatermark, - 'candwnldpreview' => '1', - 'actif' => '1', + \ACL::CANPUTINALBUM => '1', + \ACL::CANDWNLDHD => (string) (int) $grantHd, + \ACL::NOWATERMARK => (string) (int) $grantWatermark, + \ACL::CANDWNLDPREVIEW => '1', + \ACL::ACTIF => '1' ]); $this->em->remove($registration); $this->em->flush(); diff --git a/lib/Alchemy/Phrasea/Model/NativeQueryProvider.php b/lib/Alchemy/Phrasea/Model/NativeQueryProvider.php index 83adb29da3..4226cc0395 100644 --- a/lib/Alchemy/Phrasea/Model/NativeQueryProvider.php +++ b/lib/Alchemy/Phrasea/Model/NativeQueryProvider.php @@ -32,16 +32,13 @@ class NativeQueryProvider $selectClause = $rsm->generateSelectClause(); - return $this->em->createNativeQuery(" - SELECT d.date_modif AS date_demand, d.base_id AS base_demand, " . $selectClause . " - FROM (demand d INNER JOIN Users u ON d.usr_id=u.id - AND d.en_cours=1 - AND u.deleted=0 - ) - WHERE (base_id='" . implode("' OR base_id='", $basList) . "') - ORDER BY d.usr_id DESC, d.base_id ASC - ", $rsm) - ->getResult(); + return $this->em->createNativeQuery( + "SELECT d.date_modif AS date_demand, d.base_id AS base_demand, " . $selectClause . "\n" + . " FROM (demand d INNER JOIN Users u ON d.usr_id=u.id AND d.en_cours=1 AND u.deleted=0)\n" + . " WHERE (base_id='" . implode("' OR base_id='", $basList) . "')\n" + . " ORDER BY d.usr_id DESC, d.base_id ASC", + $rsm + )->getResult(); } public function getModelForUser(User $user, array $basList) @@ -51,14 +48,14 @@ class NativeQueryProvider $selectClause = $rsm->generateSelectClause(); - $query = $this->em->createNativeQuery(" - SELECT " . $selectClause . " - FROM Users u - INNER JOIN basusr b ON (b.usr_id=u.id) - WHERE u.model_of = :user_id - AND b.base_id IN (" . implode(', ', $basList) . ") - AND u.deleted='0' - GROUP BY u.id", $rsm); + $query = $this->em->createNativeQuery( + "SELECT " . $selectClause . " FROM Users u INNER JOIN basusr b ON (b.usr_id=u.id)\n" + . " WHERE u.model_of = :user_id\n" + . " AND b.base_id IN (" . implode(', ', $basList) . ")\n" + . " AND u.deleted='0'\n" + . " GROUP BY u.id", + $rsm + ); $query->setParameter(':user_id', $user->getId()); @@ -72,14 +69,15 @@ class NativeQueryProvider $rsm->addScalarResult('base_id', 'base_id'); $selectClause = $rsm->generateSelectClause(); - $query = $this->em->createNativeQuery(' - SELECT b.base_id, '.$selectClause.' FROM Users u, basusr b - WHERE u.id = b.usr_id - AND b.base_id IN (' . implode(', ', $basList) . ') - AND u.model_of IS NULL - AND b.actif="1" - AND b.canadmin="1" - AND u.deleted="0"', $rsm + $query = $this->em->createNativeQuery( + "SELECT b.base_id, ".$selectClause." FROM Users u, basusr b\n" + . " WHERE u.id = b.usr_id\n" + . " AND b.base_id IN (" . implode(', ', $basList) . ")\n" + . " AND u.model_of IS NULL\n" + . " AND b.actif=1\n" + . " AND b.canadmin=1\n" + . " AND u.deleted=0", + $rsm ); return $query->getResult(); diff --git a/lib/Alchemy/Phrasea/Order/Controller/ProdOrderController.php b/lib/Alchemy/Phrasea/Order/Controller/ProdOrderController.php index 50830d3e07..1a86dc381d 100644 --- a/lib/Alchemy/Phrasea/Order/Controller/ProdOrderController.php +++ b/lib/Alchemy/Phrasea/Order/Controller/ProdOrderController.php @@ -109,7 +109,7 @@ class ProdOrderController extends BaseOrderController $sort = $request->query->get('sort'); - $baseIds = array_keys($this->getAclForUser()->get_granted_base(['order_master'])); + $baseIds = array_keys($this->getAclForUser()->get_granted_base([\ACL::ORDER_MASTER])); $ordersList = $this->getOrderRepository()->listOrders($baseIds, $offsetStart, $perPage, $sort); $total = $this->getOrderRepository()->countTotalOrders($baseIds); diff --git a/lib/Alchemy/Phrasea/Order/OrderValidator.php b/lib/Alchemy/Phrasea/Order/OrderValidator.php index 55339c2697..551958dc62 100644 --- a/lib/Alchemy/Phrasea/Order/OrderValidator.php +++ b/lib/Alchemy/Phrasea/Order/OrderValidator.php @@ -114,7 +114,7 @@ class OrderValidator $element->getRecordId() ); - $acl->grant_hd_on($recordReference, $user, 'order'); + $acl->grant_hd_on($recordReference, $user, \ACL::GRANT_ACTION_ORDER); } } diff --git a/lib/Alchemy/Phrasea/Search/SubdefTransformer.php b/lib/Alchemy/Phrasea/Search/SubdefTransformer.php index ecd43ff032..a2d23cb34f 100644 --- a/lib/Alchemy/Phrasea/Search/SubdefTransformer.php +++ b/lib/Alchemy/Phrasea/Search/SubdefTransformer.php @@ -53,7 +53,7 @@ class SubdefTransformer extends TransformerAbstract return null; } if ($media->get_name() === 'document' - && !$acl->has_right_on_base($record->getBaseId(), 'candwnldhd') + && !$acl->has_right_on_base($record->getBaseId(), \ACL::CANDWNLDHD) && !$acl->has_hd_grant($record) ) { return null; diff --git a/lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php b/lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php index 77bfecd071..75dc4cfa1d 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php +++ b/lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php @@ -639,9 +639,9 @@ class SearchEngineOptions $options->onCollections($bas); - if ($isAuthenticated && $acl->has_right('modifyrecord')) { + if ($isAuthenticated && $acl->has_right(\ACL::CANMODIFRECORD)) { $bf = array_filter($bas, function (\collection $collection) use ($acl) { - return $acl->has_right_on_base($collection->get_base_id(), 'canmodifrecord'); + return $acl->has_right_on_base($collection->get_base_id(), \ACL::CANMODIFRECORD); }); $options->allowBusinessFieldsOn($bf); diff --git a/lib/Alchemy/Phrasea/Security/Firewall.php b/lib/Alchemy/Phrasea/Security/Firewall.php index 836edd1ed8..2343a50b3e 100644 --- a/lib/Alchemy/Phrasea/Security/Firewall.php +++ b/lib/Alchemy/Phrasea/Security/Firewall.php @@ -146,7 +146,7 @@ class Firewall public function requireOrdersAdmin() { - if (empty($this->app->getAclForUser($this->app->getAuthenticatedUser())->get_granted_base(['order_master']))) { + if (empty($this->app->getAclForUser($this->app->getAuthenticatedUser())->get_granted_base([\ACL::ORDER_MASTER]))) { $this->app->abort(403, 'You are not an order admin'); } diff --git a/lib/Alchemy/Phrasea/Setup/Installer.php b/lib/Alchemy/Phrasea/Setup/Installer.php index 4c18e5eb5a..cc8c28f837 100644 --- a/lib/Alchemy/Phrasea/Setup/Installer.php +++ b/lib/Alchemy/Phrasea/Setup/Installer.php @@ -60,8 +60,10 @@ class Installer ->give_access_to_sbas([$databox->get_sbas_id()]) ->update_rights_to_sbas( $databox->get_sbas_id(), [ - 'bas_manage' => 1, 'bas_modify_struct' => 1, - 'bas_modif_th' => 1, 'bas_chupub' => 1 + 'bas_manage' => 1, + 'bas_modify_struct' => 1, + 'bas_modif_th' => 1, + 'bas_chupub' => 1 ] ); @@ -69,11 +71,22 @@ class Installer $this->app->getAclForUser($admin)->give_access_to_base([$collection->get_base_id()]); $this->app->getAclForUser($admin)->update_rights_to_base($collection->get_base_id(), [ - 'canpush' => 1, 'cancmd' => 1 - , 'canputinalbum' => 1, 'candwnldhd' => 1, 'candwnldpreview' => 1, 'canadmin' => 1 - , 'actif' => 1, 'canreport' => 1, 'canaddrecord' => 1, 'canmodifrecord' => 1 - , 'candeleterecord' => 1, 'chgstatus' => 1, 'imgtools' => 1, 'manage' => 1 - , 'modify_struct' => 1, 'nowatermark' => 1 + \ACL::CANPUSH => 1, + \ACL::CANCMD => 1, + \ACL::CANPUTINALBUM => 1, + \ACL::CANDWNLDHD => 1, + \ACL::CANDWNLDPREVIEW => 1, + \ACL::CANADMIN => 1, + \ACL::ACTIF => 1, + \ACL::CANREPORT => 1, + \ACL::CANADDRECORD => 1, + \ACL::CANMODIFRECORD => 1, + \ACL::CANDELETERECORD => 1, + \ACL::CHGSTATUS => 1, + \ACL::IMGTOOLS => 1, + \ACL::MANAGE => 1, + \ACL::MODIFY_STRUCT => 1, + \ACL::NOWATERMARK => 1 ] ); diff --git a/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php b/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php index a11b9d6ee6..62a42e46b3 100644 --- a/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php +++ b/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php @@ -133,7 +133,7 @@ class PhraseanetExtension extends \Twig_Extension $structure = $databox->getStatusStructure()->toArray(); - if (!$this->isGrantedOnCollection($record->getBaseId(), 'chgstatus')) { + if (!$this->isGrantedOnCollection($record->getBaseId(), \ACL::CHGSTATUS)) { $structure = array_filter($structure, function($status) { return (bool) $status['printable']; }); diff --git a/lib/Alchemy/Phrasea/Vocabulary/ControlProvider/UserProvider.php b/lib/Alchemy/Phrasea/Vocabulary/ControlProvider/UserProvider.php index 2c9af43bd3..a8a7224b1d 100644 --- a/lib/Alchemy/Phrasea/Vocabulary/ControlProvider/UserProvider.php +++ b/lib/Alchemy/Phrasea/Vocabulary/ControlProvider/UserProvider.php @@ -56,7 +56,7 @@ class UserProvider implements ControlProviderInterface ->like(\User_Query::LIKE_LOGIN, $query) ->like_match(\User_Query::LIKE_MATCH_OR) ->include_phantoms(true) - ->on_bases_where_i_am($this->app->getAclForUser($for_user), ['canadmin']) + ->on_bases_where_i_am($this->app->getAclForUser($for_user), [\ACL::CANADMIN]) ->limit(0, 50) ->execute()->get_results(); diff --git a/lib/classes/ACL.php b/lib/classes/ACL.php index 5a851a7dc4..e07bb62ee0 100644 --- a/lib/classes/ACL.php +++ b/lib/classes/ACL.php @@ -32,25 +32,42 @@ use Doctrine\DBAL\DBALException; class ACL implements cache_cacheableInterface { + const ACTIF = 'actif'; + const CANADDRECORD = 'canaddrecord'; + const CANADMIN = 'canadmin'; + const CANCMD = 'cancmd'; + const CANDELETERECORD = 'candeleterecord'; + const CANDWNLDHD = 'candwnldhd'; + const CANDWNLDPREVIEW = 'candwnldpreview'; + const CANMODIFRECORD = 'canmodifrecord'; + const CANPUSH = 'canpush'; + const CANPUTINALBUM = 'canputinalbum'; + const CANREPORT = 'canreport'; + const CHGSTATUS = 'chgstatus'; + const IMGTOOLS = 'imgtools'; + const COLL_MANAGE = 'manage'; + const COLL_MODIFY_STRUCT = 'modify_struct'; + const NOWATERMARK = 'nowatermark'; + const ORDER_MASTER = 'order_master'; protected static $bas_rights = [ 'actif', 'canaddrecord', - 'canadmin', + self::CANADMIN, 'cancmd', - 'candeleterecord', - 'candwnldhd', - 'candwnldpreview', - 'canmodifrecord', + self::CANDELETERECORD, + self::CANDWNLDHD, + self::CANDWNLDPREVIEW, + self::CANMODIFRECORD, 'canpush', - 'canputinalbum', + self::CANPUTINALBUM, 'canreport', - 'chgstatus', - 'imgtools', - 'manage', - 'modify_struct', + self::CHGSTATUS, + self::IMGTOOLS, + self::COLL_MANAGE, + self::COLL_MODIFY_STRUCT, 'nowatermark', - 'order_master', + self::ORDER_MASTER, ]; /** @@ -89,23 +106,23 @@ class ACL implements cache_cacheableInterface protected $is_admin; protected $_global_rights = [ - 'addrecord' => false, - 'addtoalbum' => false, + self::CANADDRECORD => false, + self::CANPUTINALBUM => false, 'bas_chupub' => false, 'bas_manage' => false, 'bas_modif_th' => false, 'bas_modify_struct' => false, - 'candwnldhd' => true, + self::CANDWNLDHD => true, 'candwnldpreview' => true, - 'changestatus' => false, - 'coll_manage' => false, - 'coll_modify_struct' => false, - 'deleterecord' => false, - 'doctools' => false, - 'manageusers' => false, - 'modifyrecord' => false, + self::CHGSTATUS => false, + self::COLL_MANAGE => false, + self::COLL_MODIFY_STRUCT => false, + self::CANDELETERECORD => false, + self::IMGTOOLS => false, + self::CANADMIN => false, + self::CANMODIFRECORD => false, 'order' => false, - 'order_master' => false, + self::ORDER_MASTER => false, 'push' => false, 'report' => false, 'taskmanager' => false, @@ -124,6 +141,7 @@ class ACL implements cache_cacheableInterface const CACHE_GLOBAL_RIGHTS = 'global_rights'; const GRANT_ACTION_PUSH = 'push'; const GRANT_ACTION_VALIDATE = 'validate'; + const GRANT_ACTION_ORDER = 'order'; /** * Constructor @@ -179,17 +197,16 @@ class ACL implements cache_cacheableInterface public function grant_hd_on(RecordReferenceInterface $record, User $pusher, $action) { - $sql = 'REPLACE INTO records_rights - (id, usr_id, sbas_id, record_id, document, `case`, pusher_usr_id) - VALUES - (null, :usr_id, :sbas_id, :record_id, 1, :case, :pusher)'; + $sql = "REPLACE INTO records_rights\n" + . "(id, usr_id, sbas_id, record_id, document, `case`, pusher_usr_id)\n" + . "VALUES (null, :usr_id, :sbas_id, :record_id, 1, :case, :pusher)"; $params = [ - ':usr_id' => $this->user->getId() - , ':sbas_id' => $record->getDataboxId() - , ':record_id' => $record->getRecordId() - , ':case' => $action - , ':pusher' => $pusher->getId() + ':usr_id' => $this->user->getId(), + ':sbas_id' => $record->getDataboxId(), + ':record_id' => $record->getRecordId(), + ':case' => $action, + ':pusher' => $pusher->getId() ]; $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); @@ -203,10 +220,10 @@ class ACL implements cache_cacheableInterface public function grant_preview_on(RecordReferenceInterface $record, User $pusher, $action) { - $sql = 'REPLACE INTO records_rights - (id, usr_id, sbas_id, record_id, preview, `case`, pusher_usr_id) - VALUES - (null, :usr_id, :sbas_id, :record_id, 1, :case, :pusher)'; + $sql = "REPLACE INTO records_rights\n" + . " (id, usr_id, sbas_id, record_id, preview, `case`, pusher_usr_id)\n" + . " VALUES\n" + . " (null, :usr_id, :sbas_id, :record_id, 1, :case, :pusher)"; $params = [ ':usr_id' => $this->user->getId() @@ -279,11 +296,11 @@ class ACL implements cache_cacheableInterface if ($subdef_class == databox_subdef::CLASS_THUMBNAIL) { $granted = true; - } elseif ($subdef_class == databox_subdef::CLASS_PREVIEW && $this->has_right_on_base($record->getBaseId(), 'candwnldpreview')) { + } elseif ($subdef_class == databox_subdef::CLASS_PREVIEW && $this->has_right_on_base($record->getBaseId(), self::CANDWNLDPREVIEW)) { $granted = true; } elseif ($subdef_class == databox_subdef::CLASS_PREVIEW && $this->has_preview_grant($record)) { $granted = true; - } elseif ($subdef_class == databox_subdef::CLASS_DOCUMENT && $this->has_right_on_base($record->getBaseId(), 'candwnldhd')) { + } elseif ($subdef_class == databox_subdef::CLASS_DOCUMENT && $this->has_right_on_base($record->getBaseId(), self::CANDWNLDHD)) { $granted = true; } elseif ($subdef_class == databox_subdef::CLASS_DOCUMENT && $this->has_hd_grant($record)) { $granted = true; @@ -448,10 +465,10 @@ class ACL implements cache_cacheableInterface } /** - * - * @param int $base_id - * @param string $right - * @return boolean + * @param $base_id + * @param $right + * @return bool + * @throws Exception */ public function has_right_on_base($base_id, $right) { @@ -472,9 +489,8 @@ class ACL implements cache_cacheableInterface } /** - * - * @param $option - * @return + * @param string|null $option + * @return string */ public function get_cache_key($option = null) { @@ -482,9 +498,7 @@ class ACL implements cache_cacheableInterface } /** - * - * @param $option - * @return + * @param string|null $option */ public function delete_data_from_cache($option = null) { @@ -508,13 +522,12 @@ class ACL implements cache_cacheableInterface break; } - return $this->app->getApplicationBox()->delete_data_from_cache($this->get_cache_key($option)); + $this->app->getApplicationBox()->delete_data_from_cache($this->get_cache_key($option)); } /** - * - * @param $option - * @return + * @param string|null $option + * @return array */ public function get_data_from_cache($option = null) { @@ -522,11 +535,10 @@ class ACL implements cache_cacheableInterface } /** - * - * @param $value - * @param $option - * @param $duration - * @return + * @param $value + * @param string|null $option + * @param int $duration + * @return bool */ public function set_data_to_cache($value, $option = null, $duration = 0) { @@ -824,8 +836,7 @@ class ACL implements cache_cacheableInterface } catch (\Exception $e) { } - $sql = 'SELECT sbas_id, record_id, preview, document - FROM records_rights WHERE usr_id = :usr_id'; + $sql = "SELECT sbas_id, record_id, preview, document FROM records_rights WHERE usr_id = :usr_id"; $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); $stmt->execute([':usr_id' => $this->user->getId()]); @@ -844,8 +855,8 @@ class ACL implements cache_cacheableInterface } $datas = [ - 'preview' => $this->_rights_records_preview - , 'document' => $this->_rights_records_document + 'preview' => $this->_rights_records_preview, + 'document' => $this->_rights_records_document ]; $this->set_data_to_cache($datas, self::CACHE_RIGHTS_RECORDS); @@ -883,9 +894,7 @@ class ACL implements cache_cacheableInterface } - $sql = 'SELECT sbasusr.* FROM sbasusr, sbas - WHERE usr_id= :usr_id - AND sbas.sbas_id = sbasusr.sbas_id'; + $sql = "SELECT sbasusr.* FROM sbasusr INNER JOIN sbas USING(sbas_id) WHERE usr_id= :usr_id"; $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); $stmt->execute([':usr_id' => $this->user->getId()]); @@ -900,20 +909,12 @@ class ACL implements cache_cacheableInterface $this->_global_rights['bas_chupub'] = false; foreach ($rs as $row) { - - if ($row['bas_modif_th'] == '1') - $this->_global_rights['bas_modif_th'] = true; - if ($row['bas_modify_struct'] == '1') - $this->_global_rights['bas_modify_struct'] = true; - if ($row['bas_manage'] == '1') - $this->_global_rights['bas_manage'] = true; - if ($row['bas_chupub'] == '1') - $this->_global_rights['bas_chupub'] = true; - - $this->_rights_sbas[$row['sbas_id']]['bas_modify_struct'] = ($row['bas_modify_struct'] == '1'); - $this->_rights_sbas[$row['sbas_id']]['bas_manage'] = ($row['bas_manage'] == '1'); - $this->_rights_sbas[$row['sbas_id']]['bas_chupub'] = ($row['bas_chupub'] == '1'); - $this->_rights_sbas[$row['sbas_id']]['bas_modif_th'] = ($row['bas_modif_th'] == '1'); + $sbid = $row['sbas_id']; + $this->_rights_sbas[$sbid] = []; + $this->_global_rights['bas_modif_th'] |= ($this->_rights_sbas[$sbid]['bas_modif_th'] = ($row['bas_modif_th'] == '1')); + $this->_global_rights['bas_modify_struct'] |= ($this->_rights_sbas[$sbid]['bas_modify_struct'] = ($row['bas_modify_struct'] == '1')); + $this->_global_rights['bas_manage'] |= ($this->_rights_sbas[$sbid]['bas_manage'] = ($row['bas_manage'] == '1')); + $this->_global_rights['bas_chupub'] |= ($this->_rights_sbas[$sbid]['bas_chupub'] = ($row['bas_chupub'] == '1')); } $this->set_data_to_cache($this->_rights_sbas, self::CACHE_RIGHTS_SBAS); $this->set_data_to_cache($this->_global_rights, self::CACHE_GLOBAL_RIGHTS); @@ -956,9 +957,9 @@ class ACL implements cache_cacheableInterface } $sql = "SELECT u.* FROM basusr u, bas b, sbas s\n" - . "WHERE usr_id= :usr_id\n" - . "AND b.base_id = u.base_id\n" - . "AND s.sbas_id = b.sbas_id"; + . " WHERE usr_id= :usr_id\n" + . " AND b.base_id = u.base_id\n" + . " AND s.sbas_id = b.sbas_id"; $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); $stmt->execute([':usr_id' => $this->user->getId()]); @@ -967,55 +968,25 @@ class ACL implements cache_cacheableInterface $this->_rights_bas = $this->_limited = []; - $this->_global_rights['manageusers'] = false; - $this->_global_rights['coll_manage'] = false; - $this->_global_rights['coll_modify_struct'] = false; + $this->_global_rights[self::CANADMIN] = false; + $this->_global_rights[self::COLL_MANAGE] = false; + $this->_global_rights[self::COLL_MODIFY_STRUCT] = false; $this->_global_rights['order'] = false; $this->_global_rights['push'] = false; - $this->_global_rights['addrecord'] = false; - $this->_global_rights['modifyrecord'] = false; - $this->_global_rights['changestatus'] = false; - $this->_global_rights['doctools'] = false; - $this->_global_rights['deleterecord'] = false; - $this->_global_rights['addtoalbum'] = false; + $this->_global_rights[self::CANADDRECORD] = false; + $this->_global_rights[self::CANMODIFRECORD] = false; + $this->_global_rights[self::CHGSTATUS] = false; + $this->_global_rights[self::IMGTOOLS] = false; + $this->_global_rights[self::CANDELETERECORD] = false; + $this->_global_rights[self::CANPUTINALBUM] = false; $this->_global_rights['report'] = false; - $this->_global_rights['candwnldpreview'] = false; - $this->_global_rights['candwnldhd'] = false; - $this->_global_rights['order_master'] = false; + $this->_global_rights[self::CANDWNLDPREVIEW] = false; + $this->_global_rights[self::CANDWNLDHD] = false; + $this->_global_rights[self::ORDER_MASTER] = false; foreach ($rs as $row) { - $this->_rights_bas[$row['base_id']]['actif'] = ($row['actif'] == '1'); - - if ($row['canadmin'] == '1') - $this->_global_rights['manageusers'] = true; - if ($row['manage'] == '1') - $this->_global_rights['coll_manage'] = true; - if ($row['modify_struct'] == '1') - $this->_global_rights['coll_modify_struct'] = true; - if ($row['cancmd'] == '1') - $this->_global_rights['order'] = true; - if ($row['canpush'] == '1') - $this->_global_rights['push'] = true; - if ($row['canaddrecord'] == '1') - $this->_global_rights['addrecord'] = true; - if ($row['canmodifrecord'] == '1') - $this->_global_rights['modifyrecord'] = true; - if ($row['chgstatus'] == '1') - $this->_global_rights['changestatus'] = true; - if ($row['imgtools'] == '1') - $this->_global_rights['doctools'] = true; - if ($row['candeleterecord'] == '1') - $this->_global_rights['deleterecord'] = true; - if ($row['canputinalbum'] == '1') - $this->_global_rights['addtoalbum'] = true; - if ($row['canreport'] == '1') - $this->_global_rights['report'] = true; - if ($row['candwnldpreview'] == '1') - $this->_global_rights['candwnldpreview'] = true; - if ($row['candwnldhd'] == '1') - $this->_global_rights['candwnldhd'] = true; - if ($row['order_master'] == '1') - $this->_global_rights['order_master'] = true; + $bid = $row['base_id']; + $this->_rights_bas[$bid]['actif'] = ($row['actif'] == '1'); $row['limited_from'] = $row['limited_from'] == '0000-00-00 00:00:00' ? '' : trim($row['limited_from']); $row['limited_to'] = $row['limited_to'] == '0000-00-00 00:00:00' ? '' : trim($row['limited_to']); @@ -1023,54 +994,41 @@ class ACL implements cache_cacheableInterface if ($row['time_limited'] == '1' && ($row['limited_from'] !== '' || $row['limited_to'] !== '')) { $this->_limited[$row['base_id']] = [ - 'dmin' => $row['limited_from'] ? new DateTime($row['limited_from']) : null - , 'dmax' => $row['limited_to'] ? new DateTime($row['limited_to']) : null + 'dmin' => $row['limited_from'] ? new DateTime($row['limited_from']) : null, + 'dmax' => $row['limited_to'] ? new DateTime($row['limited_to']) : null ]; } - $this->_rights_bas[$row['base_id']]['imgtools'] - = $row['imgtools'] == '1'; + $this->_global_rights[self::IMGTOOLS] |= ($this->_rights_bas[$bid][self::IMGTOOLS] = ($row['imgtools'] == '1')); + $this->_global_rights[self::CHGSTATUS] |= ($this->_rights_bas[$bid][self::CHGSTATUS] = ($row['chgstatus'] == '1')); + $this->_global_rights['order'] |= ($this->_rights_bas[$bid]['cancmd'] = ($row['cancmd'] == '1')); + $this->_global_rights[self::CANADDRECORD] |= ($this->_rights_bas[$bid][self::CANADDRECORD] = ($row['canaddrecord'] == '1')); + $this->_global_rights['push'] |= ($this->_rights_bas[$bid]['canpush'] = ($row['canpush'] == '1')); + $this->_global_rights[self::CANDELETERECORD] |= ($this->_rights_bas[$bid][self::CANDELETERECORD] = ($row['candeleterecord'] == '1')); + $this->_global_rights[self::CANADMIN] |= ($this->_rights_bas[$bid][self::CANADMIN] = ($row['canadmin'] == '1')); + $this->_global_rights[self::CANDWNLDPREVIEW] |= ($this->_rights_bas[$bid][self::CANDWNLDPREVIEW] = ($row['candwnldpreview'] == '1')); + $this->_global_rights[self::CANDWNLDHD] |= ($this->_rights_bas[$bid][self::CANDWNLDHD] = ($row['candwnldhd'] == '1')); + $this->_global_rights[self::CANMODIFRECORD] |= ($this->_rights_bas[$bid][self::CANMODIFRECORD] = ($row['canmodifrecord'] == '1')); + $this->_global_rights[self::CANPUTINALBUM] |= ($this->_rights_bas[$bid][self::CANPUTINALBUM] = ($row['canputinalbum'] == '1')); + $this->_global_rights['report'] |= ($this->_rights_bas[$bid]['canreport'] = ($row['canreport'] == '1')); + $this->_global_rights[self::COLL_MODIFY_STRUCT] |= ($this->_rights_bas[$bid][self::COLL_MODIFY_STRUCT] = ($row['modify_struct'] == '1')); + $this->_global_rights[self::COLL_MANAGE] |= ($this->_rights_bas[$bid][self::COLL_MANAGE] = ($row['manage'] == '1')); + $this->_global_rights[self::ORDER_MASTER] |= ($this->_rights_bas[$bid][self::ORDER_MASTER] = ($row[\ACL::ORDER_MASTER] == '1')); + $this->_rights_bas[$bid]['nowatermark'] = ($row['nowatermark'] == '1'); + $this->_rights_bas[$bid]['restrict_dwnld'] = ($row['restrict_dwnld'] == '1'); + $this->_rights_bas[$bid]['remain_dwnld'] = (int) $row['remain_dwnld']; + $this->_rights_bas[$bid]['mask_and'] = (int) $row['mask_and']; + $this->_rights_bas[$bid]['mask_xor'] = (int) $row['mask_xor']; - $this->_rights_bas[$row['base_id']]['chgstatus'] - = $row['chgstatus'] == '1'; - $this->_rights_bas[$row['base_id']]['cancmd'] - = $row['cancmd'] == '1'; - $this->_rights_bas[$row['base_id']]['canaddrecord'] - = $row['canaddrecord'] == '1'; - $this->_rights_bas[$row['base_id']]['canpush'] - = $row['canpush'] == '1'; - $this->_rights_bas[$row['base_id']]['candeleterecord'] - = $row['candeleterecord'] == '1'; - $this->_rights_bas[$row['base_id']]['canadmin'] - = $row['canadmin'] == '1'; - $this->_rights_bas[$row['base_id']]['chgstatus'] - = $row['chgstatus'] == '1'; - $this->_rights_bas[$row['base_id']]['candwnldpreview'] - = $row['candwnldpreview'] == '1'; - $this->_rights_bas[$row['base_id']]['candwnldhd'] - = $row['candwnldhd'] == '1'; - $this->_rights_bas[$row['base_id']]['nowatermark'] - = $row['nowatermark'] == '1'; - $this->_rights_bas[$row['base_id']]['restrict_dwnld'] - = $row['restrict_dwnld'] == '1'; - $this->_rights_bas[$row['base_id']]['remain_dwnld'] - = (int) $row['remain_dwnld']; - $this->_rights_bas[$row['base_id']]['canmodifrecord'] - = $row['canmodifrecord'] == '1'; - $this->_rights_bas[$row['base_id']]['canputinalbum'] - = $row['canputinalbum'] == '1'; - $this->_rights_bas[$row['base_id']]['canreport'] - = $row['canreport'] == '1'; - $this->_rights_bas[$row['base_id']]['mask_and'] - = (int) $row['mask_and']; - $this->_rights_bas[$row['base_id']]['mask_xor'] - = (int) $row['mask_xor']; - $this->_rights_bas[$row['base_id']]['modify_struct'] - = $row['modify_struct'] == '1'; - $this->_rights_bas[$row['base_id']]['manage'] - = $row['manage'] == '1'; - $this->_rights_bas[$row['base_id']]['order_master'] - = $row['order_master'] == '1'; + $row['limited_from'] = $row['limited_from'] == '0000-00-00 00:00:00' ? '' : trim($row['limited_from']); + $row['limited_to'] = $row['limited_to'] == '0000-00-00 00:00:00' ? '' : trim($row['limited_to']); + + if ($row['time_limited'] == '1' && ($row['limited_from'] !== '' || $row['limited_to'] !== '')) { + $this->_limited[$row['base_id']] = [ + 'dmin' => $row['limited_from'] ? new DateTime($row['limited_from']) : null, + 'dmax' => $row['limited_to'] ? new DateTime($row['limited_to']) : null + ]; + } } $this->set_data_to_cache($this->_global_rights, self::CACHE_GLOBAL_RIGHTS); @@ -1106,17 +1064,17 @@ class ACL implements cache_cacheableInterface case 'admin': return ( ($this->has_right('bas_modify_struct') || - $this->has_right('coll_modify_struct') || + $this->has_right(self::COLL_MODIFY_STRUCT) || $this->has_right('bas_manage') || - $this->has_right('coll_manage') || - $this->has_right('manageusers') || + $this->has_right(self::COLL_MANAGE) || + $this->has_right(self::CANADMIN) || $this->is_admin()) ); break; case 'thesaurus': return ($this->has_right('bas_modif_th') === true ); break; case 'upload': - return ($this->has_right('addrecord') === true); + return ($this->has_right(self::CANADDRECORD) === true); break; case 'report': return ($this->has_right('report') === true); @@ -1168,48 +1126,31 @@ class ACL implements cache_cacheableInterface */ public function give_access_to_base(Array $base_ids) { - $sql_ins = 'INSERT INTO basusr (id, base_id, usr_id, actif) - VALUES (null, :base_id, :usr_id, "1")'; - $stmt_ins = $this->app->getApplicationBox()->get_connection()->prepare($sql_ins); + $sql = "INSERT INTO basusr (id, base_id, usr_id, actif)\n" + . "VALUES (null, :base_id, :usr_id, '1')\n" + . "ON DUPLICATE KEY UPDATE actif='1"; + $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); $usr_id = $this->user->getId(); - $to_update = []; + $this->load_rights_bas(); foreach ($base_ids as $base_id) { - if (!isset($this->_rights_bas[$base_id])) { - try { - $stmt_ins->execute([':base_id' => $base_id, ':usr_id' => $usr_id]); - } catch (DBALException $e) { -// if (null !== $e) { -// var_dump(get_class($e->getPrevious())); -// } - if (($e->getCode() == 23000)) { - $to_update[] = $base_id; - } + if (!isset($this->_rights_bas[$base_id]) || $this->_rights_bas[$base_id]['actif'] === false) { + $stmt->execute([':base_id' => $base_id, ':usr_id' => $usr_id]); + if($stmt->rowCount() > 0) { + $this->app['dispatcher']->dispatch( + AclEvents::ACCESS_TO_BASE_GRANTED, + new AccessToBaseGrantedEvent( + $this, + array( + 'base_id'=>$base_id + ) + ) + ); } - } elseif ($this->_rights_bas[$base_id]['actif'] === false) { - $to_update[] = $base_id; } } - $stmt_ins->closeCursor(); - - $sql_upd = 'UPDATE basusr SET actif="1" - WHERE usr_id = :usr_id AND base_id = :base_id'; - $stmt_upd = $this->app->getApplicationBox()->get_connection()->prepare($sql_upd); - foreach ($to_update as $base_id) { - $stmt_upd->execute([':usr_id' => $usr_id, ':base_id' => $base_id]); - - $this->app['dispatcher']->dispatch( - AclEvents::ACCESS_TO_BASE_GRANTED, - new AccessToBaseGrantedEvent( - $this, - array( - 'base_id'=>$base_id - ) - ) - ); - } - $stmt_upd->closeCursor(); + $stmt->closeCursor(); $this->delete_data_from_cache(self::CACHE_RIGHTS_BAS); $this->inject_rights(); @@ -1358,23 +1299,21 @@ class ACL implements cache_cacheableInterface $sql_args = []; $usr_id = $this->user->getId(); - $params = [':sbas_id' => $sbas_id, ':usr_id' => $usr_id]; foreach ($rights as $right => $v) { - $sql_args[] = " " . $right . " = :" . $right; - $params[':' . $right] = $v ? '1' : '0'; + $sql_args[] = "`" . $right . "`=" . ($v ? '1' : '0'); } if (count($sql_args) == 0) { return $this; } - $sql_up .= implode(', ', $sql_args) . ' - WHERE sbas_id = :sbas_id AND usr_id = :usr_id'; + $sql_up .= implode(', ', $sql_args) . "\n" + . " WHERE sbas_id = :sbas_id AND usr_id = :usr_id"; $stmt_up = $this->app->getApplicationBox()->get_connection()->prepare($sql_up); - if (!$stmt_up->execute($params)) { + if (!$stmt_up->execute([':sbas_id' => $sbas_id, ':usr_id' => $usr_id])) { throw new Exception('Error while updating some rights'); } $stmt_up->closeCursor(); @@ -1401,9 +1340,8 @@ class ACL implements cache_cacheableInterface */ public function remove_quotas_on_base($base_id) { - $sql = 'UPDATE basusr - SET remain_dwnld = 0, restrict_dwnld = 0, month_dwnld_max = 0 - WHERE usr_id = :usr_id AND base_id = :base_id '; + $sql = "UPDATE basusr SET remain_dwnld = 0, restrict_dwnld = 0, month_dwnld_max = 0\n" + . " WHERE usr_id = :usr_id AND base_id = :base_id"; $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); $stmt->execute([':usr_id' => $this->user->getId(), ':base_id' => $base_id]); @@ -1427,16 +1365,15 @@ class ACL implements cache_cacheableInterface public function update_download_restrictions() { - $sql = 'UPDATE basusr SET remain_dwnld = month_dwnld_max - WHERE actif = 1 - AND usr_id = :usr_id - AND MONTH(lastconn) != MONTH(NOW()) AND restrict_dwnld = 1'; + $sql = "UPDATE basusr SET remain_dwnld = month_dwnld_max\n" + . " WHERE actif = 1" + . " AND usr_id = :usr_id" + . " AND MONTH(lastconn) != MONTH(NOW()) AND restrict_dwnld = 1'"; $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); $stmt->execute([':usr_id' => $this->user->getId()]); $stmt->closeCursor(); - $sql = "UPDATE basusr SET lastconn=now() - WHERE usr_id = :usr_id AND actif = 1"; + $sql = "UPDATE basusr SET lastconn=now() WHERE usr_id = :usr_id AND actif = 1"; $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); $stmt->execute([':usr_id' => $this->user->getId()]); $stmt->closeCursor(); @@ -1463,9 +1400,8 @@ class ACL implements cache_cacheableInterface */ public function set_quotas_on_base($base_id, $droits, $restes) { - $sql = 'UPDATE basusr - SET remain_dwnld = :restes, restrict_dwnld = 1, month_dwnld_max = :droits - WHERE usr_id = :usr_id AND base_id = :base_id '; + $sql = "UPDATE basusr SET remain_dwnld = :restes, restrict_dwnld = 1, month_dwnld_max = :droits\n" + . " WHERE usr_id = :usr_id AND base_id = :base_id"; $params = [ ':usr_id' => $this->user->getId(), @@ -1498,8 +1434,7 @@ class ACL implements cache_cacheableInterface public function duplicate_right_from_bas($base_id_from, $base_id_dest) { - $sql = 'SELECT * FROM basusr - WHERE base_id = :base_from AND usr_id = :usr_id'; + $sql = "SELECT * FROM basusr WHERE base_id = :base_from AND usr_id = :usr_id"; $params = [ ':base_from' => $base_id_from, @@ -1522,16 +1457,12 @@ class ACL implements cache_cacheableInterface 'mask_xor' => $row['mask_xor'], ]; - if ($row['canputinalbum']) - $rights['canputinalbum'] = true; - if ($row['candwnldhd']) - $rights['candwnldhd'] = true; - if ($row['candwnldpreview']) - $rights['candwnldpreview'] = true; + $rights[self::CANPUTINALBUM] = ($row['canputinalbum'] == '1'); + $rights[self::CANDWNLDHD] = ($row['candwnldhd'] == '1'); + $rights[self::CANDWNLDPREVIEW] = ($row['candwnldpreview'] == '1'); if ($row['cancmd']) $rights['cancmd'] = true; - if ($row['canadmin']) - $rights['canadmin'] = true; + $rights[self::CANADMIN] = ($row['canadmin'] == '1'); if ($row['canreport']) $rights['canreport'] = true; if ($row['canpush']) @@ -1540,18 +1471,12 @@ class ACL implements cache_cacheableInterface $rights['nowatermark'] = true; if ($row['canaddrecord']) $rights['canaddrecord'] = true; - if ($row['canmodifrecord']) - $rights['canmodifrecord'] = true; - if ($row['candeleterecord']) - $rights['candeleterecord'] = true; - if ($row['chgstatus']) - $rights['chgstatus'] = true; - if ($row['imgtools']) - $rights['imgtools'] = true; - if ($row['manage']) - $rights['manage'] = true; - if ($row['modify_struct']) - $rights['modify_struct'] = true; + $rights[self::CANMODIFRECORD] = ($row['canmodifrecord' == '1']); + $rights[self::CANDELETERECORD] = ($row['candeleterecord'] == '1'); + $rights[self::CHGSTATUS] = ($row['chgstatus'] == '1'); + $rights[self::IMGTOOLS] = ($row['imgtools'] == '1'); + $rights[self::COLL_MANAGE] = ($row['manage'] == '1'); + $rights[self::COLL_MODIFY_STRUCT] = ($row['modify_struct'] == '1'); $this->update_rights_to_base($base_id_dest, $rights); @@ -1695,6 +1620,13 @@ class ACL implements cache_cacheableInterface return $lim_max || $lim_min; } + /** + * returns date limits ['dmin'=>x, 'dmax'=>y] with x,y : NullableDateTime + * + * + * @param $base_id + * @return array|null + */ public function get_limits($base_id) { $this->load_rights_bas(); @@ -1753,7 +1685,7 @@ class ACL implements cache_cacheableInterface { // a user can see the business fields if he has at least the right on one collection to edit a record foreach($databox->get_collections() as $collection) { - if ($this->has_access_to_base($collection->get_base_id()) && $this->has_right_on_base($collection->get_base_id(), 'canmodifrecord')) { + if ($this->has_access_to_base($collection->get_base_id()) && $this->has_right_on_base($collection->get_base_id(), self::CANMODIFRECORD)) { return true; } } @@ -1768,7 +1700,7 @@ class ACL implements cache_cacheableInterface */ public function getOrderMasterCollectionsBaseIds() { - $sql = 'SELECT base_id FROM basusr WHERE order_master="1" AND usr_id= :usr_id'; + $sql = "SELECT base_id FROM basusr WHERE order_master='1' AND usr_id= :usr_id"; $result = $this->app->getApplicationBox() ->get_connection() ->executeQuery($sql, [':usr_id' => $this->user->getId()]) @@ -1819,8 +1751,7 @@ class ACL implements cache_cacheableInterface */ public function set_order_master(\collection $collection, $bool) { - $sql = 'UPDATE basusr SET order_master = :master - WHERE usr_id = :usr_id AND base_id = :base_id'; + $sql = "UPDATE basusr SET order_master = :master WHERE usr_id = :usr_id AND base_id = :base_id"; $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); $stmt->execute([ diff --git a/lib/classes/databox.php b/lib/classes/databox.php index 9e8c32ad33..6d21264272 100644 --- a/lib/classes/databox.php +++ b/lib/classes/databox.php @@ -1155,22 +1155,22 @@ class databox extends base implements ThumbnailedElement foreach ($base_ids as $base_id) { $this->app->getAclForUser($user)->update_rights_to_base($base_id, [ - 'canpush' => 1, - 'cancmd' => 1, - 'canputinalbum' => 1, - 'candwnldhd' => 1, - 'candwnldpreview' => 1, - 'canadmin' => 1, - 'actif' => 1, - 'canreport' => 1, - 'canaddrecord' => 1, - 'canmodifrecord' => 1, - 'candeleterecord' => 1, - 'chgstatus' => 1, - 'imgtools' => 1, - 'manage' => 1, - 'modify_struct' => 1, - 'nowatermark' => 1 + \ACL::CANPUSH => 1, + \ACL::CANCMD => 1, + \ACL::CANPUTINALBUM => 1, + \ACL::CANDWNLDHD => 1, + \ACL::CANDWNLDPREVIEW => 1, + \ACL::CANADMIN => 1, + \ACL::ACTIF => 1, + \ACL::CANREPORT => 1, + \ACL::CANADDRECORD => 1, + \ACL::CANMODIFRECORD => 1, + \ACL::CANDELETERECORD => 1, + \ACL::CHGSTATUS => 1, + \ACL::IMGTOOLS => 1, + \ACL::MANAGE => 1, + \ACL::MODIFY_STRUCT => 1, + \ACL::NOWATERMARK => 1 ]); } diff --git a/lib/classes/databox/status.php b/lib/classes/databox/status.php index cf3a817ded..744041e034 100644 --- a/lib/classes/databox/status.php +++ b/lib/classes/databox/status.php @@ -24,7 +24,7 @@ class databox_status foreach ($app->getAclForUser($app->getAuthenticatedUser())->get_granted_sbas() as $databox) { $see_all = false; foreach ($databox->get_collections() as $collection) { - if ($app->getAclForUser($app->getAuthenticatedUser())->has_right_on_base($collection->get_base_id(), 'chgstatus')) { + if ($app->getAclForUser($app->getAuthenticatedUser())->has_right_on_base($collection->get_base_id(), \ACL::CHGSTATUS)) { $see_all = true; break; } diff --git a/lib/classes/eventsmanager/notify/autoregister.php b/lib/classes/eventsmanager/notify/autoregister.php index a4a609087b..d9749f8835 100644 --- a/lib/classes/eventsmanager/notify/autoregister.php +++ b/lib/classes/eventsmanager/notify/autoregister.php @@ -73,6 +73,6 @@ class eventsmanager_notify_autoregister extends eventsmanager_notifyAbstract return false; } - return $this->app->getAclForUser($user)->has_right('manageusers'); + return $this->app->getAclForUser($user)->has_right(\ACL::CANADMIN); } } diff --git a/lib/classes/eventsmanager/notify/order.php b/lib/classes/eventsmanager/notify/order.php index 734530fe6e..d5aca30998 100644 --- a/lib/classes/eventsmanager/notify/order.php +++ b/lib/classes/eventsmanager/notify/order.php @@ -75,6 +75,6 @@ class eventsmanager_notify_order extends eventsmanager_notifyAbstract */ public function is_available(User $user) { - return $this->app->getAclForUser($user)->has_right('order_master'); + return $this->app->getAclForUser($user)->has_right(\ACL::ORDER_MASTER); } } diff --git a/lib/classes/eventsmanager/notify/register.php b/lib/classes/eventsmanager/notify/register.php index 8d58b6f001..c0d7222251 100644 --- a/lib/classes/eventsmanager/notify/register.php +++ b/lib/classes/eventsmanager/notify/register.php @@ -75,6 +75,6 @@ class eventsmanager_notify_register extends eventsmanager_notifyAbstract return false; } - return $this->app->getAclForUser($user)->has_right('manageusers'); + return $this->app->getAclForUser($user)->has_right(\ACL::CANADMIN); } } diff --git a/lib/classes/eventsmanager/notify/uploadquarantine.php b/lib/classes/eventsmanager/notify/uploadquarantine.php index 4f1a82b57f..e44f2d66e3 100644 --- a/lib/classes/eventsmanager/notify/uploadquarantine.php +++ b/lib/classes/eventsmanager/notify/uploadquarantine.php @@ -75,6 +75,6 @@ class eventsmanager_notify_uploadquarantine extends eventsmanager_notifyAbstract */ public function is_available(User $user) { - return $this->app->getAclForUser($user)->has_right('addrecord'); + return $this->app->getAclForUser($user)->has_right(\ACL::CANADDRECORD); } } diff --git a/lib/classes/record/exportElement.php b/lib/classes/record/exportElement.php index ddae4ca66d..cf3f1b6d5f 100644 --- a/lib/classes/record/exportElement.php +++ b/lib/classes/record/exportElement.php @@ -99,10 +99,10 @@ class record_exportElement extends record_adapter 'thumbnail' => true ]; - if ($this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($this->getBaseId(), 'candwnldhd')) { + if ($this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($this->getBaseId(), \ACL::CANDWNLDHD)) { $go_dl['document'] = true; } - if ($this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($this->getBaseId(), 'candwnldpreview')) { + if ($this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($this->getBaseId(), \ACL::CANDWNLDPREVIEW)) { $go_dl['preview'] = true; } if ($this->app->getAclForUser($this->app->getAuthenticatedUser())->has_hd_grant($this)) { @@ -116,7 +116,7 @@ class record_exportElement extends record_adapter $query = $this->app['phraseanet.user-query']; $masters = $query->on_base_ids([$this->getBaseId()]) - ->who_have_right(['order_master']) + ->who_have_right([\ACL::ORDER_MASTER]) ->execute()->get_results(); $go_cmd = (count($masters) > 0 && $this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($this->getBaseId(), 'cancmd')); diff --git a/lib/classes/set/export.php b/lib/classes/set/export.php index 4eb955a930..5658b5645d 100644 --- a/lib/classes/set/export.php +++ b/lib/classes/set/export.php @@ -175,7 +175,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(), 'canmodifrecord')) { + if ($app->getAclForUser($app->getAuthenticatedUser())->has_right_on_base($download_element->getBaseId(), \ACL::CANMODIFRECORD)) { $this->businessFieldsAccess = true; } @@ -227,11 +227,11 @@ class set_export extends set_abstract $display_ftp = []; - $hasadminright = $app->getAclForUser($app->getAuthenticatedUser())->has_right('addrecord') - || $app->getAclForUser($app->getAuthenticatedUser())->has_right('deleterecord') - || $app->getAclForUser($app->getAuthenticatedUser())->has_right('modifyrecord') - || $app->getAclForUser($app->getAuthenticatedUser())->has_right('coll_manage') - || $app->getAclForUser($app->getAuthenticatedUser())->has_right('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 = []; @@ -419,7 +419,7 @@ class set_export extends set_abstract $BF = false; - if ($includeBusinessFields && $this->app->getAclForUser($user)->has_right_on_base($download_element->getBaseId(), 'canmodifrecord')) { + if ($includeBusinessFields && $this->app->getAclForUser($user)->has_right_on_base($download_element->getBaseId(), \ACL::CANMODIFRECORD)) { $BF = true; } diff --git a/templates/web/admin/collection/collection.html.twig b/templates/web/admin/collection/collection.html.twig index a7b2f747a3..72d5eff89e 100644 --- a/templates/web/admin/collection/collection.html.twig +++ b/templates/web/admin/collection/collection.html.twig @@ -35,7 +35,7 @@
  • {{ collection.get_record_amount() }} records {{ 'phraseanet:: details' | trans }}
  • -{% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(bas_id, 'manage') %} +{% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(bas_id, constant('\\ACL::COLL_MANAGE')) %}
    {{ 'admin::collection:: Gestionnaires des commandes' | trans }}
    @@ -144,7 +144,7 @@
    {{ 'admin::base:collection: minilogo actuel' | trans }}
    {% if collection.getLogo(bas_id, app) is not empty %}
    {{ collection.getLogo(bas_id, app) | raw }}
    - {% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(bas_id, 'manage') %} + {% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(bas_id, constant('\\ACL::COLL_MANAGE')) %}
    {% endif%} - {% elseif app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(bas_id, 'manage') %} + {% elseif app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(bas_id, constant('\\ACL::COLL_MANAGE')) %} {{ 'admin::base:collection: aucun fichier (minilogo, watermark ...)' | trans }}
    @@ -169,7 +169,7 @@
    {{ "Watermark" | trans }}
    {% if collection.getWatermark(bas_id) is not empty %}
    {{ collection.getWatermark(bas_id)| raw }}
    - {% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(bas_id, 'manage') %} + {% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(bas_id, constant('\\ACL::COLL_MANAGE')) %} {% endif%} - {% elseif app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(bas_id, 'manage') %} + {% elseif app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(bas_id, constant('\\ACL::COLL_MANAGE')) %} {{ 'admin::base:collection: aucun fichier (minilogo, watermark ...)' | trans }}
    @@ -194,7 +194,7 @@
    {{ "Stamp logo" | trans }}
    {% if collection.getStamp(bas_id) is not empty %}
    {{ collection.getStamp(bas_id)| raw }}
    - {% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(bas_id, 'manage') %} + {% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(bas_id, constant('\\ACL::COLL_MANAGE')) %} {% endif%} - {% elseif app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(bas_id, 'manage') %} + {% elseif app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(bas_id, constant('\\ACL::COLL_MANAGE')) %} {{ 'admin::base:collection: aucun fichier (minilogo, watermark ...)' | trans }}
    diff --git a/templates/web/admin/collection/create.html.twig b/templates/web/admin/collection/create.html.twig index 36cdca68b0..26c0039feb 100644 --- a/templates/web/admin/collection/create.html.twig +++ b/templates/web/admin/collection/create.html.twig @@ -32,10 +32,10 @@
    - {% if app.getAclForUser(app.getAuthenticatedUser()).get_granted_base(["canadmin"]) | length > 0 %} + {% if app.getAclForUser(app.getAuthenticatedUser()).get_granted_base([constant('\\ACL::CANADMIN')]) | length > 0 %} diff --git a/templates/web/admin/databox/databox.html.twig b/templates/web/admin/databox/databox.html.twig index 9182ac6787..fc89409480 100644 --- a/templates/web/admin/databox/databox.html.twig +++ b/templates/web/admin/databox/databox.html.twig @@ -155,7 +155,7 @@
  • {% trans with {'%name%' : name} %}Monter la collection %name%{% endtrans %}
    - {% if app.getAclForUser(app.getAuthenticatedUser()).get_granted_base(["canadmin"]) | length > 0 %} + {% if app.getAclForUser(app.getAuthenticatedUser()).get_granted_base([constant('\\ACL::CANADMIN')]) | length > 0 %}
    {{ 'Select a user in the list' | trans }}
    - {% if app.getAclForUser(app.getAuthenticatedUser()).has_right('manageusers') %} + {% if app.getAclForUser(app.getAuthenticatedUser()).has_right(constant('\\ACL::CANADMIN')) %} {{ 'or' | trans }} {{ 'Add user' | trans }} {% endif %} diff --git a/templates/web/prod/actions/edit_default.html.twig b/templates/web/prod/actions/edit_default.html.twig index 1cf5b739ae..32a12a6fd2 100644 --- a/templates/web/prod/actions/edit_default.html.twig +++ b/templates/web/prod/actions/edit_default.html.twig @@ -27,7 +27,7 @@ {% endif %} {% set class_status = 'nostatus' %} - {% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(record.get_base_id(), 'chgstatus') %} + {% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(record.get_base_id(), constant('\\ACL::CHGSTATUS')) %} {% set class_status = '' %} {% endif %} diff --git a/templates/web/prod/index.html.twig b/templates/web/prod/index.html.twig index d6e6ce422c..4e561bebb5 100644 --- a/templates/web/prod/index.html.twig +++ b/templates/web/prod/index.html.twig @@ -145,7 +145,7 @@ {{ 'Browse Baskets' | trans }}
  • - {% if app['conf'].get(['registry', 'modules', 'stories']) and app.getAclForUser(app.getAuthenticatedUser()).has_right('addrecord') %} + {% if app['conf'].get(['registry', 'modules', 'stories']) and app.getAclForUser(app.getAuthenticatedUser()).has_right(constant('\\ACL::CANADDRECORD')) %}
    diff --git a/templates/web/prod/preview/caption.html.twig b/templates/web/prod/preview/caption.html.twig index a966f22c91..792686f091 100644 --- a/templates/web/prod/preview/caption.html.twig +++ b/templates/web/prod/preview/caption.html.twig @@ -1,6 +1,6 @@ {% import 'common/macros.html.twig' as macro %} - {% set can_edit = granted_on_collection(record.baseId, 'canmodifrecord') %} + {% set can_edit = granted_on_collection(record.baseId, constant('\\ACL::CANMODIFRECORD')) %} {% set can_see_business = can_edit %} {% if can_edit %} diff --git a/templates/web/prod/preview/tools.html.twig b/templates/web/prod/preview/tools.html.twig index 422210e269..184c086712 100644 --- a/templates/web/prod/preview/tools.html.twig +++ b/templates/web/prod/preview/tools.html.twig @@ -1,5 +1,5 @@ -{% if (record.is_from_basket is empty) and app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(record.get_base_id(), 'canputinalbum') %} +{% if (record.is_from_basket is empty) and app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(record.get_base_id(), constant('\\ACL::CANPUTINALBUM')) %}
    @@ -21,7 +21,7 @@
    -{% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(record.get_base_id(), 'candwnldhd') or app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(record.get_base_id(), 'candwnldpreview') %} +{% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(record.get_base_id(), constant('\\ACL::CANDWNLDHD')) or app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(record.get_base_id(), constant('\\ACL::CANDWNLDPREVIEW')) %}
    {# #} diff --git a/templates/web/prod/results/list.html.twig b/templates/web/prod/results/list.html.twig index 7e24f19aaa..9a6a5c433e 100644 --- a/templates/web/prod/results/list.html.twig +++ b/templates/web/prod/results/list.html.twig @@ -13,7 +13,7 @@
    - {% set can_see_business = granted_on_collection(record.baseId, 'canmodifrecord') %} + {% set can_see_business = granted_on_collection(record.baseId, constant('\\ACL::CANMODIFRECORD')) %} {{ macro.caption(record, can_see_business) }}
    diff --git a/templates/web/prod/results/record.html.twig b/templates/web/prod/results/record.html.twig index eb29cc8243..b9512f7de0 100644 --- a/templates/web/prod/results/record.html.twig +++ b/templates/web/prod/results/record.html.twig @@ -18,7 +18,7 @@
    - {% set can_see_business = granted_on_collection(record.baseId, 'canmodifrecord') %} + {% set can_see_business = granted_on_collection(record.baseId, constant('\\ACL::CANMODIFRECORD')) %}
    - {% if granted_on_collection(record.baseId, 'canputinalbum') and not record.story %} + {% if granted_on_collection(record.baseId, constant('\\ACL::CANPUTINALBUM')) and not record.story %}
    @@ -113,7 +113,7 @@
    {% endif %} - {% if granted_on_collection(record.baseId, 'candwnldpreview') or granted_on_collection(record.baseId, 'candwnldhd') %} + {% if granted_on_collection(record.baseId, constant('\\ACL::CANDWNLDPREVIEW')) or granted_on_collection(record.baseId, constant('\\ACL::CANDWNLDHD')) %}
    diff --git a/templates/web/prod/toolbar.html.twig b/templates/web/prod/toolbar.html.twig index 229b9a587b..668a20b230 100644 --- a/templates/web/prod/toolbar.html.twig +++ b/templates/web/prod/toolbar.html.twig @@ -63,19 +63,19 @@ {% set actions = {} %} - {% if acl.has_right('modifyrecord') %} + {% if acl.has_right(constant('\\ACL::CANMODIFRECORD')) %} {% set label %} {{ 'action : editer' | trans }} {% endset %} {% set actions = actions|merge( { 'edit' : {'icon': "/assets/common/images/icons/ppen_history.png", 'class':'TOOL_ppen_btn', 'label' : label} }) %} {% endif %} - {% if acl.has_right('changestatus') %} + {% if acl.has_right(constant('\\ACL::CHGSTATUS')) %} {% set label %} {{ 'action : status' | trans }} {% endset %} {% set actions = actions|merge( { 'status' : {'icon': "/assets/common/images/icons/chgstatus_history.png", 'class':'TOOL_chgstatus_btn', 'label' : label} }) %} {% endif %} - {% if acl.has_right('deleterecord') and acl.has_right('addrecord') %} + {% if acl.has_right(constant('\\ACL::CANDELETERECORD')) and acl.has_right(constant('\\ACL::CANADDRECORD')) %} {% set label %} {{ 'action : collection' | trans }} {% endset %} @@ -287,7 +287,7 @@ {% endif %} - {% if acl.has_right('doctools') %} + {% if acl.has_right(constant('\\ACL::IMGTOOLS')) %}
    {% endif %} - {% if acl.has_right('deleterecord') %} + {% if acl.has_right(constant('\\ACL::CANDELETERECORD')) %}
    -{% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_sbas(databox.get_sbas_id(), "bas_manage") %} +{% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_sbas(databox.get_sbas_id(), constant('\\ACL::BAS_MANAGE')) %}
    - {% if rights['restrict_dwnld'] > 0 %} + {% if rights[constant('\\ACL::RESTRICT_DWNLD')] > 0 %} {% else %} @@ -419,10 +418,10 @@ {{_self.format_checkbox(app.getAuthenticatedUser(), rights, constant('\\ACL::CANPUSH'), users, 'base')}} - {{_self.format_checkbox(app.getAuthenticatedUser(), rights, constant('\\ACL::MANAGE'), users, 'base')}} + {{_self.format_checkbox(app.getAuthenticatedUser(), rights, constant('\\ACL::COLL_MANAGE'), users, 'base')}} - {{_self.format_checkbox(app.getAuthenticatedUser(), rights, constant('\\ACL::MODIFY_STRUCT'), users, 'base')}} + {{_self.format_checkbox(app.getAuthenticatedUser(), rights, constant('\\ACL::COLL_MODIFY_STRUCT'), users, 'base')}} diff --git a/templates/web/admin/editusers_quotas.html.twig b/templates/web/admin/editusers_quotas.html.twig index 537e7baaae..75fcea933a 100644 --- a/templates/web/admin/editusers_quotas.html.twig +++ b/templates/web/admin/editusers_quotas.html.twig @@ -5,8 +5,8 @@ {% for usr_id, data in datas %} {% if restrict == -1 %} - {% set restrict = data['restrict_dwnld'] %} - {% elseif restrict != data['restrict_dwnld'] %} + {% set restrict = data[constant('\\ACL::RESTRICT_DWNLD')] %} + {% elseif restrict != data[constant('\\ACL::RESTRICT_DWNLD')] %} {% set restrict = 2 %} {% endif %} diff --git a/templates/web/admin/publications/fiche.html.twig b/templates/web/admin/publications/fiche.html.twig index d53d912280..77a678400e 100644 --- a/templates/web/admin/publications/fiche.html.twig +++ b/templates/web/admin/publications/fiche.html.twig @@ -106,7 +106,7 @@
    - {% for databox in app.getAclForUser(app.getAuthenticatedUser()).get_granted_sbas('bas_chupub') %} + {% for databox in app.getAclForUser(app.getAuthenticatedUser()).get_granted_sbas(constant('\\ACL::BAS_CHUPUB')) %} {% for collection in databox.get_collections() %} diff --git a/templates/web/admin/tree.html.twig b/templates/web/admin/tree.html.twig index 6b86124894..ecad1411c4 100644 --- a/templates/web/admin/tree.html.twig +++ b/templates/web/admin/tree.html.twig @@ -51,7 +51,7 @@ {% endif %} - {% if app.getAclForUser(app.getAuthenticatedUser()).has_right('bas_chupub') %} + {% if app.getAclForUser(app.getAuthenticatedUser()).has_right(constant('\\ACL::BAS_CHUPUB')) %}
  • @@ -60,7 +60,7 @@
  • {% endif %} - {% if app.getAclForUser(app.getAuthenticatedUser()).has_right('taskmanager') %} + {% if app.getAclForUser(app.getAuthenticatedUser()).has_right(constant('\\ACL::TASKMANAGER')) %}
  • @@ -110,7 +110,7 @@
  • {% if app['conf'].get(['registry', 'actions', 'social-tools']) == 'all' or (app['conf'].get(['registry', 'actions', 'social-tools']) == 'publishers' - and granted_on_databox(record.databoxId, 'bas_chupub')) %} + and granted_on_databox(record.databoxId, constant('\\ACL::BAS_CHUPUB'))) %} {% if record.story is empty %}
    {% endif %} - {% if acl.has_right('push') and acl.has_right('bas_chupub') %} + {% if acl.has_right(constant('\\ACL::CANPUSH')) and acl.has_right(constant('\\ACL::BAS_CHUPUB')) %}
    - {% elseif acl.has_right('push') %} + {% elseif acl.has_right(constant('\\ACL::CANPUSH')) %}
    - {% elseif acl.has_right('bas_chupub') %} + {% elseif acl.has_right(constant('\\ACL::BAS_CHUPUB')) %}
    - {% set can_see_business = granted_on_collection(record.baseId, constant('\\ACL::CANMODIFRECORD')) %} + {% set can_see_business = granted_on_collection(record.baseId, [constant('\\ACL::CANMODIFRECORD')]) %}
    - {% if granted_on_collection(record.baseId, constant('\\ACL::CANPUTINALBUM')) and not record.story %} + {% if granted_on_collection(record.baseId, [constant('\\ACL::CANPUTINALBUM')]) and not record.story %}
    @@ -113,7 +113,7 @@
    {% endif %} - {% if granted_on_collection(record.baseId, constant('\\ACL::CANDWNLDPREVIEW')) or granted_on_collection(record.baseId, constant('\\ACL::CANDWNLDHD')) %} + {% if granted_on_collection(record.baseId, [constant('\\ACL::CANDWNLDPREVIEW')]) or granted_on_collection(record.baseId, [constant('\\ACL::CANDWNLDHD')]) %}
    diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php index a584ce7846..3b88401969 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php @@ -1,6 +1,8 @@ getAclForUser($user)->give_access_to_sbas(array_keys(self::$DI['app']->getDataboxes())); + /** @var Databox $databox */ foreach (self::$DI['app']->getDataboxes() as $databox) { - $rights = [ - \ACL::BAS_MANAGE => '1', - \ACL::BAS_MODIFY_STRUCT => '1', - \ACL::BAS_MODIF_TH => '1', - \ACL::BAS_CHUPUB => '1', - ]; - - self::$DI['app']->getAclForUser($user)->update_rights_to_sbas($databox->get_sbas_id(), $rights); + self::$DI['app']->getAclForUser($user) + ->update_rights_to_sbas( + $databox->get_sbas_id(), + [ + \ACL::BAS_MANAGE => true, + \ACL::BAS_MODIFY_STRUCT => true, + \ACL::BAS_MODIF_TH => true, + \ACL::BAS_CHUPUB => true, + ] + ); foreach ($databox->get_collections() as $collection) { $base_id = $collection->get_base_id(); self::$DI['app']->getAclForUser($user)->give_access_to_base([$base_id]); - $rights = [ - \ACL::CANPUTINALBUM => '1', - \ACL::CANDWNLDHD => '1', - 'candwnldsubdef' => '1', - \ACL::NOWATERMARK => '1' - ]; + self::$DI['app']->getAclForUser($user) + ->update_rights_to_base( + $collection->get_base_id(), + [ + \ACL::CANPUTINALBUM => true, + \ACL::CANDWNLDHD => true, + \ACL::NOWATERMARK => true + ] + ); - self::$DI['app']->getAclForUser($user)->update_rights_to_base($collection->get_base_id(), $rights); break; } } @@ -444,7 +451,13 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase // create a template if (null === self::$DI['app']['repo.users']->findByLogin('csv_template')) { $user = self::$DI['app']['manipulator.user']->createTemplate('csv_template', self::$DI['app']->getAuthenticatedUser()); - self::$DI['app']->getAclForUser($user)->update_rights_to_base(self::$DI['collection']->get_base_id(), ['actif'=> 1]); + self::$DI['app']->getAclForUser($user) + ->update_rights_to_base( + self::$DI['collection']->get_base_id(), + [ + \ACL::ACTIF => true + ] + ); } $nativeQueryMock = $this->getMockBuilder('Alchemy\Phrasea\Model\NativeQueryProvider') diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiJsonTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiJsonTest.php index ae5dfa3c8f..1d1023c064 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiJsonTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiJsonTest.php @@ -1009,13 +1009,14 @@ class ApiJsonTest extends ApiTestCase if ('none' !== $collection->get_pub_wm()) { $collection->set_public_presentation('none'); } - $app->getAclForUser(self::$DI['user_notAdmin'])->update_rights_to_base( - $collection->get_base_id(), - [ - \ACL::CANDWNLDPREVIEW => 1, - \ACL::CANDWNLDHD => 1 - ] - ); + $app->getAclForUser(self::$DI['user_notAdmin']) + ->update_rights_to_base( + $collection->get_base_id(), + [ + \ACL::CANDWNLDPREVIEW => true, + \ACL::CANDWNLDHD => true + ] + ); /** @var \record_adapter $record_1 */ $record_1 = self::$DI['record_1']; @@ -1053,10 +1054,14 @@ class ApiJsonTest extends ApiTestCase { $this->setToken($this->userAccessToken); - self::$DI['app']->getAclForUser(self::$DI['user_notAdmin'])->update_rights_to_base(self::$DI['collection']->get_base_id(), array( - \ACL::CANDWNLDPREVIEW => 1, - \ACL::CANDWNLDHD => 0 - )); + self::$DI['app']->getAclForUser(self::$DI['user_notAdmin']) + ->update_rights_to_base( + self::$DI['collection']->get_base_id(), + [ + \ACL::CANDWNLDPREVIEW => true, + \ACL::CANDWNLDHD => false + ] + ); $route = '/api/v1/records/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/embed/'; @@ -1077,13 +1082,14 @@ class ApiJsonTest extends ApiTestCase { $this->setToken($this->userAccessToken); - self::$DI['app']->getAclForUser(self::$DI['user_notAdmin'])->update_rights_to_base( - self::$DI['collection']->get_base_id(), - [ - \ACL::CANDWNLDPREVIEW => 0, - \ACL::CANDWNLDHD => 0 - ] - ); + self::$DI['app']->getAclForUser(self::$DI['user_notAdmin']) + ->update_rights_to_base( + self::$DI['collection']->get_base_id(), + [ + \ACL::CANDWNLDPREVIEW => false, + \ACL::CANDWNLDHD => false + ] + ); $route = '/api/v1/records/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/embed/'; diff --git a/tests/Alchemy/Tests/Phrasea/Controller/RecordsRequestTest.php b/tests/Alchemy/Tests/Phrasea/Controller/RecordsRequestTest.php index ef7fe5d345..96c5ede69b 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/RecordsRequestTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/RecordsRequestTest.php @@ -79,7 +79,12 @@ class RecordsRequestTest extends \PhraseanetAuthenticatedTestCase public function testSimpleWithoutSbasRights() { self::$DI['app']->getAclForUser(self::$DI['app']->getAuthenticatedUser()) - ->update_rights_to_sbas(self::$DI['record_2']->get_sbas_id(), [\ACL::BAS_CHUPUB => 0]); + ->update_rights_to_sbas( + self::$DI['record_2']->get_sbas_id(), + [ + \ACL::BAS_CHUPUB => false + ] + ); $request = new Request([ 'lst' => implode(';', [ @@ -107,7 +112,9 @@ class RecordsRequestTest extends \PhraseanetAuthenticatedTestCase self::$DI['app']->getAclForUser(self::$DI['app']->getAuthenticatedUser()) ->update_rights_to_base( self::$DI['record_2']->get_base_id(), - [\ACL::CHGSTATUS => 0] + [ + \ACL::CHGSTATUS => false + ] ); $request = new Request([ diff --git a/tests/Alchemy/Tests/Phrasea/Model/Manipulator/ACLManipulatorTest.php b/tests/Alchemy/Tests/Phrasea/Model/Manipulator/ACLManipulatorTest.php index 1409291e56..44e1f4752c 100644 --- a/tests/Alchemy/Tests/Phrasea/Model/Manipulator/ACLManipulatorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Model/Manipulator/ACLManipulatorTest.php @@ -2,6 +2,9 @@ namespace Alchemy\Tests\Phrasea\Model\Manipulator; +use \ACL; +use \Databox; + /** * @group functional * @group legacy @@ -11,46 +14,53 @@ class ACLManipulatorTest extends \PhraseanetTestCase public function testResetAdminRights() { $user = self::$DI['app']['manipulator.user']->createUser(uniqid('toto'), 'toto', null, true); + /** @var ACL $acl */ $acl = self::$DI['app']->getAclForUser($user); $databoxId = null; $baseId = null; + /** @var Databox $databox */ foreach (self::$DI['app']->getDataboxes() as $databox) { $databoxId = $databox->get_sbas_id(); - $acl->update_rights_to_sbas($databoxId, [ - \ACL::BAS_MANAGE => '0', - \ACL::BAS_MODIFY_STRUCT => '0', - \ACL::BAS_MODIF_TH => '0', - \ACL::BAS_CHUPUB => '0', - ]); + $acl->update_rights_to_sbas( + $databoxId, + [ + \ACL::BAS_MANAGE => false, + \ACL::BAS_MODIFY_STRUCT => false, + \ACL::BAS_MODIF_TH => false, + \ACL::BAS_CHUPUB => false + ] + ); foreach ($databox->get_collections() as $collection) { $baseId = $collection->get_base_id(); $acl->set_limits($baseId, true); $acl->set_masks_on_base($baseId, '1', '1', '1', '1'); - $acl->update_rights_to_base($baseId, [ - \ACL::CANPUTINALBUM => '0', - \ACL::CANDWNLDHD => '0', - 'candwnldsubdef' => '0', - \ACL::NOWATERMARK => '0', - \ACL::CANDWNLDPREVIEW => '0', - \ACL::CANCMD => '0', - \ACL::CANADMIN => '0', - \ACL::CANREPORT => '0', - \ACL::CANPUSH => '0', - 'creationdate' => '0', - \ACL::CANADDRECORD => '0', - \ACL::CANMODIFRECORD => '0', - \ACL::CANDELETERECORD => '0', - \ACL::CHGSTATUS => '0', - \ACL::IMGTOOLS => '0', - \ACL::COLL_MANAGE => '0', - \ACL::COLL_MODIFY_STRUCT => '0', - \ACL::BAS_MODIFY_STRUCT => '0' - ]); + $acl->update_rights_to_base( + $baseId, + [ + 'creationdate' => '0', // todo: wtf + \ACL::CANPUTINALBUM => false, + \ACL::CANDWNLDHD => false, + \ACL::NOWATERMARK => false, + \ACL::CANDWNLDPREVIEW => false, + \ACL::CANCMD => false, + \ACL::CANADMIN => false, + \ACL::CANREPORT => false, + \ACL::CANPUSH => false, + \ACL::CANADDRECORD => false, + \ACL::CANMODIFRECORD => false, + \ACL::CANDELETERECORD => false, + \ACL::CHGSTATUS => false, + \ACL::IMGTOOLS => false, + \ACL::COLL_MANAGE => false, + \ACL::COLL_MODIFY_STRUCT => false, + \ACL::BAS_MODIFY_STRUCT => false + ] + ); break 2; } diff --git a/tests/classes/ACLTest.php b/tests/classes/ACLTest.php index a6d70f3c87..89f40fe935 100644 --- a/tests/classes/ACLTest.php +++ b/tests/classes/ACLTest.php @@ -118,7 +118,7 @@ class ACLTest extends \PhraseanetTestCase public function testGive_access_to_sbas() { - + /** @var Databox $databox */ foreach (self::$DI['app']->getDataboxes() as $databox) { $sbas_id = $databox->get_sbas_id(); $base_ids = []; @@ -136,6 +136,7 @@ class ACLTest extends \PhraseanetTestCase public function testRevoke_unused_sbas_rights() { + /** @var Databox $databox */ foreach (self::$DI['app']->getDataboxes() as $databox) { $sbas_id = $databox->get_sbas_id(); $base_ids = []; @@ -158,6 +159,7 @@ class ACLTest extends \PhraseanetTestCase public function testSet_quotas_on_base() { + /** @var Databox $databox */ foreach (self::$DI['app']->getDataboxes() as $databox) { foreach ($databox->get_collections() as $collection) { $base_id = $collection->get_base_id(); @@ -178,10 +180,10 @@ class ACLTest extends \PhraseanetTestCase public function testDuplicate_right_from_bas() { - $first = true; $base_ref = null; + /** @var Databox $databox */ foreach (self::$DI['app']->getDataboxes() as $databox) { foreach ($databox->get_collections() as $collection) { $base_id = $collection->get_base_id(); @@ -189,12 +191,15 @@ class ACLTest extends \PhraseanetTestCase $this->object->give_access_to_base([$base_id]); if ($first) { - $this->object->update_rights_to_base($base_id, [ - \ACL::IMGTOOLS => true, - \ACL::CHGSTATUS => true, - \ACL::CANADDRECORD => true, - \ACL::CANPUTINALBUM => true - ]); + $this->object->update_rights_to_base( + $base_id, + [ + \ACL::IMGTOOLS => true, + \ACL::CHGSTATUS => true, + \ACL::CANADDRECORD => true, + \ACL::CANPUTINALBUM => true + ] + ); $base_ref = $base_id; } else { $this->object->duplicate_right_from_bas($base_ref, $base_id); @@ -233,21 +238,34 @@ class ACLTest extends \PhraseanetTestCase \ACL::CANADDRECORD => true, ]; + /** @var Databox $databox */ foreach (self::$DI['app']->getDataboxes() as $databox) { foreach ($databox->get_collections() as $collection) { $base_id = $collection->get_base_id(); $this->object->give_access_to_base([$base_id]); - $this->object->update_rights_to_base($base_id, $rights_false); + + $this->object->update_rights_to_base( + $base_id, + $rights_false + ); $this->assertFalse($this->object->has_right_on_base($base_id, \ACL::IMGTOOLS)); $this->assertFalse($this->object->has_right_on_base($base_id, \ACL::CHGSTATUS)); $this->assertFalse($this->object->has_right_on_base($base_id, \ACL::CANADDRECORD)); $this->assertFalse($this->object->has_right_on_base($base_id, \ACL::CANPUTINALBUM)); - $this->object->update_rights_to_base($base_id, $rights_true); + + $this->object->update_rights_to_base( + $base_id, + $rights_true + ); $this->assertTrue($this->object->has_right_on_base($base_id, \ACL::IMGTOOLS)); $this->assertTrue($this->object->has_right_on_base($base_id, \ACL::CHGSTATUS)); $this->assertTrue($this->object->has_right_on_base($base_id, \ACL::CANADDRECORD)); $this->assertFalse($this->object->has_right_on_base($base_id, \ACL::CANPUTINALBUM)); - $this->object->update_rights_to_base($base_id, $rights_false); + + $this->object->update_rights_to_base( + $base_id, + $rights_false + ); $this->assertFalse($this->object->has_right_on_base($base_id, \ACL::IMGTOOLS)); $this->assertFalse($this->object->has_right_on_base($base_id, \ACL::CHGSTATUS)); $this->assertFalse($this->object->has_right_on_base($base_id, \ACL::CANADDRECORD)); @@ -262,6 +280,7 @@ class ACLTest extends \PhraseanetTestCase */ public function testGetSetOrder_master() { + /** @var Appbox $appbox */ $appbox = self::$DI['app']['phraseanet.appbox']; $acl = $this->object; @@ -338,19 +357,26 @@ class ACLTest extends \PhraseanetTestCase public function testHasRight() { + /** @var Databox $databox */ $databox = self::$DI['collection']->get_databox(); $this->object->give_access_to_sbas([$databox->get_sbas_id()]); - $this->object->update_rights_to_sbas($databox->get_sbas_id(), [ - \ACL::BAS_MODIFY_STRUCT => false, - \ACL::BAS_MODIF_TH => false, - ]); + $this->object->update_rights_to_sbas( + $databox->get_sbas_id(), + [ + \ACL::BAS_MODIFY_STRUCT => false, + \ACL::BAS_MODIF_TH => false + ] + ); $this->assertFalse($this->object->has_right(\ACL::BAS_MODIFY_STRUCT )); $this->assertFalse($this->object->has_right(\ACL::BAS_MODIF_TH)); - $this->object->update_rights_to_sbas($databox->get_sbas_id(), [ - \ACL::BAS_MODIFY_STRUCT => true, - ]); + $this->object->update_rights_to_sbas( + $databox->get_sbas_id(), + [ + \ACL::BAS_MODIFY_STRUCT => true + ] + ); $this->assertTrue($this->object->has_right(\ACL::BAS_MODIFY_STRUCT )); $this->assertFalse($this->object->has_right(\ACL::BAS_MODIF_TH)); @@ -362,29 +388,42 @@ class ACLTest extends \PhraseanetTestCase \ACL::BAS_MODIFY_STRUCT => false, \ACL::BAS_MANAGE => false, \ACL::BAS_CHUPUB => false, - \ACL::BAS_MODIF_TH => false, + \ACL::BAS_MODIF_TH => false ]; $rights_true = [ \ACL::BAS_MODIFY_STRUCT => true, \ACL::BAS_MANAGE => true, \ACL::BAS_CHUPUB => true, - \ACL::BAS_MODIF_TH => true, + \ACL::BAS_MODIF_TH => true ]; + /** @var Databox $databox */ foreach (self::$DI['app']->getDataboxes() as $databox) { $this->object->give_access_to_sbas([$databox->get_sbas_id()]); - $this->object->update_rights_to_sbas($databox->get_sbas_id(), $rights_false); + + $this->object->update_rights_to_sbas( + $databox->get_sbas_id(), + $rights_false + ); $this->assertFalse($this->object->has_right_on_sbas($databox->get_sbas_id(), \ACL::BAS_MODIFY_STRUCT)); $this->assertFalse($this->object->has_right_on_sbas($databox->get_sbas_id(), \ACL::BAS_MANAGE)); $this->assertFalse($this->object->has_right_on_sbas($databox->get_sbas_id(), \ACL::BAS_CHUPUB)); $this->assertFalse($this->object->has_right_on_sbas($databox->get_sbas_id(), \ACL::BAS_MODIF_TH)); - $this->object->update_rights_to_sbas($databox->get_sbas_id(), $rights_true); + + $this->object->update_rights_to_sbas( + $databox->get_sbas_id(), + $rights_true + ); $this->assertTrue($this->object->has_right_on_sbas($databox->get_sbas_id(), \ACL::BAS_MODIFY_STRUCT)); $this->assertTrue($this->object->has_right_on_sbas($databox->get_sbas_id(), \ACL::BAS_MANAGE)); $this->assertTrue($this->object->has_right_on_sbas($databox->get_sbas_id(), \ACL::BAS_CHUPUB)); $this->assertTrue($this->object->has_right_on_sbas($databox->get_sbas_id(), \ACL::BAS_MODIF_TH)); - $this->object->update_rights_to_sbas($databox->get_sbas_id(), $rights_false); + + $this->object->update_rights_to_sbas( + $databox->get_sbas_id(), + $rights_false + ); $this->assertFalse($this->object->has_right_on_sbas($databox->get_sbas_id(), \ACL::BAS_MODIFY_STRUCT)); $this->assertFalse($this->object->has_right_on_sbas($databox->get_sbas_id(), \ACL::BAS_MANAGE)); $this->assertFalse($this->object->has_right_on_sbas($databox->get_sbas_id(), \ACL::BAS_CHUPUB)); @@ -394,18 +433,39 @@ class ACLTest extends \PhraseanetTestCase public function testGet_mask_and() { + /** @var Databox $databox */ foreach (self::$DI['app']->getDataboxes() as $databox) { foreach ($databox->get_collections() as $collection) { $base_id = $collection->get_base_id(); $this->object->give_access_to_base([$base_id]); - $this->object->update_rights_to_base($base_id, ['actif' => false]); + $this->object->update_rights_to_base( + $base_id, + [ + \ACL::ACTIF => false + ] + ); $this->assertFalse($this->object->get_mask_and($base_id)); - $this->object->update_rights_to_base($base_id, ['mask_and' => 42]); + $this->object->update_rights_to_base( + $base_id, + [ + 'mask_and' => 42 + ] + ); $this->assertEquals('42', $this->object->get_mask_and($base_id)); - $this->object->update_rights_to_base($base_id, ['mask_and' => 1]); + $this->object->update_rights_to_base( + $base_id, + [ + 'mask_and' => 1 + ] + ); $this->assertEquals('1', $this->object->get_mask_and($base_id)); - $this->object->update_rights_to_base($base_id, ['mask_and' => 0]); + $this->object->update_rights_to_base( + $base_id, + [ + 'mask_and' => 0 + ] + ); $this->assertEquals('0', $this->object->get_mask_and($base_id)); } } @@ -413,19 +473,45 @@ class ACLTest extends \PhraseanetTestCase public function testGet_mask_xor() { + /** @var Databox $databox */ foreach (self::$DI['app']->getDataboxes() as $databox) { foreach ($databox->get_collections() as $collection) { $base_id = $collection->get_base_id(); $this->object->give_access_to_base([$base_id]); - $this->object->update_rights_to_base($base_id, ['actif' => false]); + $this->object->update_rights_to_base( + $base_id, + [ + \ACL::ACTIF => false + ] + ); $this->assertFalse($this->object->get_mask_xor($base_id)); - $this->object->update_rights_to_base($base_id, ['actif' => true]); - $this->object->update_rights_to_base($base_id, ['mask_xor' => 42]); + $this->object->update_rights_to_base( + $base_id, + [ + \ACL::ACTIF => true + ] + ); + $this->object->update_rights_to_base( + $base_id, + [ + 'mask_xor' => 42 + ] + ); $this->assertEquals('42', $this->object->get_mask_xor($base_id)); - $this->object->update_rights_to_base($base_id, ['mask_xor' => 1]); + $this->object->update_rights_to_base( + $base_id, + [ + 'mask_xor' => 0 + ] + ); $this->assertEquals('1', $this->object->get_mask_xor($base_id)); - $this->object->update_rights_to_base($base_id, ['mask_xor' => 0]); + $this->object->update_rights_to_base( + $base_id, + [ + 'mask_xor' => 0 + ] + ); $this->assertEquals('0', $this->object->get_mask_xor($base_id)); } } @@ -435,6 +521,8 @@ class ACLTest extends \PhraseanetTestCase { $base_ids = []; $n = 0; + + /** @var Databox $databox */ foreach (self::$DI['app']->getDataboxes() as $databox) { foreach ($databox->get_collections() as $collection) { $base_ids[] = $collection->get_base_id(); @@ -460,21 +548,36 @@ class ACLTest extends \PhraseanetTestCase $this->assertEquals(1, $row['actif']); $this->assertTrue($this->object->has_access_to_base($base_id)); - $this->object->update_rights_to_base($base_id, ['actif' => false]); + $this->object->update_rights_to_base( + $base_id, + [ + \ACL::ACTIF => false + ] + ); $stmt->execute([':usr_id' => self::$DI['user']->getId(), ':base_id' => $base_id]); $row = $stmt->fetch(PDO::FETCH_ASSOC); $this->assertEquals(0, $row['actif']); $this->assertFalse($this->object->has_access_to_base($base_id)); - $this->object->update_rights_to_base($base_id, ['actif' => true]); + $this->object->update_rights_to_base( + $base_id, + [ + \ACL::ACTIF => true + ] + ); $stmt->execute([':usr_id' => self::$DI['user']->getId(), ':base_id' => $base_id]); $row = $stmt->fetch(PDO::FETCH_ASSOC); $this->assertEquals(1, $row['actif']); $this->assertTrue($this->object->has_access_to_base($base_id)); - $this->object->update_rights_to_base($base_id, ['actif' => false]); + $this->object->update_rights_to_base( + $base_id, + [ + \ACL::ACTIF => false + ] + ); $this->assertFalse($this->object->has_access_to_base($base_id)); } $this->object->give_access_to_base($base_ids); @@ -489,6 +592,8 @@ class ACLTest extends \PhraseanetTestCase { $base_ids = []; $n = 0; + + /** @var Databox $databox */ foreach (self::$DI['app']->getDataboxes() as $databox) { foreach ($databox->get_collections() as $collection) { $base_ids[] = $collection->get_base_id(); @@ -521,6 +626,8 @@ class ACLTest extends \PhraseanetTestCase { $sbas_ids = []; $n = 0; + + /** @var Databox $databox */ foreach (self::$DI['app']->getDataboxes() as $databox) { $sbas_ids[] = $databox->get_sbas_id(); $n ++; @@ -568,7 +675,12 @@ class ACLTest extends \PhraseanetTestCase foreach ($databox->get_collections() as $collection) { $base_id = $collection->get_base_id(); $base_ids[] = $base_id; - $this->object->update_rights_to_base($base_id, [\ACL::CANREPORT => true]); + $this->object->update_rights_to_base( + $base_id, + [ + \ACL::CANREPORT => true + ] + ); $found = true; break; } @@ -579,8 +691,14 @@ class ACLTest extends \PhraseanetTestCase $this->assertFalse($this->object->has_access_to_module('thesaurus')); $this->assertFalse($this->object->has_access_to_module('upload')); + /** @var Databox $databox */ foreach (self::$DI['app']->getDataboxes() as $databox) { - $this->object->update_rights_to_sbas($databox->get_sbas_id(), [\ACL::BAS_MODIF_TH => true]); + $this->object->update_rights_to_sbas( + $databox->get_sbas_id(), + [ + \ACL::BAS_MODIF_TH => true + ] + ); $found = true; } $this->assertTrue($this->object->has_access_to_module('report')); @@ -592,7 +710,12 @@ class ACLTest extends \PhraseanetTestCase foreach ($databox->get_collections() as $collection) { $base_id = $collection->get_base_id(); $base_ids[] = $base_id; - $this->object->update_rights_to_base($base_id, [\ACL::CANADDRECORD => true]); + $this->object->update_rights_to_base( + $base_id, + [ + \ACL::CANADDRECORD => true + ] + ); $found = true; break; } @@ -606,9 +729,9 @@ class ACLTest extends \PhraseanetTestCase public function testis_limited() { - $found = false; + /** @var Databox $databox */ foreach (self::$DI['app']->getDataboxes() as $databox) { foreach ($databox->get_collections() as $collection) { $base_id = $collection->get_base_id(); @@ -639,9 +762,9 @@ class ACLTest extends \PhraseanetTestCase public function testget_limits() { - $found = false; + /** @var Databox $databox */ foreach (self::$DI['app']->getDataboxes() as $databox) { foreach ($databox->get_collections() as $collection) { $base_id = $collection->get_base_id(); diff --git a/tests/classes/PhraseanetAuthenticatedWebTestCase.php b/tests/classes/PhraseanetAuthenticatedWebTestCase.php index 52d8a2e682..5d28a1d3db 100644 --- a/tests/classes/PhraseanetAuthenticatedWebTestCase.php +++ b/tests/classes/PhraseanetAuthenticatedWebTestCase.php @@ -108,14 +108,15 @@ abstract class PhraseanetAuthenticatedWebTestCase extends \PhraseanetAuthenticat self::$createdDataboxes[] = $databox; - $rights = [ - \ACL::BAS_MANAGE => '1', - \ACL::BAS_MODIFY_STRUCT => '1', - \ACL::BAS_MODIF_TH => '1', - \ACL::BAS_CHUPUB => '1' - ]; - - $app->getAclForUser($app->getAuthenticatedUser())->update_rights_to_sbas($databox->get_sbas_id(), $rights); + $app->getAclForUser($app->getAuthenticatedUser())->update_rights_to_sbas( + $databox->get_sbas_id(), + [ + \ACL::BAS_MANAGE => true, + \ACL::BAS_MODIFY_STRUCT => true, + \ACL::BAS_MODIF_TH => true, + \ACL::BAS_CHUPUB => true + ] + ); $databox->registerAdmin($app->getAuthenticatedUser()); diff --git a/tests/classes/PhraseanetTestCase.php b/tests/classes/PhraseanetTestCase.php index 96e22620d5..ed9e05d8ba 100644 --- a/tests/classes/PhraseanetTestCase.php +++ b/tests/classes/PhraseanetTestCase.php @@ -571,14 +571,15 @@ abstract class PhraseanetTestCase extends WebTestCase foreach ($app->getDataboxes() as $databox) { $app->getAclForUser($user)->delete_data_from_cache(\ACL::CACHE_RIGHTS_SBAS); - $rights = [ - \ACL::BAS_MANAGE => '1', - \ACL::BAS_MODIFY_STRUCT => '1', - \ACL::BAS_MODIF_TH => '1', - \ACL::BAS_CHUPUB => '1' - ]; - - $app->getAclForUser($user)->update_rights_to_sbas($databox->get_sbas_id(), $rights); + $app->getAclForUser($user)->update_rights_to_sbas( + $databox->get_sbas_id(), + [ + \ACL::BAS_MANAGE => true, + \ACL::BAS_MODIFY_STRUCT => true, + \ACL::BAS_MODIF_TH => true, + \ACL::BAS_CHUPUB => true + ] + ); foreach ($databox->get_collections() as $collection) { if (null !== $base_ids && !in_array($collection->get_base_id(), (array) $base_ids, true)) { @@ -594,30 +595,35 @@ abstract class PhraseanetTestCase extends WebTestCase $app->getAclForUser($user)->delete_data_from_cache(\ACL::CACHE_RIGHTS_BAS); $app->getAclForUser($user)->give_access_to_base([$base_id]); - $app->getAclForUser($user)->update_rights_to_base($base_id, [\ACL::ORDER_MASTER => true]); + $app->getAclForUser($user)->update_rights_to_base( + $base_id, + [ + \ACL::ORDER_MASTER => true + ] + ); - $rights = [ - \ACL::CANPUTINALBUM => '1', - \ACL::CANDWNLDHD => '1', - 'candwnldsubdef' => '1', - \ACL::NOWATERMARK => '1', - \ACL::CANDWNLDPREVIEW => '1', - \ACL::CANCMD => '1', - \ACL::CANADMIN => '1', - \ACL::CANREPORT => '1', - \ACL::CANPUSH => '1', - 'creationdate' => '1', - \ACL::CANADDRECORD => '1', - \ACL::CANMODIFRECORD => '1', - \ACL::CANDELETERECORD => '1', - \ACL::CHGSTATUS => '1', - \ACL::IMGTOOLS => '1', - \ACL::COLL_MANAGE => '1', - \ACL::COLL_MODIFY_STRUCT => '1', - \ACL::BAS_MODIFY_STRUCT => '1' - ]; - - $app->getAclForUser($user)->update_rights_to_base($collection->get_base_id(), $rights); + $app->getAclForUser($user)->update_rights_to_base( + $collection->get_base_id(), + [ + 'creationdate' => '1', // todo : wtf + \ACL::CANPUTINALBUM => true, + \ACL::CANDWNLDHD => true, + \ACL::NOWATERMARK => true, + \ACL::CANDWNLDPREVIEW => true, + \ACL::CANCMD => true, + \ACL::CANADMIN => true, + \ACL::CANREPORT => true, + \ACL::CANPUSH => true, + \ACL::CANADDRECORD => true, + \ACL::CANMODIFRECORD => true, + \ACL::CANDELETERECORD => true, + \ACL::CHGSTATUS => true, + \ACL::IMGTOOLS => true, + \ACL::COLL_MANAGE => true, + \ACL::COLL_MODIFY_STRUCT => true, + \ACL::BAS_MODIFY_STRUCT => true + ] + ); } } } From 45eea297100073c331e4869b7de461c6957748bb Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Wed, 26 Oct 2016 19:14:11 +0200 Subject: [PATCH 08/42] PHRAS-508_acl-cache - fix unit tests --- lib/classes/ACL.php | 84 ++++++++++++------- templates/web/prod/WorkZone/Story.html.twig | 2 +- .../RegistrationManipulatorTest.php | 10 +-- tests/classes/ACLTest.php | 9 +- 4 files changed, 67 insertions(+), 38 deletions(-) diff --git a/lib/classes/ACL.php b/lib/classes/ACL.php index 6ea8c0f3da..e49fcabf74 100644 --- a/lib/classes/ACL.php +++ b/lib/classes/ACL.php @@ -1153,38 +1153,27 @@ class ACL implements cache_cacheableInterface { $this->load_rights_bas(); - $sql_i = "INSERT INTO basusr (base_id, usr_id, actif) VALUES (:base_id, :usr_id, '1')"; - $sql_u = "UPDATE basusr SET UPDATE actif='1' WHERE base_id = :base_id AND usr_id = :usr_id"; - $stmt_i = $this->app->getApplicationBox()->get_connection()->prepare($sql_i); - $stmt_u = $this->app->getApplicationBox()->get_connection()->prepare($sql_u); - $usr_id = $this->user->getId(); foreach ($base_ids as $base_id) { - if (!isset($this->_rights_bas[$base_id]) || $this->_rights_bas[$base_id][self::ACTIF] === false) { - try { - $stmt_i->execute([':base_id' => $base_id, ':usr_id' => $usr_id]); - if($stmt_i->rowCount() > 0) { - $this->app['dispatcher']->dispatch( - AclEvents::ACCESS_TO_BASE_GRANTED, - new AccessToBaseGrantedEvent( - $this, - array( - 'base_id'=>$base_id - ) - ) - ); - } - else { - $stmt_u->execute([':base_id' => $base_id, ':usr_id' => $usr_id]); - } - } - catch(\Exception $e) { - // no-opp - } + if (isset($this->_rights_bas[$base_id]) && $this->_rights_bas[$base_id][self::ACTIF] == true) { + continue; + } + + if($this->try_give_access_to_base_insert($base_id, $usr_id) == true) { + $this->app['dispatcher']->dispatch( + AclEvents::ACCESS_TO_BASE_GRANTED, + new AccessToBaseGrantedEvent( + $this, + array( + 'base_id'=>$base_id + ) + ) + ); + } + else { + $this->try_give_access_to_base_update($base_id, $usr_id); } } - $stmt_u->closeCursor(); - $stmt_i->closeCursor(); $this->delete_data_from_cache(self::CACHE_RIGHTS_BAS); $this->inject_rights(); @@ -1192,6 +1181,45 @@ class ACL implements cache_cacheableInterface return $this; } + private function try_give_access_to_base_insert($base_id, $usr_id) + { + static $stmt = null; + if(!$stmt) { + $sql = "INSERT INTO basusr (base_id, usr_id, actif) VALUES (:base_id, :usr_id, '1')"; + $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); + } + $inserted = false; + try { + $stmt->execute([':base_id' => $base_id, ':usr_id' => $usr_id]); + if ($stmt->rowCount() > 0) { + $inserted = true; + } + $stmt->closeCursor(); + } + catch(DBALException $e) { + // no-op, mostly the row did exist + } + + return $inserted; + } + + private function try_give_access_to_base_update($base_id, $usr_id) + { + static $stmt = null; + if(!$stmt) { + $sql = "UPDATE basusr SET UPDATE actif='1' WHERE base_id = :base_id AND usr_id = :usr_id"; + $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); + } + + try { + $stmt->execute([':base_id' => $base_id, ':usr_id' => $usr_id]); + $stmt->closeCursor(); + } + catch(DBALException $e) { + // no-op, mostly the row was deleted + } + } + /** * * @param array $sbas_ids diff --git a/templates/web/prod/WorkZone/Story.html.twig b/templates/web/prod/WorkZone/Story.html.twig index 803a8af778..56ab777d0d 100644 --- a/templates/web/prod/WorkZone/Story.html.twig +++ b/templates/web/prod/WorkZone/Story.html.twig @@ -40,7 +40,7 @@ {% endif %} - {% if app.getAclForUser(app.getAuthenticatedUser()).has_right(cnstant('\\ACL::BAS_CHUPUB')) %} + {% if app.getAclForUser(app.getAuthenticatedUser()).has_right(constant('\\ACL::BAS_CHUPUB')) %} diff --git a/tests/Alchemy/Tests/Phrasea/Model/Manipulator/RegistrationManipulatorTest.php b/tests/Alchemy/Tests/Phrasea/Model/Manipulator/RegistrationManipulatorTest.php index 7517ebf6c2..0ee1a18699 100644 --- a/tests/Alchemy/Tests/Phrasea/Model/Manipulator/RegistrationManipulatorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Model/Manipulator/RegistrationManipulatorTest.php @@ -40,11 +40,11 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase $aclMock->expects($this->once())->method('give_access_to_sbas')->with($this->equalTo([self::$DI['collection']->get_sbas_id()])); $aclMock->expects($this->once())->method('give_access_to_base')->with($this->equalTo([self::$DI['collection']->get_base_id()])); $aclMock->expects($this->once())->method('update_rights_to_base')->with($this->equalTo(self::$DI['collection']->get_base_id()), $this->equalTo([ - \ACL::CANPUTINALBUM => '1', - \ACL::CANDWNLDHD => '1', - \ACL::NOWATERMARK => '0', - \ACL::CANDWNLDPREVIEW => '1', - \ACL::ACTIF => '1', + \ACL::CANPUTINALBUM => true, + \ACL::CANDWNLDHD => true, + \ACL::NOWATERMARK => false, + \ACL::CANDWNLDPREVIEW => true, + \ACL::ACTIF => true, ])); $aclProviderMock = $this->getMockBuilder('Alchemy\Phrasea\Authentication\ACLProvider')->disableOriginalConstructor()->getMock(); diff --git a/tests/classes/ACLTest.php b/tests/classes/ACLTest.php index 89f40fe935..bcfae0d306 100644 --- a/tests/classes/ACLTest.php +++ b/tests/classes/ACLTest.php @@ -452,21 +452,21 @@ class ACLTest extends \PhraseanetTestCase 'mask_and' => 42 ] ); - $this->assertEquals('42', $this->object->get_mask_and($base_id)); + $this->assertEquals(42, $this->object->get_mask_and($base_id)); $this->object->update_rights_to_base( $base_id, [ 'mask_and' => 1 ] ); - $this->assertEquals('1', $this->object->get_mask_and($base_id)); + $this->assertEquals(1, $this->object->get_mask_and($base_id)); $this->object->update_rights_to_base( $base_id, [ 'mask_and' => 0 ] ); - $this->assertEquals('0', $this->object->get_mask_and($base_id)); + $this->assertEquals(0, $this->object->get_mask_and($base_id)); } } } @@ -531,8 +531,9 @@ class ACLTest extends \PhraseanetTestCase $this->object->give_access_to_sbas([$databox->get_sbas_id()]); } - if ($n === 0) + if ($n === 0) { $this->fail('Not enough collection to test'); + } $this->object->give_access_to_base($base_ids); $bases = array_keys($this->object->get_granted_base()); From cba54238221044877443c078fc13a53cdbc3e8b8 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 27 Oct 2016 13:04:47 +0200 Subject: [PATCH 09/42] Fix concept_path node in index structure --- .../Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php index 321b19f951..5b716e6872 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php @@ -111,6 +111,8 @@ class RecordIndex implements MappingProvider { $thesaurusMapping = new Mapping\ComplexFieldMapping($name, FieldMapping::TYPE_OBJECT); + $thesaurusMapping->useAsPropertyContainer(); + foreach (array_keys($this->structure->getThesaurusEnabledFields()) as $name) { $child = new Mapping\StringFieldMapping($name); From 165877e50ae2560aeba5d9ceee08f8dcc312fe8d Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 27 Oct 2016 13:14:05 +0200 Subject: [PATCH 10/42] Fix infinite recursion error --- .../Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php index 5b716e6872..8dc631539a 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php @@ -120,7 +120,7 @@ class RecordIndex implements MappingProvider $child->setAnalyzer('keyword', 'searching'); $child->addChild((new Mapping\StringFieldMapping('raw'))->enableRawIndexing()); - $thesaurusMapping->addChild($thesaurusMapping); + $thesaurusMapping->addChild($child); } return $thesaurusMapping; From fe7f3762dd88bcbc012d56b176e43f3086441832 Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Thu, 27 Oct 2016 15:07:31 +0200 Subject: [PATCH 11/42] PHRAS-508_acl-cache - fix for tests --- lib/classes/ACL.php | 84 +++++++++++---------------------------- tests/classes/ACLTest.php | 2 +- 2 files changed, 25 insertions(+), 61 deletions(-) diff --git a/lib/classes/ACL.php b/lib/classes/ACL.php index e49fcabf74..40ebc6621f 100644 --- a/lib/classes/ACL.php +++ b/lib/classes/ACL.php @@ -78,6 +78,14 @@ class ACL implements cache_cacheableInterface self::COLL_MODIFY_STRUCT, self::NOWATERMARK, self::ORDER_MASTER, + self::RESTRICT_DWNLD + ]; + + protected static $sbas_rights = [ + self::BAS_CHUPUB, + self::BAS_MANAGE, + self::BAS_MODIF_TH, + self::BAS_MODIFY_STRUCT ]; /** @@ -116,6 +124,7 @@ class ACL implements cache_cacheableInterface protected $is_admin; protected $_global_rights = [ + self::ACTIF => false, self::CANADDRECORD => false, self::CANPUTINALBUM => false, self::CANDWNLDHD => true, @@ -131,6 +140,8 @@ class ACL implements cache_cacheableInterface self::ORDER_MASTER => false, self::CANPUSH => false, self::CANREPORT => false, + self::NOWATERMARK => false, + self::RESTRICT_DWNLD => false, self::BAS_CHUPUB => false, self::BAS_MANAGE => false, @@ -346,13 +357,6 @@ class ACL implements cache_cacheableInterface $sbas_ids = array_unique($sbas_ids); - $sbas_rights = [ - self::BAS_MANAGE, - self::BAS_MODIFY_STRUCT, - self::BAS_MODIF_TH, - self::BAS_CHUPUB - ]; - $sbas_to_acces = []; $rights_to_give = []; @@ -366,7 +370,7 @@ class ACL implements cache_cacheableInterface $sbas_to_acces[] = $sbas_id; } - foreach ($sbas_rights as $right) { + foreach (self::$sbas_rights as $right) { if ($this->app->getAclForUser($template_user)->has_right_on_sbas($sbas_id, $right)) { $rights_to_give[$sbas_id][$right] = true; } @@ -926,18 +930,16 @@ class ACL implements cache_cacheableInterface $this->_rights_sbas = []; - $this->_global_rights[self::BAS_MODIF_TH] = false; - $this->_global_rights[self::BAS_MODIFY_STRUCT] = false; - $this->_global_rights[self::BAS_MANAGE] = false; - $this->_global_rights[self::BAS_CHUPUB] = false; + foreach(self::$sbas_rights as $b) { + $this->_global_rights[$b] = false; + } foreach ($rs as $row) { $sbid = $row['sbas_id']; $this->_rights_sbas[$sbid] = []; - $this->_global_rights[self::BAS_MODIF_TH] |= ($this->_rights_sbas[$sbid][self::BAS_MODIF_TH] = ($row[self::BAS_MODIF_TH] == '1')); - $this->_global_rights[self::BAS_MODIFY_STRUCT] |= ($this->_rights_sbas[$sbid][self::BAS_MODIFY_STRUCT] = ($row[self::BAS_MODIFY_STRUCT] == '1')); - $this->_global_rights[self::BAS_MANAGE] |= ($this->_rights_sbas[$sbid][self::BAS_MANAGE] = ($row[self::BAS_MANAGE] == '1')); - $this->_global_rights[self::BAS_CHUPUB] |= ($this->_rights_sbas[$sbid][self::BAS_CHUPUB] = ($row[self::BAS_CHUPUB] == '1')); + foreach (self::$sbas_rights as $b) { + $this->_global_rights[$b] = ($this->_rights_sbas[$sbid][$b] = ($row[$b] == '1')) || $this->_global_rights[$b]; + } } $this->set_data_to_cache($this->_rights_sbas, self::CACHE_RIGHTS_SBAS); $this->set_data_to_cache($this->_global_rights, self::CACHE_GLOBAL_RIGHTS); @@ -991,55 +993,17 @@ class ACL implements cache_cacheableInterface $this->_rights_bas = $this->_limited = []; - $this->_global_rights[self::CANADMIN] = false; - $this->_global_rights[self::COLL_MANAGE] = false; - $this->_global_rights[self::COLL_MODIFY_STRUCT] = false; - $this->_global_rights[self::CANCMD] = false; - $this->_global_rights[self::CANPUSH] = false; - $this->_global_rights[self::CANADDRECORD] = false; - $this->_global_rights[self::CANMODIFRECORD] = false; - $this->_global_rights[self::CHGSTATUS] = false; - $this->_global_rights[self::IMGTOOLS] = false; - $this->_global_rights[self::CANDELETERECORD] = false; - $this->_global_rights[self::CANPUTINALBUM] = false; - $this->_global_rights[self::CANREPORT] = false; - $this->_global_rights[self::CANDWNLDPREVIEW] = false; - $this->_global_rights[self::CANDWNLDHD] = false; - $this->_global_rights[self::ORDER_MASTER] = false; + foreach(self::$bas_rights as $b) { + $this->_global_rights[$b] = false; + } foreach ($rs as $row) { $bid = $row['base_id']; - $this->_rights_bas[$bid][self::ACTIF] = ($row[self::ACTIF] == '1'); - $row['limited_from'] = $row['limited_from'] == '0000-00-00 00:00:00' ? '' : trim($row['limited_from']); - $row['limited_to'] = $row['limited_to'] == '0000-00-00 00:00:00' ? '' : trim($row['limited_to']); - - if ($row['time_limited'] == '1' - && ($row['limited_from'] !== '' || $row['limited_to'] !== '')) { - $this->_limited[$row['base_id']] = [ - 'dmin' => $row['limited_from'] ? new DateTime($row['limited_from']) : null, - 'dmax' => $row['limited_to'] ? new DateTime($row['limited_to']) : null - ]; + foreach(self::$bas_rights as $b) { + $this->_global_rights[$b] = ($this->_rights_bas[$bid][$b] = ($row[$b] == '1')) || $this->_global_rights[$b]; } - $this->_global_rights[self::IMGTOOLS] |= ($this->_rights_bas[$bid][self::IMGTOOLS] = ($row[self::IMGTOOLS] == '1')); - $this->_global_rights[self::CHGSTATUS] |= ($this->_rights_bas[$bid][self::CHGSTATUS] = ($row[self::CHGSTATUS] == '1')); - $this->_global_rights[self::CANCMD] |= ($this->_rights_bas[$bid][self::CANCMD] = ($row[self::CANCMD] == '1')); - $this->_global_rights[self::CANADDRECORD] |= ($this->_rights_bas[$bid][self::CANADDRECORD] = ($row[self::CANADDRECORD] == '1')); - $this->_global_rights[self::CANPUSH] |= ($this->_rights_bas[$bid][self::CANPUSH] = ($row[self::CANPUSH] == '1')); - $this->_global_rights[self::CANDELETERECORD] |= ($this->_rights_bas[$bid][self::CANDELETERECORD] = ($row[self::CANDELETERECORD] == '1')); - $this->_global_rights[self::CANADMIN] |= ($this->_rights_bas[$bid][self::CANADMIN] = ($row[self::CANADMIN] == '1')); - $this->_global_rights[self::CANDWNLDPREVIEW] |= ($this->_rights_bas[$bid][self::CANDWNLDPREVIEW] = ($row[self::CANDWNLDPREVIEW] == '1')); - $this->_global_rights[self::CANDWNLDHD] |= ($this->_rights_bas[$bid][self::CANDWNLDHD] = ($row[self::CANDWNLDHD] == '1')); - $this->_global_rights[self::CANMODIFRECORD] |= ($this->_rights_bas[$bid][self::CANMODIFRECORD] = ($row[self::CANMODIFRECORD] == '1')); - $this->_global_rights[self::CANPUTINALBUM] |= ($this->_rights_bas[$bid][self::CANPUTINALBUM] = ($row[self::CANPUTINALBUM] == '1')); - $this->_global_rights[self::CANREPORT] |= ($this->_rights_bas[$bid][self::CANREPORT] = ($row[self::CANREPORT] == '1')); - $this->_global_rights[self::COLL_MODIFY_STRUCT] |= ($this->_rights_bas[$bid][self::COLL_MODIFY_STRUCT] = ($row[self::COLL_MODIFY_STRUCT] == '1')); - $this->_global_rights[self::COLL_MANAGE] |= ($this->_rights_bas[$bid][self::COLL_MANAGE] = ($row[self::COLL_MANAGE] == '1')); - $this->_global_rights[self::ORDER_MASTER] |= ($this->_rights_bas[$bid][self::ORDER_MASTER] = ($row[self::ORDER_MASTER] == '1')); - - $this->_rights_bas[$bid][self::NOWATERMARK] = ($row['nowatermark'] == '1'); - $this->_rights_bas[$bid][self::RESTRICT_DWNLD] = ($row['restrict_dwnld'] == '1'); $this->_rights_bas[$bid]['remain_dwnld'] = (int) $row['remain_dwnld']; $this->_rights_bas[$bid]['mask_and'] = (int) $row['mask_and']; $this->_rights_bas[$bid]['mask_xor'] = (int) $row['mask_xor']; @@ -1207,7 +1171,7 @@ class ACL implements cache_cacheableInterface { static $stmt = null; if(!$stmt) { - $sql = "UPDATE basusr SET UPDATE actif='1' WHERE base_id = :base_id AND usr_id = :usr_id"; + $sql = "UPDATE basusr SET actif='1' WHERE base_id = :base_id AND usr_id = :usr_id"; $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); } diff --git a/tests/classes/ACLTest.php b/tests/classes/ACLTest.php index bcfae0d306..816a9bc171 100644 --- a/tests/classes/ACLTest.php +++ b/tests/classes/ACLTest.php @@ -502,7 +502,7 @@ class ACLTest extends \PhraseanetTestCase $this->object->update_rights_to_base( $base_id, [ - 'mask_xor' => 0 + 'mask_xor' => 1 ] ); $this->assertEquals('1', $this->object->get_mask_xor($base_id)); From ce59523405339f5cc7a23c391dce787faf346b94 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 27 Oct 2016 15:13:57 +0200 Subject: [PATCH 12/42] Add specialized complex mapping for property maps --- .../Elastic/Indexer/RecordIndex.php | 18 ++++--------- .../Elastic/Mapping/ComplexFieldMapping.php | 14 ++++++++++- .../Mapping/ComplexPropertiesMapping.php | 25 +++++++++++++++++++ 3 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexPropertiesMapping.php diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php index 8dc631539a..7e9b7e8942 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php @@ -47,7 +47,7 @@ class RecordIndex implements MappingProvider $mapping = new MappingBuilder(); // Compound primary key - $mapping->addField('record_id', FieldMapping::TYPE_INTEGER); + $mapping->addIntegerField('record_id', FieldMapping::TYPE_INTEGER); $mapping->addField('databox_id', FieldMapping::TYPE_INTEGER); // Database name (still indexed for facets) @@ -87,9 +87,7 @@ class RecordIndex implements MappingProvider private function buildCaptionMapping(MappingBuilder $parent, $name, array $fields) { $fieldConverter = new Mapping\FieldToFieldMappingConverter(); - $captionMapping = new Mapping\ComplexFieldMapping($name, FieldMapping::TYPE_OBJECT); - - $captionMapping->useAsPropertyContainer(); + $captionMapping = new Mapping\ComplexPropertiesMapping($name); foreach ($fields as $field) { $captionMapping->addChild($fieldConverter->convertField($field, $this->locales)); @@ -109,9 +107,7 @@ class RecordIndex implements MappingProvider private function buildThesaurusPathMapping($name) { - $thesaurusMapping = new Mapping\ComplexFieldMapping($name, FieldMapping::TYPE_OBJECT); - - $thesaurusMapping->useAsPropertyContainer(); + $thesaurusMapping = new Mapping\ComplexPropertiesMapping($name); foreach (array_keys($this->structure->getThesaurusEnabledFields()) as $name) { $child = new Mapping\StringFieldMapping($name); @@ -129,9 +125,7 @@ class RecordIndex implements MappingProvider private function buildMetadataTagMapping($name) { $tagConverter = new Mapping\MetadataTagToFieldMappingConverter(); - $metadataMapping = new Mapping\ComplexFieldMapping($name, FieldMapping::TYPE_OBJECT); - - $metadataMapping->useAsPropertyContainer(); + $metadataMapping = new Mapping\ComplexPropertiesMapping($name); foreach ($this->structure->getMetadataTags() as $tag) { $metadataMapping->addChild($tagConverter->convertTag($tag)); @@ -143,9 +137,7 @@ class RecordIndex implements MappingProvider private function buildFlagMapping($name) { $index = 0; - $flagMapping = new Mapping\ComplexFieldMapping($name, FieldMapping::TYPE_OBJECT); - - $flagMapping->useAsPropertyContainer(); + $flagMapping = new Mapping\ComplexPropertiesMapping($name); foreach ($this->structure->getAllFlags() as $childName => $_) { if (trim($childName) == '') { diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexFieldMapping.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexFieldMapping.php index 1159144650..1b09fb0197 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexFieldMapping.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexFieldMapping.php @@ -20,6 +20,9 @@ class ComplexFieldMapping extends FieldMapping */ private $children = []; + /** + * @var null|string + */ private $childKey = 'fields'; public function useAsPropertyContainer() @@ -32,6 +35,11 @@ class ComplexFieldMapping extends FieldMapping $this->childKey = 'fields'; } + public function useAsBareContainer() + { + $this->childKey = null; + } + /** * @param FieldMapping $child * @return FieldMapping @@ -88,6 +96,10 @@ class ComplexFieldMapping extends FieldMapping $properties[$name] = $child->toArray(); } - return [ $this->childKey => $properties ]; + if ($this->childKey) { + return [$this->childKey => $properties]; + } + + return $properties; } } diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexPropertiesMapping.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexPropertiesMapping.php new file mode 100644 index 0000000000..9c559d850d --- /dev/null +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexPropertiesMapping.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Alchemy\Phrasea\SearchEngine\Elastic\Mapping; + +use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping; + +class ComplexPropertiesMapping extends ComplexFieldMapping +{ + + public function __construct($name) + { + parent::__construct($name, FieldMapping::TYPE_OBJECT); + + $this->useAsPropertyContainer(); + } +} From e1fc53dc649cb47306e904ef6162b315f837d86f Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 27 Oct 2016 15:17:33 +0200 Subject: [PATCH 13/42] Clean up mapping build process --- .../Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php index 7e9b7e8942..e577eb6498 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php @@ -47,8 +47,8 @@ class RecordIndex implements MappingProvider $mapping = new MappingBuilder(); // Compound primary key - $mapping->addIntegerField('record_id', FieldMapping::TYPE_INTEGER); - $mapping->addField('databox_id', FieldMapping::TYPE_INTEGER); + $mapping->addIntegerField('record_id'); + $mapping->addIntegerField('databox_id'); // Database name (still indexed for facets) $mapping->addStringField('databox_name')->disableAnalysis(); From 59befbfecc8460b47e7113b446c8224942232ca5 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 27 Oct 2016 15:22:39 +0200 Subject: [PATCH 14/42] Clean up complex field hierarchy to improve readability --- .../Elastic/Mapping/ComplexFieldMapping.php | 82 +----------------- .../Elastic/Mapping/ComplexMapping.php | 85 +++++++++++++++++++ .../Mapping/ComplexPropertiesMapping.php | 10 ++- 3 files changed, 97 insertions(+), 80 deletions(-) create mode 100644 lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexMapping.php diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexFieldMapping.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexFieldMapping.php index 1b09fb0197..288b82fe7b 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexFieldMapping.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexFieldMapping.php @@ -13,72 +13,12 @@ namespace Alchemy\Phrasea\SearchEngine\Elastic\Mapping; use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping; -class ComplexFieldMapping extends FieldMapping +class ComplexFieldMapping extends ComplexMapping { - /** - * @var FieldMapping[] - */ - private $children = []; - /** - * @var null|string - */ - private $childKey = 'fields'; - - public function useAsPropertyContainer() + public function __construct($name, $type = null) { - $this->childKey = 'properties'; - } - - public function useAsFieldContainer() - { - $this->childKey = 'fields'; - } - - public function useAsBareContainer() - { - $this->childKey = null; - } - - /** - * @param FieldMapping $child - * @return FieldMapping - */ - public function addChild(FieldMapping $child) - { - if (isset($this->children[$child->getName()])) { - throw new \LogicException(sprintf('There is already a "%s" multi field.', $child->getName())); - } - - if ($child->getType() !== $this->getType() && $this->getType() !== self::TYPE_OBJECT) { - throw new \LogicException('Child field type must match parent type.'); - } - - return $this->children[$child->getName()] = $child; - } - - /** - * @return RawFieldMapping - */ - public function addRawChild() - { - return $this->addChild(new RawFieldMapping($this->getType())); - } - - /** - * @return bool - */ - public function hasChildren() - { - return ! empty($this->children); - } - - /** - * @return FieldMapping[] - */ - public function getChildren() - { - return $this->children; + parent::__construct($name, $type ?: FieldMapping::TYPE_OBJECT); } /** @@ -86,20 +26,6 @@ class ComplexFieldMapping extends FieldMapping */ protected function getProperties() { - if (! $this->hasChildren()) { - return []; - } - - $properties = [ ]; - - foreach ($this->children as $name => $child) { - $properties[$name] = $child->toArray(); - } - - if ($this->childKey) { - return [$this->childKey => $properties]; - } - - return $properties; + return [ 'fields' => parent::getProperties() ]; } } diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexMapping.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexMapping.php new file mode 100644 index 0000000000..58f50faecd --- /dev/null +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexMapping.php @@ -0,0 +1,85 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Alchemy\Phrasea\SearchEngine\Elastic\Mapping; + +use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping; + +class ComplexMapping extends FieldMapping +{ + /** + * @var FieldMapping[] + */ + private $children = []; + + /** + * @param FieldMapping $child + * @return FieldMapping + */ + public function addChild(FieldMapping $child) + { + if (isset($this->children[$child->getName()])) { + throw new \LogicException(sprintf('There is already a "%s" multi field.', $child->getName())); + } + + if ($child->getType() !== $this->getType() && $this->getType() !== self::TYPE_OBJECT) { + throw new \LogicException('Child field type must match parent type.'); + } + + return $this->children[$child->getName()] = $child; + } + + /** + * @return RawFieldMapping + */ + public function addRawChild() + { + return $this->addChild(new RawFieldMapping($this->getType())); + } + + /** + * @return bool + */ + public function hasChildren() + { + return ! empty($this->children); + } + + /** + * @return FieldMapping[] + */ + public function getChildren() + { + return $this->children; + } + + /** + * @return array + */ + protected function getProperties() + { + if (! $this->hasChildren()) { + return []; + } + + $properties = [ ]; + + foreach ($this->children as $name => $child) { + $properties[$name] = $child->toArray(); + } + + if ($this->childKey) { + return [$this->childKey => $properties]; + } + + return $properties; + } +} diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexPropertiesMapping.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexPropertiesMapping.php index 9c559d850d..c3e48be954 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexPropertiesMapping.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexPropertiesMapping.php @@ -13,13 +13,19 @@ namespace Alchemy\Phrasea\SearchEngine\Elastic\Mapping; use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping; -class ComplexPropertiesMapping extends ComplexFieldMapping +class ComplexPropertiesMapping extends ComplexMapping { public function __construct($name) { parent::__construct($name, FieldMapping::TYPE_OBJECT); + } - $this->useAsPropertyContainer(); + /** + * @return array + */ + public function toArray() + { + return [ 'properties' => parent::getProperties() ]; } } From a5aecacefe24c577a183f733e713852d3f8d6e1f Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Thu, 27 Oct 2016 15:38:23 +0200 Subject: [PATCH 15/42] PHRAS-508_acl-cache - tryout without cache --- lib/classes/ACL.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/classes/ACL.php b/lib/classes/ACL.php index 40ebc6621f..0af8a8c3bd 100644 --- a/lib/classes/ACL.php +++ b/lib/classes/ACL.php @@ -567,7 +567,7 @@ class ACL implements cache_cacheableInterface */ public function set_data_to_cache($value, $option = null, $duration = 0) { - return $this->app->getApplicationBox()->set_data_to_cache($value, $this->get_cache_key($option), $duration); + // return $this->app->getApplicationBox()->set_data_to_cache($value, $this->get_cache_key($option), $duration); } /** From 2ae21532bc0a24724c5d8fa91dfd2c98bc57e93f Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 27 Oct 2016 15:42:26 +0200 Subject: [PATCH 16/42] Fix undefined property error --- .../Phrasea/SearchEngine/Elastic/Mapping/ComplexMapping.php | 4 ---- .../SearchEngine/Elastic/Mapping/ComplexPropertiesMapping.php | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexMapping.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexMapping.php index 58f50faecd..0e154f832f 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexMapping.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexMapping.php @@ -76,10 +76,6 @@ class ComplexMapping extends FieldMapping $properties[$name] = $child->toArray(); } - if ($this->childKey) { - return [$this->childKey => $properties]; - } - return $properties; } } diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexPropertiesMapping.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexPropertiesMapping.php index c3e48be954..af1487da15 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexPropertiesMapping.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexPropertiesMapping.php @@ -24,7 +24,7 @@ class ComplexPropertiesMapping extends ComplexMapping /** * @return array */ - public function toArray() + public function getProperties() { return [ 'properties' => parent::getProperties() ]; } From 343967b7c334c8d9f3e3823642e982168bf35571 Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Thu, 27 Oct 2016 17:51:04 +0200 Subject: [PATCH 17/42] PHRAS-508_acl-cache - wip --- lib/classes/ACL.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/classes/ACL.php b/lib/classes/ACL.php index 0af8a8c3bd..3036777dca 100644 --- a/lib/classes/ACL.php +++ b/lib/classes/ACL.php @@ -567,7 +567,7 @@ class ACL implements cache_cacheableInterface */ public function set_data_to_cache($value, $option = null, $duration = 0) { - // return $this->app->getApplicationBox()->set_data_to_cache($value, $this->get_cache_key($option), $duration); + return $this->app->getApplicationBox()->set_data_to_cache($value, $this->get_cache_key($option), $duration); } /** @@ -1147,7 +1147,7 @@ class ACL implements cache_cacheableInterface private function try_give_access_to_base_insert($base_id, $usr_id) { - static $stmt = null; + $stmt = null; if(!$stmt) { $sql = "INSERT INTO basusr (base_id, usr_id, actif) VALUES (:base_id, :usr_id, '1')"; $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); @@ -1169,7 +1169,7 @@ class ACL implements cache_cacheableInterface private function try_give_access_to_base_update($base_id, $usr_id) { - static $stmt = null; + $stmt = null; if(!$stmt) { $sql = "UPDATE basusr SET actif='1' WHERE base_id = :base_id AND usr_id = :usr_id"; $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); @@ -1231,7 +1231,6 @@ class ACL implements cache_cacheableInterface */ public function update_rights_to_base($base_id, $rights) { - if (!$this->has_access_to_base($base_id) && (!isset($rights[self::ACTIF]) || $rights[self::ACTIF] == true)) { $this->give_access_to_base([$base_id]); } From ce0aeaff0e7ad1792bddee540d035ef8dea8f53b Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Thu, 27 Oct 2016 18:23:27 +0200 Subject: [PATCH 18/42] PHRAS-508_acl-cache - fix "static" into method causing side effects --- lib/classes/ACL.php | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/lib/classes/ACL.php b/lib/classes/ACL.php index 3036777dca..f220183589 100644 --- a/lib/classes/ACL.php +++ b/lib/classes/ACL.php @@ -1118,12 +1118,19 @@ class ACL implements cache_cacheableInterface $this->load_rights_bas(); $usr_id = $this->user->getId(); + + $sql_i = "INSERT INTO basusr (base_id, usr_id, actif) VALUES (:base_id, :usr_id, '1')"; + $stmt_i = $this->app->getApplicationBox()->get_connection()->prepare($sql_i); + + $sql_u = "UPDATE basusr SET actif='1' WHERE base_id = :base_id AND usr_id = :usr_id"; + $stmt_u = $this->app->getApplicationBox()->get_connection()->prepare($sql_u); + foreach ($base_ids as $base_id) { if (isset($this->_rights_bas[$base_id]) && $this->_rights_bas[$base_id][self::ACTIF] == true) { continue; } - if($this->try_give_access_to_base_insert($base_id, $usr_id) == true) { + if($this->try_give_access_to_base_insert($stmt_i, $base_id, $usr_id) == true) { $this->app['dispatcher']->dispatch( AclEvents::ACCESS_TO_BASE_GRANTED, new AccessToBaseGrantedEvent( @@ -1135,7 +1142,7 @@ class ACL implements cache_cacheableInterface ); } else { - $this->try_give_access_to_base_update($base_id, $usr_id); + $this->try_give_access_to_base_update($stmt_u, $base_id, $usr_id); } } @@ -1145,13 +1152,8 @@ class ACL implements cache_cacheableInterface return $this; } - private function try_give_access_to_base_insert($base_id, $usr_id) + private function try_give_access_to_base_insert(&$stmt, $base_id, $usr_id) { - $stmt = null; - if(!$stmt) { - $sql = "INSERT INTO basusr (base_id, usr_id, actif) VALUES (:base_id, :usr_id, '1')"; - $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); - } $inserted = false; try { $stmt->execute([':base_id' => $base_id, ':usr_id' => $usr_id]); @@ -1167,21 +1169,10 @@ class ACL implements cache_cacheableInterface return $inserted; } - private function try_give_access_to_base_update($base_id, $usr_id) + private function try_give_access_to_base_update(&$stmt, $base_id, $usr_id) { - $stmt = null; - if(!$stmt) { - $sql = "UPDATE basusr SET actif='1' WHERE base_id = :base_id AND usr_id = :usr_id"; - $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); - } - - try { - $stmt->execute([':base_id' => $base_id, ':usr_id' => $usr_id]); - $stmt->closeCursor(); - } - catch(DBALException $e) { - // no-op, mostly the row was deleted - } + $stmt->execute([':base_id' => $base_id, ':usr_id' => $usr_id]); + $stmt->closeCursor(); } /** From e42bb376f80bda7ae173fe782392e4408b6f4bcc Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Thu, 27 Oct 2016 18:32:39 +0200 Subject: [PATCH 19/42] PHRAS-508_acl-cache - fix ref on pdo stmt --- .../Elastic/Indexer/RecordIndex.php | 2 +- lib/classes/ACL.php | 5 +++-- .../Fixtures/configuration-setup.yml | 1 + .../Configuration/Fixtures/configuration.yml | 1 + tests/files/cestlafete.jpg | Bin 31486 -> 31487 bytes 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php index 321b19f951..e2af26a5ac 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php @@ -118,7 +118,7 @@ class RecordIndex implements MappingProvider $child->setAnalyzer('keyword', 'searching'); $child->addChild((new Mapping\StringFieldMapping('raw'))->enableRawIndexing()); - $thesaurusMapping->addChild($thesaurusMapping); + $thesaurusMapping->addChild($child); } return $thesaurusMapping; diff --git a/lib/classes/ACL.php b/lib/classes/ACL.php index f220183589..5c51cbee2f 100644 --- a/lib/classes/ACL.php +++ b/lib/classes/ACL.php @@ -1152,8 +1152,9 @@ class ACL implements cache_cacheableInterface return $this; } - private function try_give_access_to_base_insert(&$stmt, $base_id, $usr_id) + private function try_give_access_to_base_insert(PDOStatement $stmt, $base_id, $usr_id) { + $stmt = null; $inserted = false; try { $stmt->execute([':base_id' => $base_id, ':usr_id' => $usr_id]); @@ -1169,7 +1170,7 @@ class ACL implements cache_cacheableInterface return $inserted; } - private function try_give_access_to_base_update(&$stmt, $base_id, $usr_id) + private function try_give_access_to_base_update(PDOStatement $stmt, $base_id, $usr_id) { $stmt->execute([':base_id' => $base_id, ':usr_id' => $usr_id]); $stmt->closeCursor(); diff --git a/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration-setup.yml b/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration-setup.yml index 3a312ed3bb..27eb933247 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration-setup.yml +++ b/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration-setup.yml @@ -5,6 +5,7 @@ languages: main: maintenance: false key: '' + api_require_ssl: true database: host: 'sql-host' port: 3306 diff --git a/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration.yml b/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration.yml index 3a312ed3bb..27eb933247 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration.yml +++ b/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration.yml @@ -5,6 +5,7 @@ languages: main: maintenance: false key: '' + api_require_ssl: true database: host: 'sql-host' port: 3306 diff --git a/tests/files/cestlafete.jpg b/tests/files/cestlafete.jpg index 7829881e396c2a8862683d4894933fffaddb56e2..698ec817b02d162ef301cc2c87de508aa5208a58 100755 GIT binary patch delta 26 icmezOmGS>q#tn{)jE0k)7$>kA8t56AZ@$K;Q3(K+K?#}w delta 25 hcmezWmGR$K#tn{)j0TgP7$>k;>X{pCzRsvo2>^~H32^`b From a7fe5090c64b9bac8f8755fabc5a14e8e9b9699a Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Thu, 27 Oct 2016 18:38:33 +0200 Subject: [PATCH 20/42] PHRAS-508_acl-cache - fix ref on pdo stmt. again. --- lib/classes/ACL.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/classes/ACL.php b/lib/classes/ACL.php index 5c51cbee2f..86817a3f5f 100644 --- a/lib/classes/ACL.php +++ b/lib/classes/ACL.php @@ -28,6 +28,7 @@ use Alchemy\Phrasea\Model\RecordInterface; use Alchemy\Phrasea\Model\RecordReferenceInterface; use Alchemy\Phrasea\Utilities\NullableDateTime; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Statement; class ACL implements cache_cacheableInterface @@ -1152,9 +1153,8 @@ class ACL implements cache_cacheableInterface return $this; } - private function try_give_access_to_base_insert(PDOStatement $stmt, $base_id, $usr_id) + private function try_give_access_to_base_insert(Statement $stmt, $base_id, $usr_id) { - $stmt = null; $inserted = false; try { $stmt->execute([':base_id' => $base_id, ':usr_id' => $usr_id]); @@ -1170,7 +1170,7 @@ class ACL implements cache_cacheableInterface return $inserted; } - private function try_give_access_to_base_update(PDOStatement $stmt, $base_id, $usr_id) + private function try_give_access_to_base_update(Statement $stmt, $base_id, $usr_id) { $stmt->execute([':base_id' => $base_id, ':usr_id' => $usr_id]); $stmt->closeCursor(); From 68ab86d9d446cd632b771f17dc19e25ec16faff7 Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Wed, 2 Nov 2016 17:29:20 +0100 Subject: [PATCH 21/42] PHRAS-1260_INDEX-WIDTH-HEIGHT - new : added with & height of document to es --- .../SearchEngine/Elastic/ElasticsearchRecordHydrator.php | 2 ++ .../Phrasea/SearchEngine/Elastic/Indexer/Record/Fetcher.php | 4 +++- .../Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchRecordHydrator.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchRecordHydrator.php index 5d5d57631e..9dd72e7a3f 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchRecordHydrator.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchRecordHydrator.php @@ -51,6 +51,8 @@ class ElasticsearchRecordHydrator $record->setOriginalName(igorw\get_in($data, ['original_name'], '')); $record->setRecordId(igorw\get_in($data, ['record_id'], 0)); $record->setSha256(igorw\get_in($data, ['sha256'], '')); + $record->setWidth(igorw\get_in($data, ['width'], 0)); + $record->setHeight(igorw\get_in($data, ['height'], 0)); $record->setType(igorw\get_in($data, ['type'], 'unknown')); $updatedOn = igorw\get_in($data, ['updated_on']); $record->setUpdated($updatedOn ? new \DateTime($updatedOn) : $updatedOn); diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Fetcher.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Fetcher.php index 187809c573..fab2e099c4 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Fetcher.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Fetcher.php @@ -132,7 +132,9 @@ class Fetcher . ", r.sha256" // -- TODO rename in "hash" . ", r.originalname AS original_name" . ", r.mime, r.type, r.parent_record_id, r.credate AS created_on, r.moddate AS updated_on" - . " FROM record r INNER JOIN coll c ON (c.coll_id = r.coll_id)" + . ", subdef.width, subdef.height" + . " FROM (record r INNER JOIN coll c ON (c.coll_id = r.coll_id))" + . " LEFT JOIN subdef ON subdef.record_id=r.record_id AND subdef.name='document'" . " -- WHERE" . " ORDER BY r.record_id DESC" . " LIMIT :offset, :limit"; diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php index e577eb6498..52e8e8c0b5 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php @@ -66,6 +66,9 @@ class RecordIndex implements MappingProvider $mapping->addStringField('type')->disableAnalysis(); $mapping->addStringField('record_type')->disableAnalysis(); + $mapping->addIntegerField('width')->disableIndexing(); + $mapping->addIntegerField('height')->disableIndexing(); + $mapping->addDateField('created_on', FieldMapping::DATE_FORMAT_MYSQL_OR_CAPTION); $mapping->addDateField('updated_on', FieldMapping::DATE_FORMAT_MYSQL_OR_CAPTION); From 2e56649c426a0a04472b8253f5a859ab86474558 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 3 Nov 2016 11:02:50 +0100 Subject: [PATCH 22/42] Fix invalid string mapping --- .../SearchEngine/Elastic/Mapping/ComplexFieldMapping.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexFieldMapping.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexFieldMapping.php index 288b82fe7b..97d757e414 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexFieldMapping.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Mapping/ComplexFieldMapping.php @@ -26,6 +26,12 @@ class ComplexFieldMapping extends ComplexMapping */ protected function getProperties() { - return [ 'fields' => parent::getProperties() ]; + $properties = parent::getProperties(); + + if (! empty($properties)) { + return ['fields' => parent::getProperties()]; + } + + return $properties; } } From 229c80fe74791d332e4da67dc62a35ec82a82f0e Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Thu, 3 Nov 2016 15:27:57 +0100 Subject: [PATCH 23/42] PHRAS-1260_INDEX-WIDTH-HEIGHT - new : added size (filesize) of document to es - new : methods getWidth(),... to record_adapter - fix : template --- .../Model/Entities/ElasticsearchRecord.php | 39 +++++++++++++++ lib/Alchemy/Phrasea/Model/RecordInterface.php | 21 ++++++++ .../Elastic/ElasticsearchRecordHydrator.php | 1 + .../Elastic/Indexer/Record/Fetcher.php | 2 +- .../Indexer/Record/Hydrator/CoreHydrator.php | 3 ++ .../Elastic/Indexer/RecordIndex.php | 1 + lib/classes/record/adapter.php | 45 +++++++++++++++++ .../web/common/technical_datas.html.twig | 48 +++++++++++-------- 8 files changed, 140 insertions(+), 20 deletions(-) diff --git a/lib/Alchemy/Phrasea/Model/Entities/ElasticsearchRecord.php b/lib/Alchemy/Phrasea/Model/Entities/ElasticsearchRecord.php index 101e63401b..7f077d02f5 100644 --- a/lib/Alchemy/Phrasea/Model/Entities/ElasticsearchRecord.php +++ b/lib/Alchemy/Phrasea/Model/Entities/ElasticsearchRecord.php @@ -38,6 +38,9 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface private $updated; private $created; private $sha256; + private $width; + private $height; + private $size; private $uuid; private $position; private $type; @@ -232,6 +235,42 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface $this->sha256 = $sha256; } + /** {@inheritdoc} */ + public function getWidth() + { + return $this->width; + } + + /** {@inheritdoc} */ + public function setWidth($width) + { + $this->width = $width; + } + + /** {@inheritdoc} */ + public function getHeight() + { + return $this->height; + } + + /** {@inheritdoc} */ + public function setHeight($height) + { + $this->height = $height; + } + + /** {@inheritdoc} */ + public function getSize() + { + return $this->size; + } + + /** {@inheritdoc} */ + public function setSize($size) + { + $this->size = $size; + } + /** * @param string|null $locale * diff --git a/lib/Alchemy/Phrasea/Model/RecordInterface.php b/lib/Alchemy/Phrasea/Model/RecordInterface.php index fb2e47fe0b..d839a38dac 100644 --- a/lib/Alchemy/Phrasea/Model/RecordInterface.php +++ b/lib/Alchemy/Phrasea/Model/RecordInterface.php @@ -48,6 +48,27 @@ interface RecordInterface extends RecordReferenceInterface /** @return array */ public function getExif(); + /** + * The width of the 'document' subdef + * + * @return integer|null + */ + public function getWidth(); + + /** + * The height of the 'document' subdef + * + * @return integer|null + */ + public function getHeight(); + + /** + * The size (filesize) of the 'document' subdef + * + * @return integer|null + */ + public function getSize(); + /** * Get Caption with requested fields if exists. * @param array $fields Returns only public fields when null diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchRecordHydrator.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchRecordHydrator.php index 9dd72e7a3f..3c6003b6fe 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchRecordHydrator.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchRecordHydrator.php @@ -53,6 +53,7 @@ class ElasticsearchRecordHydrator $record->setSha256(igorw\get_in($data, ['sha256'], '')); $record->setWidth(igorw\get_in($data, ['width'], 0)); $record->setHeight(igorw\get_in($data, ['height'], 0)); + $record->setSize(igorw\get_in($data, ['size'], 0)); $record->setType(igorw\get_in($data, ['type'], 'unknown')); $updatedOn = igorw\get_in($data, ['updated_on']); $record->setUpdated($updatedOn ? new \DateTime($updatedOn) : $updatedOn); diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Fetcher.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Fetcher.php index fab2e099c4..ab90cb4a73 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Fetcher.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Fetcher.php @@ -132,7 +132,7 @@ class Fetcher . ", r.sha256" // -- TODO rename in "hash" . ", r.originalname AS original_name" . ", r.mime, r.type, r.parent_record_id, r.credate AS created_on, r.moddate AS updated_on" - . ", subdef.width, subdef.height" + . ", subdef.width, subdef.height, subdef.size" . " FROM (record r INNER JOIN coll c ON (c.coll_id = r.coll_id))" . " LEFT JOIN subdef ON subdef.record_id=r.record_id AND subdef.name='document'" . " -- WHERE" diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Hydrator/CoreHydrator.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Hydrator/CoreHydrator.php index 135cf854e8..7dd92b567e 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Hydrator/CoreHydrator.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Hydrator/CoreHydrator.php @@ -45,6 +45,9 @@ class CoreHydrator implements HydratorInterface $record['base_id'] = $this->helper->getUniqueCollectionId($this->databox_id, $record['collection_id']); $record['databox_id'] = $this->databox_id; $record['databox_name'] = $this->databox_name; + $record['width'] = (int) $record['width']; + $record['height'] = (int) $record['height']; + $record['size'] = (int) $record['size']; $record['record_type'] = ((int) $record['parent_record_id'] === 1) ? SearchEngineInterface::GEM_TYPE_STORY diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php index 52e8e8c0b5..8f3ca67283 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndex.php @@ -68,6 +68,7 @@ class RecordIndex implements MappingProvider $mapping->addIntegerField('width')->disableIndexing(); $mapping->addIntegerField('height')->disableIndexing(); + $mapping->addIntegerField('size')->disableIndexing(); $mapping->addDateField('created_on', FieldMapping::DATE_FORMAT_MYSQL_OR_CAPTION); $mapping->addDateField('updated_on', FieldMapping::DATE_FORMAT_MYSQL_OR_CAPTION); diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index 0c72b464f6..a1f15f3c45 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -98,6 +98,13 @@ class record_adapter implements RecordInterface, cache_cacheableInterface /** @var DateTime */ private $updated; + /** @var bool|null|integer */ + private $width; + /** @var bool|null|integer */ + private $height; + /** @var bool|null|integer */ + private $size; + /** * @param Application $app * @param integer $sbas_id @@ -111,6 +118,8 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $this->reference = RecordReference::createFromDataboxIdAndRecordId($sbas_id, $record_id); $this->number = (int)$number; + $this->width = $this->height = $this->size = false; // means unknown for now + if ($load) { $this->load(); } @@ -171,6 +180,42 @@ class record_adapter implements RecordInterface, cache_cacheableInterface return $this->uuid; } + public function getWidth() + { + $this->getDocInfos(); + + return $this->width; + } + + public function getHeight() + { + $this->getDocInfos(); + + return $this->height; + } + + public function getSize() + { + $this->getDocInfos(); + + return $this->size; + } + + private function getDocInfos() + { + if($this->width === false) { // strict false means unknown + try { + $doc = $this->get_subdef('document'); + $this->width = $doc->get_width(); + $this->height = $doc->get_height(); + $this->size = $doc->get_size(); + } catch (\Exception $e) { + // failing once is failing ever + $this->width = $this->height = $this->size = null; + } + } + } + /** * @return DateTime * @deprecated use {@link self::getUpdated} instead diff --git a/templates/web/common/technical_datas.html.twig b/templates/web/common/technical_datas.html.twig index e010e7037b..b9c8156cbe 100644 --- a/templates/web/common/technical_datas.html.twig +++ b/templates/web/common/technical_datas.html.twig @@ -2,7 +2,7 @@ {% if record.story %}
    {{ 'Story_id' | trans }}
    {{ record.recordId }}
    {% else %} -
    {{ 'Record_id' | trans }}
    {{ record.recordId }}
    +
    {{ 'Record_id' | trans }}
    {{ record.recordId }}
    {% endif %} {% if not record.story %} @@ -15,27 +15,37 @@ {% endblock %} {% block td_weight %} - {# @todo we should index document weight as well #} + {% set size = record.getSize()/1024.0 %} + {% set unit = "Ko" %} + {% if size > 1000 %} + {% set size = size/1024.0 %} + {% set unit = "Mo" %} + {% endif %} + {% if size > 1000 %} + {% set size = size/1024.0 %} + {% set unit = "Go" %} + {% endif %} +
    Weight
    +
    {{ record.getSize() }} ({{ size|round(2) }} {{ unit }})
    {% endblock %} {% block td_size %} -
    {{ 'Size' | trans }}
    {% set width = record.exif[constant('media_subdef::TC_DATA_WIDTH')]|default - (null) %} - {% set height = record.exif[constant('media_subdef::TC_DATA_HEIGHT')]|default(null) %} - {% if width is not none and height is not none %} - {{ width ~ " x " ~ height }} - {% endif %}
    - {% set document = record.get_subdef('document') %} - {% if document and document.get_width() and document.get_height() %} -
     
    -
    {% if record.get_type() == 'image' and document.get_width() and document.get_height() %} - {% set size_w = (document.get_width() * (254/100) / 300) %} - {% set size_h = (document.get_height() * (254/100) / 300) %} - {{ size_w|round(1) }} x {{ size_h|round(1) }} cm (300dpi) - {% set size_w = (document.get_width() * (254/100) / 72) %}
    - {% set size_h = (document.get_height() * (254/100) / 72) %} - {{ size_w|round(1) }} x {{ size_h|round(1) }} cm (72dpi) - {% endif %}
    + {% if record.getWidth() and record.getHeight() %} + {% set width = record.getWidth() %} + {% set height = record.getHeight() %} + {% if width is not none and height is not none %} +
    {{ 'Size' | trans }}
    +
    {{ width }} x {{ height }} + {% if record.getType() == 'image' %} + {% set size_w = width * 2.54 %} + {% set size_h = height * 2.54 %} +
    + {{ (size_w/300)|round(1) }} x {{ (size_h/300)|round(1) }} cm (300 dpi) +
    + {{ (size_w/72)|round(1) }} x {{ (size_h/72)|round(1) }} cm (72 dpi) + {% endif %} +
    + {% endif %} {% endif %} {% endblock %} From 4e5d0758e69daa3b218a30a0eaeb38b03e656503 Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Thu, 3 Nov 2016 17:41:39 +0100 Subject: [PATCH 24/42] PHRAS-1279_SUBSTITUTE-UNKNOWN-TYPE - new : added type "unknown" to subviews setup so an "unknown"-type document can have substituted subdefs --- .../Phrasea/Media/MediaTypeFactory.php | 2 ++ lib/Alchemy/Phrasea/Media/Type/Type.php | 1 + lib/Alchemy/Phrasea/Media/Type/Unknown.php | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 lib/Alchemy/Phrasea/Media/Type/Unknown.php diff --git a/lib/Alchemy/Phrasea/Media/MediaTypeFactory.php b/lib/Alchemy/Phrasea/Media/MediaTypeFactory.php index 33a351ce5f..2bc93f907f 100644 --- a/lib/Alchemy/Phrasea/Media/MediaTypeFactory.php +++ b/lib/Alchemy/Phrasea/Media/MediaTypeFactory.php @@ -30,6 +30,8 @@ class MediaTypeFactory return new Type\Document(); case Type\Type::TYPE_FLASH: return new Type\Flash(); + case Type\Type::TYPE_UNKNOWN: + return new Type\Unknown(); } throw new \RuntimeException('Could not create requested media type'); diff --git a/lib/Alchemy/Phrasea/Media/Type/Type.php b/lib/Alchemy/Phrasea/Media/Type/Type.php index 6febd03a9c..731ced8149 100644 --- a/lib/Alchemy/Phrasea/Media/Type/Type.php +++ b/lib/Alchemy/Phrasea/Media/Type/Type.php @@ -18,6 +18,7 @@ interface Type const TYPE_DOCUMENT = 'document'; const TYPE_FLASH = 'flash'; const TYPE_IMAGE = 'image'; + const TYPE_UNKNOWN = 'unknown'; public function getType(); } diff --git a/lib/Alchemy/Phrasea/Media/Type/Unknown.php b/lib/Alchemy/Phrasea/Media/Type/Unknown.php new file mode 100644 index 0000000000..1b22583be9 --- /dev/null +++ b/lib/Alchemy/Phrasea/Media/Type/Unknown.php @@ -0,0 +1,21 @@ + Date: Thu, 3 Nov 2016 18:48:57 +0100 Subject: [PATCH 25/42] PHRAS-1279_SUBSTITUTE-UNKNOWN-TYPE - new : added missing options (settings) "size", "resolution", ... to "unknown"-type subdef --- lib/Alchemy/Phrasea/Media/Subdef/Subdef.php | 1 + lib/Alchemy/Phrasea/Media/Subdef/Unknown.php | 69 ++++++++++++++++++++ lib/classes/databox/subdef.php | 8 +++ 3 files changed, 78 insertions(+) create mode 100644 lib/Alchemy/Phrasea/Media/Subdef/Unknown.php diff --git a/lib/Alchemy/Phrasea/Media/Subdef/Subdef.php b/lib/Alchemy/Phrasea/Media/Subdef/Subdef.php index db42b01c84..339d50002f 100644 --- a/lib/Alchemy/Phrasea/Media/Subdef/Subdef.php +++ b/lib/Alchemy/Phrasea/Media/Subdef/Subdef.php @@ -20,6 +20,7 @@ interface Subdef const TYPE_VIDEO = 'video'; const TYPE_AUDIO = 'audio'; const TYPE_FLEXPAPER = 'flexpaper'; + const TYPE_UNKNOWN = 'unknown'; /** * One of Subdef Type const diff --git a/lib/Alchemy/Phrasea/Media/Subdef/Unknown.php b/lib/Alchemy/Phrasea/Media/Subdef/Unknown.php new file mode 100644 index 0000000000..4a19f4b3d0 --- /dev/null +++ b/lib/Alchemy/Phrasea/Media/Subdef/Unknown.php @@ -0,0 +1,69 @@ +translator = $translator; + + $this->registerOption(new OptionType\Range($this->translator->trans('Dimension'), self::OPTION_SIZE, 20, 3000, 800)); + $this->registerOption(new OptionType\Range($this->translator->trans('Resolution'), self::OPTION_RESOLUTION, 50, 300, 72)); + $this->registerOption(new OptionType\Boolean($this->translator->trans('Remove ICC Profile'), self::OPTION_STRIP, false)); + $this->registerOption(new OptionType\Boolean($this->translator->trans('Flatten layers'), self::OPTION_FLATTEN, false)); + $this->registerOption(new OptionType\Range($this->translator->trans('Quality'), self::OPTION_QUALITY, 0, 100, 75)); + $this->registerOption(new OptionType\Enum('Image Codec', self::OPTION_ICODEC, array('jpeg', 'png', 'tiff'), 'jpeg')); + } + + public function getType() + { + return self::TYPE_IMAGE; + } + + public function getDescription() + { + return $this->translator->trans('Generates an image'); + } + + public function getMediaAlchemystSpec() + { + if (! $this->spec) { + $this->spec = new ImageSpecification(); + } + + $size = $this->getOption(self::OPTION_SIZE)->getValue(); + $resolution = $this->getOption(self::OPTION_RESOLUTION)->getValue(); + + $this->spec->setImageCodec($this->getOption(self::OPTION_ICODEC)->getValue()); + $this->spec->setResizeMode(ImageSpecification::RESIZE_MODE_INBOUND_FIXEDRATIO); + $this->spec->setDimensions($size, $size); + $this->spec->setQuality($this->getOption(self::OPTION_QUALITY)->getValue()); + $this->spec->setStrip($this->getOption(self::OPTION_STRIP)->getValue()); + $this->spec->setFlatten($this->getOption(self::OPTION_FLATTEN)->getValue()); + $this->spec->setResolution($resolution, $resolution); + + return $this->spec; + } +} diff --git a/lib/classes/databox/subdef.php b/lib/classes/databox/subdef.php index e64ca7fb08..94f6f546a4 100644 --- a/lib/classes/databox/subdef.php +++ b/lib/classes/databox/subdef.php @@ -14,6 +14,7 @@ use Alchemy\Phrasea\Media\Subdef\Audio; use Alchemy\Phrasea\Media\Subdef\Video; use Alchemy\Phrasea\Media\Subdef\FlexPaper; use Alchemy\Phrasea\Media\Subdef\Gif; +use Alchemy\Phrasea\Media\Subdef\Unknown; use Alchemy\Phrasea\Media\Subdef\Subdef as SubdefSpecs; use Alchemy\Phrasea\Media\Type\Type as SubdefType; use MediaAlchemyst\Specification\SpecificationInterface; @@ -46,6 +47,7 @@ class databox_subdef SubdefType::TYPE_FLASH => [SubdefSpecs::TYPE_IMAGE], SubdefType::TYPE_IMAGE => [SubdefSpecs::TYPE_IMAGE], SubdefType::TYPE_VIDEO => [SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_VIDEO, SubdefSpecs::TYPE_ANIMATION], + SubdefType::TYPE_UNKNOWN => [SubdefSpecs::TYPE_IMAGE], ]; const CLASS_THUMBNAIL = 'thumbnail'; @@ -106,6 +108,9 @@ class databox_subdef case SubdefSpecs::TYPE_FLEXPAPER: $this->subdef_type = $this->buildFlexPaperSubdef($sd); break; + case SubdefSpecs::TYPE_UNKNOWN: + $this->subdef_type = $this->buildImageSubdef($sd); + break; } } @@ -229,6 +234,9 @@ class databox_subdef case SubdefSpecs::TYPE_VIDEO: $mediatype_obj = new Video($this->translator); break; + case SubdefSpecs::TYPE_UNKNOWN: + $mediatype_obj = new Unknown($this->translator); + break; default: continue; break; From 7a49bb56e68cc45434c7ec9e177eaf32f83dcfcf Mon Sep 17 00:00:00 2001 From: Xavier Rousset Date: Mon, 7 Nov 2016 16:51:24 +0100 Subject: [PATCH 26/42] Remove plugin folder before elasticsearch setup --- resources/ansible/roles/elasticsearch/tasks/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/resources/ansible/roles/elasticsearch/tasks/main.yml b/resources/ansible/roles/elasticsearch/tasks/main.yml index 5608d8f9f9..c869f754d2 100644 --- a/resources/ansible/roles/elasticsearch/tasks/main.yml +++ b/resources/ansible/roles/elasticsearch/tasks/main.yml @@ -31,6 +31,10 @@ apt: deb=/tmp/elasticsearch-{{ elasticsearch.version }}.deb when: not is_installed +- name: Remove old plugin directory + shell: rm -rf /usr/share/elasticsearch/plugins/analysis-icu + sudo: yes + - name: Install plugins shell: /usr/share/elasticsearch/bin/plugin install {{ item.name }}/{{ item.version }} when: not is_installed From 75a44812d62a70c5ae3835015f4e278bb771de4f Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Mon, 7 Nov 2016 18:38:51 +0100 Subject: [PATCH 27/42] PHRAS-828_CTERMS-NOT-PURGED - fix : cterms are cleared before reindexation (admin button) or populate (cli) ; terms in "stock" are preserved. nb.: rejected terms (red) are also purged so a term may pop-up again as candidate even if it had been rejected before. --- .../Phrasea/SearchEngine/Elastic/Indexer.php | 1 + lib/classes/databox.php | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer.php index 48396902de..1d7d9d2db6 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer.php @@ -142,6 +142,7 @@ class Indexer } if ($what & self::RECORDS) { + $databox->clearCandidates(); $this->recordIndexer->populateIndex($bulk, $databox); // Final flush diff --git a/lib/classes/databox.php b/lib/classes/databox.php index 57b8f754ed..b6e7e1c7d3 100644 --- a/lib/classes/databox.php +++ b/lib/classes/databox.php @@ -1193,14 +1193,40 @@ class databox extends base implements ThumbnailedElement return $this; } + public function clearCandidates() + { + try { + $domct = $this->get_dom_cterms(); + + if ($domct !== false) { + $nodesToDel = []; + for($n = $domct->documentElement->firstChild; $n; $n = $n->nextSibling) { + if(!($n->getAttribute('delbranch'))){ + $nodesToDel[] = $n; + } + } + foreach($nodesToDel as $n) { + $n->parentNode->removeChild($n); + } + if(!empty($nodesToDel)) { + $this->saveCterms($domct); + } + } + } catch (\Exception $e) { + + } + } + public function reindex() { + $this->clearCandidates(); $this->get_connection()->update('pref', ['updated_on' => '0000-00-00 00:00:00'], ['prop' => 'indexes']); // Set TO_INDEX flag on all records - $sql = "UPDATE record SET jeton = (jeton | :token)"; + $sql = "UPDATE record SET jeton = ((jeton & ~ :token_and) | :token_or)"; $stmt = $this->connection->prepare($sql); - $stmt->bindValue(':token', PhraseaTokens::TO_INDEX, PDO::PARAM_INT); + $stmt->bindValue(':token_and', PhraseaTokens::INDEXING, PDO::PARAM_INT); + $stmt->bindValue(':token_or', PhraseaTokens::TO_INDEX, PDO::PARAM_INT); $stmt->execute(); $this->app['dispatcher']->dispatch( From 120f311e5c7688b62bfd8296eb212b057a1a0566 Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Tue, 8 Nov 2016 16:57:24 +0100 Subject: [PATCH 28/42] PHRAS-830_CANDIDATES-CACHED fix : Loading cterms was not possible if the already loaded list was empty (missing html tag). Not a cache problem. --- .../Thesaurus/ThesaurusXmlHttpController.php | 60 +++---------------- 1 file changed, 8 insertions(+), 52 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Thesaurus/ThesaurusXmlHttpController.php b/lib/Alchemy/Phrasea/Controller/Thesaurus/ThesaurusXmlHttpController.php index 0bfa6e912e..b6f86c70c9 100644 --- a/lib/Alchemy/Phrasea/Controller/Thesaurus/ThesaurusXmlHttpController.php +++ b/lib/Alchemy/Phrasea/Controller/Thesaurus/ThesaurusXmlHttpController.php @@ -700,43 +700,14 @@ class ThesaurusXmlHttpController extends Controller foreach ($collections as $collection) { $lcoll .= ($lcoll?",":"") . $collection->get_coll_id(); } - $site = $this->app['phraseanet.configuration']['main']['key']; - $usr_id = $this->getAuthenticatedUser()->getId(); $tids = explode('.', $request->get('id')); $thid = implode('.', $tids); try { $databox = $this->findDataboxById($sbid); - $connbas = $databox->get_connection(); $dbname = \phrasea::sbas_labels($sbid, $this->app); - $t_nrec = []; - $lthid = strlen($thid); - - // count occurrences - if ($lthid > 1) { - $dthid = str_replace('.', 'd', $thid); - $sql = "SELECT" - . " 0+SUBSTR(t.value, " . ($lthid + 2) . ") AS k, COUNT(DISTINCT(`record_id`)) AS n" - . " FROM (thit AS t INNER JOIN record AS r USING(record_id))" - . " INNER JOIN collusr AS c ON c.site=:site AND c.usr_id=:usr_id AND r.coll_id=c.coll_id" - . " WHERE t.value LIKE :like AND r.coll_id IN(".$lcoll.") AND (r.status^c.mask_xor)&c.mask_and=0" - . " GROUP BY k ORDER BY NULL"; - $sqlparm = array(':like' => $dthid . 'd%', ':site'=>$site, ':usr_id'=>$usr_id); - - $stmt = $connbas->prepare($sql); - $stmt->execute($sqlparm); - - $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - foreach ($rs as $rowbas) { - $t_nrec[$thid . '.' . $rowbas['k']] = $rowbas; - } - } - - $databox = $this->findDataboxById($sbid); if ($request->get('type') == 'T') { $xqroot = 'thesaurus'; $dom = $databox->get_dom_thesaurus(); @@ -758,17 +729,7 @@ class ThesaurusXmlHttpController extends Controller $node0 = $nodes->item(0); $key0 = null; // key of the sy in the current language (or key of the first sy if we can't find good lng) - $nts0 = 0; // count of ts under this term - $label = $this->buildBranchLabel($dbname, $lng, $node0, $key0, $nts0); - - $class = ''; - if ($nts0 > 0) { - $class .= ( $class == '' ? '' : ' ') . 'expandable'; - } - if ($request->get('last')) { - $class .= ( $class == '' ? '' : ' ') . 'last'; - } // on dresse la liste des termes specifiques avec comme cle le synonyme dans la langue pivot $nts = 0; $tts = []; @@ -795,14 +756,14 @@ class ThesaurusXmlHttpController extends Controller } } + $field0 = $node0->getAttribute('field'); + if ($field0) { + $field0 = 'field="' . $field0 . '"'; + } + + $html .= '
      ' . "\n"; + if ($nts > 0) { - $field0 = $node0->getAttribute('field'); - if ($field0) { - $field0 = 'field="' . $field0 . '"'; - } - - $html .= '
        ' . "\n"; - if ($request->get('sortsy') && $lng != '') { ksort($tts, SORT_STRING); } elseif ($request->get('type') == 'C') { @@ -830,10 +791,6 @@ class ThesaurusXmlHttpController extends Controller $html .= '' . $ts['label'] . ''; - if (isset($t_nrec[$tid])) { - $html .= ' ' . $t_nrec[$tid]['n'] . ''; - } - $html .= "\n"; if ($ts['nts'] > 0) { @@ -842,10 +799,9 @@ class ThesaurusXmlHttpController extends Controller $html .= '' . "\n"; } - $html .= '
      ' . "\n"; } - $html .= '' . "\n"; + $html .= '
    ' . "\n"; } } } catch (\Exception $e) { From 3a0517774c0be44993f7590613e91e9552282eb5 Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Wed, 9 Nov 2016 15:22:19 +0100 Subject: [PATCH 29/42] PHRAS-1155_UPDATE-3.8-4.0-FAILS fix : the new column "Orders.notification_method" creation (2016...) is moved to an older patch (2013...) since this patch runs on 2016 orm object "Orders" --- .../Phrasea/Setup/DoctrineMigrations/OrderMigration.php | 3 +++ .../Setup/DoctrineMigrations/Version20160511160640.php | 7 ++----- lib/classes/patch/390alpha1a.php | 9 ++------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/OrderMigration.php b/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/OrderMigration.php index 6d4b2e57e8..7ca214f03e 100644 --- a/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/OrderMigration.php +++ b/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/OrderMigration.php @@ -11,6 +11,7 @@ namespace Alchemy\Phrasea\Setup\DoctrineMigrations; +use Alchemy\Phrasea\Model\Entities\Order; use Doctrine\DBAL\Schema\Schema; class OrderMigration extends AbstractMigration @@ -23,6 +24,8 @@ class OrderMigration extends AbstractMigration public function doUpSql(Schema $schema) { $this->addSql("CREATE TABLE Orders (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, basket_id INT DEFAULT NULL, order_usage VARCHAR(2048) NOT NULL, todo INT DEFAULT NULL, deadline DATETIME NOT NULL, created_on DATETIME NOT NULL, INDEX IDX_E283F8D8A76ED395 (user_id), UNIQUE INDEX UNIQ_E283F8D81BE1FB52 (basket_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"); + $this->addSql(sprintf("ALTER TABLE Orders ADD COLUMN notification_method VARCHAR(32) NOT NULL DEFAULT '%s'", Order::NOTIFY_MAIL)); + $this->addSql("ALTER TABLE Orders ALTER COLUMN notification_method DROP DEFAULT"); $this->addSql("CREATE TABLE OrderElements (id INT AUTO_INCREMENT NOT NULL, order_master INT DEFAULT NULL, order_id INT DEFAULT NULL, base_id INT NOT NULL, record_id INT NOT NULL, deny TINYINT(1) DEFAULT NULL, INDEX IDX_8C7066C8EE86B303 (order_master), INDEX IDX_8C7066C88D9F6D38 (order_id), UNIQUE INDEX unique_ordercle (base_id, record_id, order_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"); $this->addSql("ALTER TABLE Orders ADD CONSTRAINT FK_E283F8D8A76ED395 FOREIGN KEY (user_id) REFERENCES Users (id)"); $this->addSql("ALTER TABLE Orders ADD CONSTRAINT FK_E283F8D81BE1FB52 FOREIGN KEY (basket_id) REFERENCES Baskets (id)"); diff --git a/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/Version20160511160640.php b/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/Version20160511160640.php index 51c9ea55b0..3c9f7a16f0 100644 --- a/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/Version20160511160640.php +++ b/lib/Alchemy/Phrasea/Setup/DoctrineMigrations/Version20160511160640.php @@ -18,9 +18,7 @@ class Version20160511160640 extends BaseMigration { // this up() migration is auto-generated, please modify it to your needs $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); - - $this->addSql(sprintf("ALTER TABLE Orders ADD COLUMN notification_method VARCHAR(32) NOT NULL DEFAULT '%s'", Order::NOTIFY_MAIL)); - $this->addSql("ALTER TABLE Orders ALTER COLUMN notification_method DROP DEFAULT"); + // no-op } /** @@ -30,7 +28,6 @@ class Version20160511160640 extends BaseMigration { // this down() migration is auto-generated, please modify it to your needs $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); - - $this->addSql("ALTER TABLE Orders DROP COLUMN notification_method"); + // no-op } } diff --git a/lib/classes/patch/390alpha1a.php b/lib/classes/patch/390alpha1a.php index 2707f7885a..59628f6b97 100644 --- a/lib/classes/patch/390alpha1a.php +++ b/lib/classes/patch/390alpha1a.php @@ -83,10 +83,7 @@ class patch_390alpha1a extends patchAbstract $em->getEventManager()->removeEventSubscriber(new TimestampableListener()); foreach ($rs as $row) { - $sql = 'SELECT count(id) as todo - FROM order_elements - WHERE deny = NULL - AND order_id = :id'; + $sql = "SELECT count(id) as todo FROM order_elements WHERE deny = NULL AND order_id = :id"; $stmt = $conn->prepare($sql); $stmt->execute([':id' => $row['id']]); @@ -116,9 +113,7 @@ class patch_390alpha1a extends patchAbstract $em->persist($order); - $sql = 'SELECT base_id, record_id, order_master_id, deny - FROM order_elements - WHERE order_id = :id'; + $sql = "SELECT base_id, record_id, order_master_id, deny FROM order_elements WHERE order_id = :id"; $stmt = $conn->prepare($sql); $stmt->execute([':id' => $row['id']]); From 435854657f148505e0da1227bd1e839af666d873 Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Tue, 15 Nov 2016 14:56:18 +0100 Subject: [PATCH 30/42] fix: if using --name argument, some subdefs were deleted --- lib/Alchemy/Phrasea/Command/BuildSubdefs.php | 26 ++++++++++++-------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/Alchemy/Phrasea/Command/BuildSubdefs.php b/lib/Alchemy/Phrasea/Command/BuildSubdefs.php index d3cd61bac1..530ad3aded 100644 --- a/lib/Alchemy/Phrasea/Command/BuildSubdefs.php +++ b/lib/Alchemy/Phrasea/Command/BuildSubdefs.php @@ -345,7 +345,9 @@ class BuildSubdefs extends Command while( ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) ) { $type = $row['type']; - $msg = sprintf(' record %s (%s) : ', $row['record_id'], $type); + $msg = []; + + $msg[] = sprintf(' record %s (%s) :', $row['record_id'], $type); try { $record = $this->databox->get_record($row['record_id']); @@ -366,7 +368,7 @@ class BuildSubdefs extends Command $subdef->delete(); } $subdefsDeleted[] = $name; - $msg .= sprintf(" \"%s\" deleted,", $name); + $msg[] = sprintf(" \"%s\" pruned", $name); } continue; } @@ -386,10 +388,14 @@ class BuildSubdefs extends Command continue; } } + // here an existing subdef must be (re)done - if(!$this->dry) { - $subdef->remove_file(); - $subdef->set_substituted(false); + if(isset($subdefNamesToDo[$name])) { + if (!$this->dry) { + $subdef->remove_file(); + $subdef->set_substituted(false); + } + $msg[] = sprintf(" [\"%s\"] deleted", $name); } } @@ -401,7 +407,7 @@ class BuildSubdefs extends Command $subdefGenerator->generateSubdefs($record, $subdefNamesToDo); } - $msg .= sprintf(" [\"%s\"] built", implode('","', $subdefNamesToDo)); + $msg[] = sprintf(" [\"%s\"] built", implode('","', $subdefNamesToDo)); } else { // $msg .= " nothing to build"; @@ -416,10 +422,10 @@ class BuildSubdefs extends Command . ' WHERE record_id=:record_id'; if($this->reset_subdef_flag) { - $msg .= ", jeton[\"make_subdef\"]=0"; + $msg[] = "jeton[\"make_subdef\"]=0"; } if($this->set_writemeta_flag) { - $msg .= ", jeton[\"write_met_subdef\"]=1"; + $msg[] = "jeton[\"write_met_subdef\"]=1"; } if(!$this->dry) { $this->connection->executeUpdate($sql, [ @@ -436,10 +442,10 @@ class BuildSubdefs extends Command if($progress) { $progress->advance(); - $this->output->write($msg); + $this->output->write(implode(' ', $msg)); } else { - $this->output->writeln($msg); + $this->output->writeln(implode("\n", $msg)); } } From c43dcf158cdeb4862b8a2c5d287c9a498386c4c5 Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Tue, 15 Nov 2016 18:07:25 +0100 Subject: [PATCH 31/42] PHRAS-1284_MAX-DURATION-TASK-PARAMETER add : parameters "maxmeg" and "maxduration" (if present) are passed to task:run as --max-memory and --max-duration --- .../Phrasea/TaskManager/Editor/SubdefsEditor.php | 1 + lib/Alchemy/Phrasea/TaskManager/TaskList.php | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Alchemy/Phrasea/TaskManager/Editor/SubdefsEditor.php b/lib/Alchemy/Phrasea/TaskManager/Editor/SubdefsEditor.php index 0929975ed5..69d9aff8eb 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Editor/SubdefsEditor.php +++ b/lib/Alchemy/Phrasea/TaskManager/Editor/SubdefsEditor.php @@ -53,6 +53,7 @@ class SubdefsEditor extends AbstractEditor 5 20 256 + 3600 EOF; } diff --git a/lib/Alchemy/Phrasea/TaskManager/TaskList.php b/lib/Alchemy/Phrasea/TaskManager/TaskList.php index 19c5f564a8..c108a10537 100644 --- a/lib/Alchemy/Phrasea/TaskManager/TaskList.php +++ b/lib/Alchemy/Phrasea/TaskManager/TaskList.php @@ -49,6 +49,17 @@ class TaskList implements TaskListInterface $arguments[] = $this->phpConf; } + $maxmegs = 128; // default (Mo) if not set in xml + $maxduration = 1800; // default (seconds) if not set in xml + if( ($sxSettings = @simplexml_load_string($task->getSettings())) ) { + if( ($v = (int)($sxSettings->maxmegs)) && $v > 0) { + $maxmegs = $v; + } + if( ($v = (int)($sxSettings->maxduration)) && $v > 0) { + $maxduration = $v; + } + } + $arguments[] = '-f'; $arguments[] = $this->root . '/bin/console'; $arguments[] = '--'; @@ -57,9 +68,9 @@ class TaskList implements TaskListInterface $arguments[] = $task->getId(); $arguments[] = '--listen-signal'; $arguments[] = '--max-duration'; - $arguments[] = '1800'; + $arguments[] = $maxduration; $arguments[] = '--max-memory'; - $arguments[] = 128 << 20; + $arguments[] = $maxmegs << 20; $builder = ProcessBuilder::create($arguments); $builder->setTimeout(0); From 2c35af060e57bad80092865f7c72d015874a5ff1 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Wed, 16 Nov 2016 17:32:54 +0100 Subject: [PATCH 32/42] Fix download permalink in unauthenticated contexts --- lib/Alchemy/Phrasea/Controller/PermalinkController.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/PermalinkController.php b/lib/Alchemy/Phrasea/Controller/PermalinkController.php index 8a6bc586de..9baf7931bc 100644 --- a/lib/Alchemy/Phrasea/Controller/PermalinkController.php +++ b/lib/Alchemy/Phrasea/Controller/PermalinkController.php @@ -126,9 +126,7 @@ class PermalinkController extends AbstractDelivery $isDownload = $request->query->getBoolean('download', false); - if ($isDownload) { - $user = $this->app->getAuthenticatedUser(); - + if ($isDownload && $user = $this->app->getAuthenticatedUser()) { $this->getEventDispatcher()->dispatch( PhraseaEvents::EXPORT_CREATE, new ExportEvent($user, 0, $sbas_id . '_' . $record_id, [ $subdef ], '') From b8c695fe887b3fd30accae374e548f25f4151879 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 17 Nov 2016 15:47:58 +0100 Subject: [PATCH 33/42] Always add recordid as last sort option --- .../Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php index eff1c38d68..8c508afe1f 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php @@ -541,10 +541,16 @@ class ElasticSearchEngine implements SearchEngineInterface $sort['_score'] = $options->getSortOrder(); } elseif ($options->getSortBy() === SearchEngineOptions::SORT_CREATED_ON) { $sort['created_on'] = $options->getSortOrder(); + } elseif ($options->getSortBy() === 'recordid') { + $sort['recordid'] = $options->getSortOrder(); } else { $sort[sprintf('caption.%s', $options->getSortBy())] = $options->getSortOrder(); } + if (! array_key_exists('recordid', $sort)) { + $sort['recordid'] = $options->getSortOrder(); + } + return $sort; } From 52578f9c656957d79c55fd96519dcab4f191609c Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 17 Nov 2016 16:56:12 +0100 Subject: [PATCH 34/42] Fix record ID field name when generating sort query --- .../Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php index 8c508afe1f..24db11d81d 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php @@ -542,13 +542,13 @@ class ElasticSearchEngine implements SearchEngineInterface } elseif ($options->getSortBy() === SearchEngineOptions::SORT_CREATED_ON) { $sort['created_on'] = $options->getSortOrder(); } elseif ($options->getSortBy() === 'recordid') { - $sort['recordid'] = $options->getSortOrder(); + $sort['record_id'] = $options->getSortOrder(); } else { $sort[sprintf('caption.%s', $options->getSortBy())] = $options->getSortOrder(); } - if (! array_key_exists('recordid', $sort)) { - $sort['recordid'] = $options->getSortOrder(); + if (! array_key_exists('record_id', $sort)) { + $sort['record_id'] = $options->getSortOrder(); } return $sort; From 8758756c16b60b0829cd00ea963237d107d915c8 Mon Sep 17 00:00:00 2001 From: Xavier Rousset Date: Mon, 21 Nov 2016 15:06:25 +0100 Subject: [PATCH 35/42] PHRAS-1286 Add missing notifications to the list --- lib/classes/eventsmanager/broker.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/classes/eventsmanager/broker.php b/lib/classes/eventsmanager/broker.php index c7d9601bdc..4128c4273e 100644 --- a/lib/classes/eventsmanager/broker.php +++ b/lib/classes/eventsmanager/broker.php @@ -129,13 +129,13 @@ class eventsmanager_broker foreach ($rs as $row) { $type = 'eventsmanager_' . $row['type']; - $data = @json_decode($row['datas'], true); + $json = @json_decode($row['datas'], true); if (json_last_error() !== JSON_ERROR_NONE) { continue; } - $content = $this->pool_classes[$type]->datas($data, $row['unread']); + $content = $this->pool_classes[$type]->datas($json, $row['unread']); if ( ! isset($this->pool_classes[$type]) || count($content) === 0) { $sql = 'DELETE FROM notifications WHERE id = :id'; From d00d674cdf2fd7ccc99f695a510d59cd35a71498 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 24 Nov 2016 17:21:11 +0100 Subject: [PATCH 36/42] Fix document substitution --- lib/Alchemy/Phrasea/Application.php | 1 + .../Phrasea/Controller/Admin/TaskManagerController.php | 3 +++ lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php | 2 ++ lib/Alchemy/Phrasea/Filesystem/FilesystemService.php | 3 +++ lib/Alchemy/Phrasea/Media/SubdefSubstituer.php | 4 ++-- lib/classes/media/subdef.php | 2 ++ 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index dea7992be8..c194068aa7 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -537,6 +537,7 @@ class Application extends SilexApplication $this['root.path'] = realpath(__DIR__ . '/../../..'); // temporary resources default path such as download zip, quarantined documents etc .. $this['tmp.path'] = getenv('PHRASEANET_TMP') ?: $this['root.path'].'/tmp'; + // plugin path $this['plugin.path'] = $this['root.path'].'/plugins'; // thumbnails path diff --git a/lib/Alchemy/Phrasea/Controller/Admin/TaskManagerController.php b/lib/Alchemy/Phrasea/Controller/Admin/TaskManagerController.php index 0fd26968da..086119ec0b 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/TaskManagerController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/TaskManagerController.php @@ -46,8 +46,10 @@ class TaskManagerController extends Controller $this->getDispatcher()->addListener(KernelEvents::TERMINATE, function () use ($cmdLine) { $process = new Process($cmdLine); + $process->setTimeout(0); $process->disableOutput(); + set_time_limit(0); ignore_user_abort(true); @@ -65,6 +67,7 @@ class TaskManagerController extends Controller $info = $this->getLiveInformationRequest(); $data = $info->getManager(); + if (null !== $pid = $data['process-id']) { if (substr(php_uname(), 0, 7) == "Windows"){ exec(sprintf('TaskKill /PID %d', $pid)); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php b/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php index 556d3d8c3a..2c037b9c00 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php @@ -186,8 +186,10 @@ class ToolsController extends Controller try { $tempoDir = tempnam(sys_get_temp_dir(), 'substit'); + unlink($tempoDir); mkdir($tempoDir); + $tempoFile = $tempoDir . DIRECTORY_SEPARATOR . $fileName; if (false === rename($file->getPathname(), $tempoFile)) { diff --git a/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php b/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php index bbe1c32ab9..9d5e75822d 100644 --- a/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php +++ b/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php @@ -115,6 +115,7 @@ class FilesystemService * @param \databox $databox * @param string $source * @param string $filename + * @return string */ public function writeMediaSourceFile(\databox $databox, $source, $filename) { @@ -122,6 +123,8 @@ class FilesystemService $this->filesystem->copy($source, $realPath, true); $this->filesystem->chmod($realPath, 0760); + + return $realPath; } /** diff --git a/lib/Alchemy/Phrasea/Media/SubdefSubstituer.php b/lib/Alchemy/Phrasea/Media/SubdefSubstituer.php index 6333ba4fd1..3bbdc2666d 100644 --- a/lib/Alchemy/Phrasea/Media/SubdefSubstituer.php +++ b/lib/Alchemy/Phrasea/Media/SubdefSubstituer.php @@ -67,9 +67,9 @@ class SubdefSubstituer $source = $file->getRealPath(); $target = $this->fs->generateDocumentFilename($record, $file); - $this->fs->writeMediaSourceFile($record->getDatabox(), $source, $target); + $target = $this->fs->writeMediaSourceFile($record->getDatabox(), $source, $target); - $media = $this->mediavorus->guess($source); + $media = $this->mediavorus->guess($target); $this->createMediaSubdef($record, 'document', $media); diff --git a/lib/classes/media/subdef.php b/lib/classes/media/subdef.php index ed9cf0ffe6..339efac9d1 100644 --- a/lib/classes/media/subdef.php +++ b/lib/classes/media/subdef.php @@ -656,10 +656,12 @@ class media_subdef extends media_abstract implements cache_cacheableInterface $params['height'] = $media->getHeight(); } + /** @var callable $factoryProvider */ $factoryProvider = $app['provider.factory.media_subdef']; $factory = $factoryProvider($record->getDataboxId()); $subdef = $factory($params); + Assertion::isInstanceOf($subdef, \media_subdef::class); $repository = self::getMediaSubdefRepository($app, $record->getDataboxId()); From 53c21825887e82067fd5cf6c29e484d36c50961f Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Fri, 25 Nov 2016 11:47:43 +0100 Subject: [PATCH 37/42] PHRAS-1092 Prevent password reset when saving config in admin --- .../Controller/Admin/SetupController.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Alchemy/Phrasea/Controller/Admin/SetupController.php b/lib/Alchemy/Phrasea/Controller/Admin/SetupController.php index a3738d8e91..01d94d132e 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/SetupController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/SetupController.php @@ -14,6 +14,7 @@ use Alchemy\Phrasea\Controller\Controller; use Alchemy\Phrasea\Core\Configuration\Configuration; use Alchemy\Phrasea\Core\Configuration\PropertyAccess; use Alchemy\Phrasea\Core\Configuration\RegistryManipulator; +use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; class SetupController extends Controller @@ -30,7 +31,7 @@ class SetupController extends Controller if ('POST' === $request->getMethod()) { $form->submit($request->request->all()); if ($form->isValid()) { - $config->set('registry', $manipulator->getRegistryData($form)); + $config->set('registry', $this->buildRegistryData($config, $manipulator, $form)); return $this->app->redirectPath('setup_display_globals'); } @@ -42,4 +43,21 @@ class SetupController extends Controller 'form' => $form->createView(), ]); } + + /** + * @param PropertyAccess $config + * @param RegistryManipulator $manipulator + * @param FormInterface $form + * @return mixed + */ + protected function buildRegistryData(PropertyAccess $config, RegistryManipulator $manipulator, FormInterface $form) + { + $data = $manipulator->getRegistryData($form); + + if ($data['email']['smtp-password'] == null) { + $data['email']['smtp-password'] = $config->get([ 'registry', 'email', 'smtp-password']); + } + + return $data; + } } From 88a2813843ff9a12ff97ad7214ac59aafcb4a1b5 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Fri, 25 Nov 2016 12:09:45 +0100 Subject: [PATCH 38/42] Refactor setup controller and registry manipulator --- .../Controller/Admin/SetupController.php | 54 +++--- .../ControllerProvider/Admin/Setup.php | 2 +- .../Configuration/RegistryFormManipulator.php | 178 ++++++++++++++++++ .../Configuration/RegistryManipulator.php | 170 +---------------- 4 files changed, 210 insertions(+), 194 deletions(-) create mode 100644 lib/Alchemy/Phrasea/Core/Configuration/RegistryFormManipulator.php diff --git a/lib/Alchemy/Phrasea/Controller/Admin/SetupController.php b/lib/Alchemy/Phrasea/Controller/Admin/SetupController.php index 01d94d132e..0ca5c9f262 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/SetupController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/SetupController.php @@ -10,30 +10,43 @@ namespace Alchemy\Phrasea\Controller\Admin; +use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Controller\Controller; -use Alchemy\Phrasea\Core\Configuration\Configuration; use Alchemy\Phrasea\Core\Configuration\PropertyAccess; -use Alchemy\Phrasea\Core\Configuration\RegistryManipulator; -use Symfony\Component\Form\FormInterface; +use Alchemy\Phrasea\Core\Configuration\RegistryFormManipulator; use Symfony\Component\HttpFoundation\Request; class SetupController extends Controller { + /** + * @var RegistryFormManipulator + */ + private $registryFormManipulator; + + /** + * @var PropertyAccess + */ + private $configuration; + + public function __construct(Application $app, RegistryFormManipulator $registryFormManipulator, PropertyAccess $configuration) + { + parent::__construct($app); + + $this->registryFormManipulator = $registryFormManipulator; + $this->configuration = $configuration; + } + public function submitGlobalsAction(Request $request) { - /** @var RegistryManipulator $manipulator */ - $manipulator = $this->app['registry.manipulator']; - /** @var PropertyAccess $config */ - $config = $this->app['conf']; - - $form = $manipulator->createForm($this->app['conf']); + $form = $this->registryFormManipulator->createForm(); if ('POST' === $request->getMethod()) { $form->submit($request->request->all()); - if ($form->isValid()) { - $config->set('registry', $this->buildRegistryData($config, $manipulator, $form)); - return $this->app->redirectPath('setup_display_globals'); + if ($form->isValid()) { + $registryData = $this->registryFormManipulator->getRegistryData($form, $this->configuration); + + $this->configuration->set('registry', $registryData); } // Do not return a 400 status code as not very well handled in calling JS. @@ -43,21 +56,4 @@ class SetupController extends Controller 'form' => $form->createView(), ]); } - - /** - * @param PropertyAccess $config - * @param RegistryManipulator $manipulator - * @param FormInterface $form - * @return mixed - */ - protected function buildRegistryData(PropertyAccess $config, RegistryManipulator $manipulator, FormInterface $form) - { - $data = $manipulator->getRegistryData($form); - - if ($data['email']['smtp-password'] == null) { - $data['email']['smtp-password'] = $config->get([ 'registry', 'email', 'smtp-password']); - } - - return $data; - } } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Setup.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Setup.php index 0575dc8a4c..9734c038fd 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Setup.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Setup.php @@ -24,7 +24,7 @@ class Setup implements ControllerProviderInterface, ServiceProviderInterface public function register(Application $app) { $app['controller.admin.setup'] = $app->share(function (PhraseaApplication $app) { - return new SetupController($app); + return new SetupController($app, $app['registry.manipulator'], $app['conf']); }); } diff --git a/lib/Alchemy/Phrasea/Core/Configuration/RegistryFormManipulator.php b/lib/Alchemy/Phrasea/Core/Configuration/RegistryFormManipulator.php new file mode 100644 index 0000000000..9543cbbc6d --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Configuration/RegistryFormManipulator.php @@ -0,0 +1,178 @@ +factory = $factory; + $this->languages = $languages; + $this->translator = $translator; + } + + /** + * Creates a setup form. Set data if a configuration is given. + * + * @param PropertyAccess $conf + * + * @return FormInterface + */ + public function createForm(PropertyAccess $conf = null) + { + $form = $this->factory->create(new MainConfigurationFormType($this->translator, $this->languages)); + $currentConf = $conf ? ($conf->get('registry') ?: []) : []; + $data = array_replace_recursive($this->getDefaultData($currentConf), $currentConf); + $form->setData($data); + + return $form; + } + + /** + * Gets the registry data given a submitted form. + * Default configuration is returned if no form provided. + * + * @param FormInterface $form + * + * @param PropertyAccess $conf + * @return array + */ + public function getRegistryData(FormInterface $form = null, PropertyAccess $conf = null) + { + $data = []; + + if (null !== $form) { + if (!$form->isSubmitted()) { + throw new RuntimeException('Form must have been submitted'); + } + $newData = $form->getData(); + $data = $this->filterNullValues($newData); + } + + $currentConf = $conf ? ($conf->get('registry') ?: []) : []; + + return array_replace_recursive($this->getDefaultData($currentConf), $data); + } + + private function filterNullValues(array &$array) + { + return array_filter($array, function (&$value) { + if (is_array($value)) { + $value = $this->filterNullValues($value); + } + + return null !== $value; + }); + } + + private function getDefaultData(array $config) + { + return [ + 'general' => [ + 'title' => 'Phraseanet', + 'keywords' => null, + 'description' => null, + 'analytics' => null, + 'allow-indexation' => true, + 'home-presentation-mode' => 'GALLERIA', + 'default-subdef-url-ttl' => 7200, + ], + 'modules' => [ + 'thesaurus' => true, + 'stories' => true, + 'doc-substitution' => true, + 'thumb-substitution' => true, + 'anonymous-report' => false, + ], + 'actions' => [ + 'download-max-size' => 120, + 'validation-reminder-days' => 2, + 'validation-expiration-days' => 10, + 'auth-required-for-export' => true, + 'tou-validation-required-for-export' => false, + 'export-title-choice' => false, + 'default-export-title' => 'title', + 'social-tools' => 'none', + 'enable-push-authentication' => false, + 'force-push-authentication' => false, + 'enable-feed-notification' => true, + ], + 'ftp' => [ + 'ftp-enabled' => false, + 'ftp-user-access' => false, + ], + 'registration' => [ + 'auto-select-collections' => true, + 'auto-register-enabled' => false, + ], + 'maintenance' => [ + 'message' => 'The application is down for maintenance', + 'enabled' => false, + ], + 'api-clients' => [ + 'api-enabled' => true, + 'navigator-enabled' => true, + 'office-enabled' => true, + ], + 'webservices' => [ + 'google-charts-enabled' => true, + 'geonames-server' => 'http://geonames.alchemyasp.com/', + 'captchas-enabled' => false, + 'recaptcha-public-key' => '', + 'recaptcha-private-key' => '', + ], + 'executables' => [ + 'h264-streaming-enabled' => false, + 'auth-token-directory' => null, + 'auth-token-directory-path' => null, + 'auth-token-passphrase' => null, + 'php-conf-path' => null, + 'imagine-driver' => '', + 'ffmpeg-threads' => 2, + 'pdf-max-pages' => 5, + ], + 'searchengine' => [ + 'min-letters-truncation' => 1, + 'default-query' => '', + 'default-query-type' => 0, + ], + 'email' => [ + 'emitter-email' => 'phraseanet@example.com', + 'prefix' => null, + 'smtp-enabled' => false, + 'smtp-auth-enabled' => false, + 'smtp-host' => null, + 'smtp-port' => null, + 'smtp-secure-mode' => 'tls', + 'smtp-user' => null, + 'smtp-password' => isset($config['email']['smtp-password']) ? $config['email']['smtp-password'] : null, + ], + ]; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Configuration/RegistryManipulator.php b/lib/Alchemy/Phrasea/Core/Configuration/RegistryManipulator.php index a8a73423c9..1fba436dbe 100644 --- a/lib/Alchemy/Phrasea/Core/Configuration/RegistryManipulator.php +++ b/lib/Alchemy/Phrasea/Core/Configuration/RegistryManipulator.php @@ -17,170 +17,12 @@ use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Translation\TranslatorInterface; -class RegistryManipulator +/** + * Class RegistryManipulator + * @package Alchemy\Phrasea\Core\Configuration + * @deprecated Use RegistryFormManipulator instead + */ +class RegistryManipulator extends RegistryFormManipulator { - /** - * @var FormFactoryInterface - */ - private $factory; - /** - * @var array - */ - private $languages; - - /** - * @var TranslatorInterface - */ - private $translator; - - /** - * @param FormFactoryInterface $factory - * @param TranslatorInterface $translator - * @param array $languages - */ - public function __construct(FormFactoryInterface $factory, TranslatorInterface $translator, array $languages) - { - $this->factory = $factory; - $this->languages = $languages; - $this->translator = $translator; - } - - /** - * Creates a setup form. Set data if a configuration is given. - * - * @param PropertyAccess $conf - * - * @return FormInterface - */ - public function createForm(PropertyAccess $conf = null) - { - $form = $this->factory->create(new MainConfigurationFormType($this->translator, $this->languages)); - $currentConf = $conf ? ($conf->get('registry') ?: []) : []; - $data = array_replace_recursive($this->getDefaultData(), $currentConf); - $form->setData($data); - - return $form; - } - - /** - * Gets the registry data given a submitted form. - * Default configuration is returned if no form provided. - * - * @param FormInterface $form - * - * @return array - * - * @throws RuntimeException - */ - public function getRegistryData(FormInterface $form = null) - { - $data = []; - - if (null !== $form) { - if (!$form->isSubmitted()) { - throw new RuntimeException('Form must have been submitted'); - } - $newData = $form->getData(); - $data = $this->filterNullValues($newData); - } - - return array_replace_recursive($this->getDefaultData(), $data); - } - - private function filterNullValues(array &$array) - { - return array_filter($array, function (&$value) { - if (is_array($value)) { - $value = $this->filterNullValues($value); - } - - return null !== $value; - }); - } - - private function getDefaultData() - { - return [ - 'general' => [ - 'title' => 'Phraseanet', - 'keywords' => null, - 'description' => null, - 'analytics' => null, - 'allow-indexation' => true, - 'home-presentation-mode' => 'GALLERIA', - 'default-subdef-url-ttl' => 7200, - ], - 'modules' => [ - 'thesaurus' => true, - 'stories' => true, - 'doc-substitution' => true, - 'thumb-substitution' => true, - 'anonymous-report' => false, - ], - 'actions' => [ - 'download-max-size' => 120, - 'validation-reminder-days' => 2, - 'validation-expiration-days' => 10, - 'auth-required-for-export' => true, - 'tou-validation-required-for-export' => false, - 'export-title-choice' => false, - 'default-export-title' => 'title', - 'social-tools' => 'none', - 'enable-push-authentication' => false, - 'force-push-authentication' => false, - 'enable-feed-notification' => true, - ], - 'ftp' => [ - 'ftp-enabled' => false, - 'ftp-user-access' => false, - ], - 'registration' => [ - 'auto-select-collections' => true, - 'auto-register-enabled' => false, - ], - 'maintenance' => [ - 'message' => 'The application is down for maintenance', - 'enabled' => false, - ], - 'api-clients' => [ - 'api-enabled' => true, - 'navigator-enabled' => true, - 'office-enabled' => true, - ], - 'webservices' => [ - 'google-charts-enabled' => true, - 'geonames-server' => 'http://geonames.alchemyasp.com/', - 'captchas-enabled' => false, - 'recaptcha-public-key' => '', - 'recaptcha-private-key' => '', - ], - 'executables' => [ - 'h264-streaming-enabled' => false, - 'auth-token-directory' => null, - 'auth-token-directory-path' => null, - 'auth-token-passphrase' => null, - 'php-conf-path' => null, - 'imagine-driver' => '', - 'ffmpeg-threads' => 2, - 'pdf-max-pages' => 5, - ], - 'searchengine' => [ - 'min-letters-truncation' => 1, - 'default-query' => '', - 'default-query-type' => 0, - ], - 'email' => [ - 'emitter-email' => 'phraseanet@example.com', - 'prefix' => null, - 'smtp-enabled' => false, - 'smtp-auth-enabled' => false, - 'smtp-host' => null, - 'smtp-port' => null, - 'smtp-secure-mode' => 'tls', - 'smtp-user' => null, - 'smtp-password' => null, - ], - ]; - } } From 22542f8df87480c842c5b82e5b22b04d904ced7e Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Fri, 25 Nov 2016 15:12:15 +0100 Subject: [PATCH 39/42] Update test assertions --- tests/Alchemy/Tests/Phrasea/Controller/Admin/SetupTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/SetupTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/SetupTest.php index 1cdb60dc85..dc8553ad90 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/SetupTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/SetupTest.php @@ -61,6 +61,7 @@ class SetupTest extends \PhraseanetAuthenticatedWebTestCase /** @var Client $client */ $client = self::$DI['client']; $client->request('POST', '/admin/setup/', ['_token' => 'token']); - $this->assertTrue($client->getResponse()->isRedirect('/admin/setup/')); + + $this->assertTrue($client->getResponse()->isSuccessful()); } } From e7dd94d5b8fed10a3a7595412f411f93dd4ae723 Mon Sep 17 00:00:00 2001 From: Xavier Rousset Date: Thu, 1 Dec 2016 15:03:34 +0100 Subject: [PATCH 40/42] Fix misplaced icon on admin dashboard --- resources/www/admin/styles/main.scss | 1 + templates/web/admin/dashboard.html.twig | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/resources/www/admin/styles/main.scss b/resources/www/admin/styles/main.scss index 254a8c409c..858ac450f8 100644 --- a/resources/www/admin/styles/main.scss +++ b/resources/www/admin/styles/main.scss @@ -253,6 +253,7 @@ div.switch_right.unchecked { } .board_section div[class="section"] ul.setup li.blocker { background-image: url('#{$iconsPath}delete.png'); + background-size: 16px; } .board_section div[class="section"] ul.setup li:hover { background-color: #fffbcd; diff --git a/templates/web/admin/dashboard.html.twig b/templates/web/admin/dashboard.html.twig index 2242d18c17..2018626663 100644 --- a/templates/web/admin/dashboard.html.twig +++ b/templates/web/admin/dashboard.html.twig @@ -7,11 +7,11 @@
  • {{ requirement.getTestMessage }} -

    {% if not requirement.isFulfilled() %} +

    {{ requirement.getHelpHtml() | raw }} - {% endif %}

    + {% endif %}
  • {% endfor %} {% endif %} From cadb9febabf3a8f4a9eaa4356dc64b4ad07f4161 Mon Sep 17 00:00:00 2001 From: Xavier Rousset Date: Fri, 2 Dec 2016 15:26:31 +0100 Subject: [PATCH 41/42] PHRAS-1220 Add warn message in admin fields setup --- resources/www/admin/styles/main.scss | 4 +++- templates/web/admin/fields/index.html.twig | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/resources/www/admin/styles/main.scss b/resources/www/admin/styles/main.scss index 254a8c409c..9317fd9997 100644 --- a/resources/www/admin/styles/main.scss +++ b/resources/www/admin/styles/main.scss @@ -322,7 +322,9 @@ div.switch_right.unchecked { #admin_setup_registry .form-horizontal .controls, #admin_setup_registry .form-horizontal .help-message { margin-left: 300px; } - +.alert .close{ + text-decoration: none; +} @import './databases'; @import './fields'; diff --git a/templates/web/admin/fields/index.html.twig b/templates/web/admin/fields/index.html.twig index f9c71746ad..e8198a324f 100644 --- a/templates/web/admin/fields/index.html.twig +++ b/templates/web/admin/fields/index.html.twig @@ -1,5 +1,10 @@