From 7c82a97340dafc05c2b65395aa50e24a76b780f2 Mon Sep 17 00:00:00 2001 From: Vadim Tokarchuk Date: Tue, 4 Apr 2017 18:27:05 +0300 Subject: [PATCH] CRM-7829: Report grid has extra disallowed actions (#8553) --- .../Datagrid/EventListener/ButtonListener.php | 17 ++++++++++++----- .../EventListener/ButtonListenerTest.php | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/Oro/Bundle/ActionBundle/Datagrid/EventListener/ButtonListener.php b/src/Oro/Bundle/ActionBundle/Datagrid/EventListener/ButtonListener.php index d7e2af96207..5a5865fcbbd 100644 --- a/src/Oro/Bundle/ActionBundle/Datagrid/EventListener/ButtonListener.php +++ b/src/Oro/Bundle/ActionBundle/Datagrid/EventListener/ButtonListener.php @@ -93,10 +93,13 @@ public function onConfigureActions(ConfigureActionsBefore $event) } $this->searchContext = $this->getButtonSearchContext($config); - $this->buttons = $this->getButtons( - $this->searchContext, - $config->offsetGetOr(ActionExtension::ACTION_KEY, []) - ); + + if (null === $this->buttons) { + $this->buttons = $this->getButtons( + $this->searchContext, + $config->offsetGetOr(ActionExtension::ACTION_KEY, []) + ); + } if (0 === count($this->buttons)) { return; @@ -154,8 +157,12 @@ function ( ) { $name = strtolower($button->getName()); $enabled = false; - $newButton = clone $button; + + if ($searchContext->getEntityId() === null) { + $configuration[$name] = false; + } + if (!array_key_exists($name, $configuration) || $configuration[$name] !== false) { $enabled = $extension->isAvailable($newButton, $searchContext); } diff --git a/src/Oro/Bundle/ActionBundle/Tests/Unit/Datagrid/EventListener/ButtonListenerTest.php b/src/Oro/Bundle/ActionBundle/Tests/Unit/Datagrid/EventListener/ButtonListenerTest.php index 2fb34ae64de..7e124a597b0 100644 --- a/src/Oro/Bundle/ActionBundle/Tests/Unit/Datagrid/EventListener/ButtonListenerTest.php +++ b/src/Oro/Bundle/ActionBundle/Tests/Unit/Datagrid/EventListener/ButtonListenerTest.php @@ -376,6 +376,25 @@ public function getRowConfigurationProvider() 'action3' => false ], ], + 'operations not allowed' => [ + 'config' => DatagridConfiguration::create([ + 'name' => 'datagrid_name', + 'source' => [ + 'type' => OrmDatasource::TYPE, + ], + ]), + 'record' => new ResultRecord([]), + 'buttonCollection' => $this->createButtonsCollection( + [ + $this->createButton('operation1', true), + $this->createButton('operation2', false) + ] + ), + 'expectedActions' => [ + 'operation1' => false, + 'operation2' => false + ], + ], '1 allowed action and array parent config' => [ 'config' => DatagridConfiguration::create([ 'name' => 'datagrid_name',