Skip to content

Commit 0be532e

Browse files
Merge pull request #79 from magento-cia/2.4.5-develop-2.4-develop-sync-05312022
Sync of 2.4.5-develop with 2.4-develop
2 parents aa9db55 + b1b9e3b commit 0be532e

File tree

5 files changed

+120
-1
lines changed

5 files changed

+120
-1
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ReCaptchaCustomer\Plugin\Customer;
9+
10+
use Magento\Framework\Exception\InputException;
11+
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
12+
use Magento\Customer\ViewModel\ForgotPasswordButton;
13+
14+
/**
15+
* Disable Forgot password button while captcha is loading
16+
*/
17+
class DisableForgotPasswordButton
18+
{
19+
/**
20+
* @var IsCaptchaEnabledInterface
21+
*/
22+
private $isCaptchaEnabled;
23+
24+
/**
25+
* @param IsCaptchaEnabledInterface $isCaptchaEnabled
26+
*/
27+
public function __construct(
28+
IsCaptchaEnabledInterface $isCaptchaEnabled
29+
) {
30+
$this->isCaptchaEnabled = $isCaptchaEnabled;
31+
}
32+
33+
/**
34+
* Temporally disable Forgot password button while captcha is loading
35+
*
36+
* @param ForgotPasswordButton $subject
37+
* @return bool
38+
* @throws InputException
39+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
40+
*/
41+
public function afterDisabled(ForgotPasswordButton $subject): bool
42+
{
43+
$key = 'customer_forgot_password';
44+
return $this->isCaptchaEnabled->isCaptchaEnabledFor($key);
45+
}
46+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ReCaptchaCustomer\Test\Unit\Plugin\Customer;
9+
10+
use Magento\Customer\ViewModel\ForgotPasswordButton;
11+
use Magento\ReCaptchaCustomer\Plugin\Customer\DisableForgotPasswordButton;
12+
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Test disable Forgot password button while captcha is loading
18+
*/
19+
class DisableForgotPasswordButtonTest extends TestCase
20+
{
21+
/**
22+
* @var IsCaptchaEnabledInterface|MockObject
23+
*/
24+
protected $isCaptchaEnabled;
25+
26+
/**
27+
* @var ForgotPasswordButton|MockObject
28+
*/
29+
protected $subject;
30+
31+
/**
32+
* @var DisableForgotPasswordButton
33+
*/
34+
protected $plugin;
35+
36+
protected function setUp(): void
37+
{
38+
$this->isCaptchaEnabled = $this->getMockForAbstractClass(
39+
IsCaptchaEnabledInterface::class
40+
);
41+
$this->subject = $this->createMock(ForgotPasswordButton::class);
42+
43+
$this->plugin = new DisableForgotPasswordButton(
44+
$this->isCaptchaEnabled
45+
);
46+
}
47+
48+
public function testAfterEnabled()
49+
{
50+
$key = 'customer_forgot_password';
51+
$this->isCaptchaEnabled->expects($this->once())
52+
->method('isCaptchaEnabledFor')->with($key)->willReturn(true);
53+
$this->assertEquals(true, $this->plugin->afterDisabled($this->subject));
54+
}
55+
}

ReCaptchaCustomer/etc/frontend/di.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@
2828
<plugin sortOrder="1" name="recaptcha_disable_create_account_button"
2929
type="Magento\ReCaptchaCustomer\Plugin\Customer\DisableCreateAccountButton"/>
3030
</type>
31+
<type name="Magento\Customer\ViewModel\ForgotPasswordButton">
32+
<plugin sortOrder="1" name="recaptcha_disable_forgot_password_button"
33+
type="Magento\ReCaptchaCustomer\Plugin\Customer\DisableForgotPasswordButton"/>
34+
</type>
3135
</config>

TwoFactorAuth/Observer/ControllerActionPredispatch.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Magento\TwoFactorAuth\Api\UserConfigRequestManagerInterface;
2323
use Magento\TwoFactorAuth\Controller\Adminhtml\Tfa\Requestconfig;
2424
use Magento\TwoFactorAuth\Model\UserConfig\HtmlAreaTokenVerifier;
25+
use Magento\AdminAdobeIms\Service\ImsConfig;
2526

2627
/**
2728
* Handle redirection to 2FA page if required
@@ -75,6 +76,11 @@ class ControllerActionPredispatch implements ObserverInterface
7576
*/
7677
private $userContext;
7778

79+
/**
80+
* @var ImsConfig
81+
*/
82+
private ImsConfig $adminAdobeImsConfig;
83+
7884
/**
7985
* @param TfaInterface $tfa
8086
* @param TfaSessionInterface $tfaSession
@@ -84,6 +90,7 @@ class ControllerActionPredispatch implements ObserverInterface
8490
* @param UrlInterface $url
8591
* @param AuthorizationInterface $authorization
8692
* @param UserContextInterface $userContext
93+
* @param ImsConfig $adminAdobeImsConfig
8794
*/
8895
public function __construct(
8996
TfaInterface $tfa,
@@ -93,7 +100,8 @@ public function __construct(
93100
ActionFlag $actionFlag,
94101
UrlInterface $url,
95102
AuthorizationInterface $authorization,
96-
UserContextInterface $userContext
103+
UserContextInterface $userContext,
104+
ImsConfig $adminAdobeImsConfig
97105
) {
98106
$this->tfa = $tfa;
99107
$this->tfaSession = $tfaSession;
@@ -103,6 +111,7 @@ public function __construct(
103111
$this->url = $url;
104112
$this->authorization = $authorization;
105113
$this->userContext = $userContext;
114+
$this->adminAdobeImsConfig = $adminAdobeImsConfig;
106115
}
107116

108117
/**
@@ -119,9 +128,13 @@ private function redirect(string $url): void
119128

120129
/**
121130
* @inheritDoc
131+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
122132
*/
123133
public function execute(Observer $observer)
124134
{
135+
if ($this->adminAdobeImsConfig->enabled()) {
136+
return;
137+
}
125138
/** @var $controllerAction AbstractAction */
126139
$controllerAction = $observer->getEvent()->getData('controller_action');
127140
$this->action = $controllerAction;

TwoFactorAuth/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"magento/module-ui": "*",
1313
"magento/module-user": "*",
1414
"magento/module-integration": "*",
15+
"magento/module-admin-adobe-ims": "*",
1516
"christian-riesen/base32": "^1.3",
1617
"spomky-labs/otphp": "^10.0",
1718
"endroid/qr-code": "^4.3.5",

0 commit comments

Comments
 (0)