Skip to content

Commit 14dfbc0

Browse files
committed
[fixed] Login As Customer functionality is available when Login As Customer->Enable Extension=No
1 parent c987bbc commit 14dfbc0

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

app/code/Magento/LoginAsCustomerUi/Block/Adminhtml/ConfirmationPopup.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,17 @@ public function getJsLayout()
7979

8080
return $this->json->serialize($layout);
8181
}
82+
83+
/**
84+
* Render block HTML
85+
*
86+
* @return string
87+
*/
88+
protected function _toHtml()
89+
{
90+
if (!$this->config->isEnabled()) {
91+
return '';
92+
}
93+
return parent::_toHtml();
94+
}
8295
}

app/code/Magento/LoginAsCustomerUi/Plugin/Button/ToolbarPlugin.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\View\Element\AbstractBlock;
1313
use Magento\Framework\Escaper;
1414
use Magento\Framework\AuthorizationInterface;
15+
use Magento\LoginAsCustomerApi\Api\ConfigInterface;
1516

1617
/**
1718
* Plugin for \Magento\Backend\Block\Widget\Button\Toolbar.
@@ -28,16 +29,24 @@ class ToolbarPlugin
2829
*/
2930
private $escaper;
3031

32+
/**
33+
* @var ConfigInterface
34+
*/
35+
private $config;
36+
3137
/**
3238
* ToolbarPlugin constructor.
3339
* @param AuthorizationInterface $authorization
40+
* @param ConfigInterface $config
3441
* @param Escaper $escaper
3542
*/
3643
public function __construct(
3744
AuthorizationInterface $authorization,
45+
ConfigInterface $config,
3846
Escaper $escaper
3947
) {
4048
$this->authorization = $authorization;
49+
$this->config = $config;
4150
$this->escaper = $escaper;
4251
}
4352

@@ -67,7 +76,10 @@ public function beforePushButtons(
6776
$order = $context->getCreditmemo()->getOrder();
6877
}
6978
if ($order) {
70-
if ($this->isAllowed()) {
79+
80+
$isAllowed = $this->authorization->isAllowed('Magento_LoginAsCustomer::login_button');
81+
$isEnabled = $this->config->isEnabled();
82+
if ($isAllowed && $isEnabled) {
7183
if (!empty($order['customer_id'])) {
7284
$buttonUrl = $context->getUrl('loginascustomer/login/login', [
7385
'customer_id' => $order['customer_id']
@@ -87,14 +99,4 @@ public function beforePushButtons(
8799
}
88100
}
89101
}
90-
91-
/**
92-
* Check is allowed access
93-
*
94-
* @return bool
95-
*/
96-
private function isAllowed(): bool
97-
{
98-
return (bool)$this->authorization->isAllowed('Magento_LoginAsCustomer::login_button');
99-
}
100102
}

app/code/Magento/LoginAsCustomerUi/Ui/Customer/Component/Control/LoginAsCustomerButton.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,28 @@
88
namespace Magento\LoginAsCustomerUi\Ui\Customer\Component\Control;
99

1010
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
11+
use Magento\Framework\AuthorizationInterface;
1112
use Magento\Framework\Escaper;
1213
use Magento\Framework\Registry;
1314
use Magento\Backend\Block\Widget\Context;
1415
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
16+
use Magento\LoginAsCustomerApi\Api\ConfigInterface;
1517

1618
/**
1719
* Login As Customer button UI component.
1820
*/
1921
class LoginAsCustomerButton extends GenericButton implements ButtonProviderInterface
2022
{
2123
/**
22-
* @var \Magento\Framework\AuthorizationInterface
24+
* @var AuthorizationInterface
2325
*/
2426
private $authorization;
2527

28+
/**
29+
* @var ConfigInterface
30+
*/
31+
private $config;
32+
2633
/**
2734
* Escaper
2835
*
@@ -33,13 +40,16 @@ class LoginAsCustomerButton extends GenericButton implements ButtonProviderInter
3340
/**
3441
* @param Context $context
3542
* @param Registry $registry
43+
* @param ConfigInterface $config
3644
*/
3745
public function __construct(
3846
Context $context,
39-
Registry $registry
47+
Registry $registry,
48+
ConfigInterface $config
4049
) {
4150
parent::__construct($context, $registry);
4251
$this->authorization = $context->getAuthorization();
52+
$this->config = $config;
4353
$this->escaper = $context->getEscaper();
4454
}
4555

@@ -50,8 +60,9 @@ public function getButtonData(): array
5060
{
5161
$customerId = $this->getCustomerId();
5262
$data = [];
53-
$canModify = $customerId && $this->authorization->isAllowed('Magento_LoginAsCustomer::login_button');
54-
if ($canModify) {
63+
$isAllowed = $customerId && $this->authorization->isAllowed('Magento_LoginAsCustomer::login_button');
64+
$isEnabled = $this->config->isEnabled();
65+
if ($isAllowed && $isEnabled) {
5566
$data = [
5667
'label' => __('Login As Customer'),
5768
'class' => 'login login-button',

0 commit comments

Comments
 (0)