Skip to content

Commit 7e254a2

Browse files
committed
security-package/issues/123: reCAPTCHA adapters modularity
1 parent 2de6064 commit 7e254a2

File tree

100 files changed

+1638
-1237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1638
-1237
lines changed

ReCaptcha/Model/CaptchaValidator.php

-52
This file was deleted.

ReCaptcha/composer.json

-28
This file was deleted.

ReCaptcha/etc/acl.xml

-26
This file was deleted.

ReCaptcha/etc/di.xml

-13
This file was deleted.

ReCaptchaAdminUi/Model/CaptchaConfig.php

-164
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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\ReCaptchaAdminUi\Model;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\ReCaptchaUi\Model\CaptchaTypeResolverInterface;
12+
13+
/**
14+
* @inheritdoc
15+
*/
16+
class CaptchaTypeResolver implements CaptchaTypeResolverInterface
17+
{
18+
private const XML_PATH_TYPE_FOR = 'recaptcha_backend/type_for/';
19+
20+
/**
21+
* @var ScopeConfigInterface
22+
*/
23+
private $scopeConfig;
24+
25+
/**
26+
* @param ScopeConfigInterface $scopeConfig
27+
*/
28+
public function __construct(
29+
ScopeConfigInterface $scopeConfig
30+
) {
31+
$this->scopeConfig = $scopeConfig;
32+
}
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
public function getCaptchaTypeFor(string $key): ?string
38+
{
39+
$type = $this->scopeConfig->getValue(
40+
self::XML_PATH_TYPE_FOR . $key
41+
);
42+
return $type;
43+
}
44+
}

ReCaptchaVersion2Checkbox/Model/OptionSource/Size.php renamed to ReCaptchaAdminUi/Model/OptionSource.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\ReCaptchaVersion2Checkbox\Model\OptionSource;
8+
namespace Magento\ReCaptchaAdminUi\Model;
99

1010
use Magento\Framework\Data\OptionSourceInterface;
1111

1212
/**
13-
* reCAPTCHA v2 sizes
13+
* Generic class for reCAPTCHA Stores/System Configuration options
14+
* Should not use directly, only as base class for "virtual type" in DI configuration
1415
*
15-
* Extension point for adding reCAPTCHA sizes
16+
* Extension point for adding reCAPTCHA options
1617
*
1718
* @api
1819
*/
19-
class Size implements OptionSourceInterface
20+
class OptionSource implements OptionSourceInterface
2021
{
2122
/**
2223
* @var array

ReCaptchaAdminUi/composer.json

-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77
"magento/module-config": "*",
88
"magento/module-re-captcha-api": "*"
99
},
10-
"authors": [
11-
{
12-
"name": "Riccardo Tempesta",
13-
"email": "[email protected]"
14-
}
15-
],
1610
"type": "magento2-module",
1711
"license": "OSL-3.0",
1812
"autoload": {

ReCaptchaAdminUi/etc/adminhtml/di.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
10-
<preference for="Magento\ReCaptchaApi\Api\CaptchaConfigInterface"
11-
type="Magento\ReCaptchaAdminUi\Model\CaptchaConfig"/>
10+
<preference for="Magento\ReCaptchaUi\Model\CaptchaTypeResolverInterface"
11+
type="Magento\ReCaptchaAdminUi\Model\CaptchaTypeResolver"/>
1212
</config>

ReCaptchaAdminUi/etc/adminhtml/system.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<class>separator-top</class>
1818
<label>Google reCAPTCHA Admin Panel</label>
1919
<tab>security</tab>
20-
<resource>Magento_ReCaptcha::config</resource>
20+
<resource>Magento_ReCaptchaUi::config</resource>
2121

2222
<group id="type_for" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="0"
2323
showInStore="0">
@@ -30,7 +30,7 @@
3030
<class>separator-top</class>
3131
<label>Google reCAPTCHA Storefront</label>
3232
<tab>security</tab>
33-
<resource>Magento_ReCaptcha::config</resource>
33+
<resource>Magento_ReCaptchaUi::config</resource>
3434

3535
<group id="type_for" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="1"
3636
showInStore="0">

0 commit comments

Comments
 (0)