Skip to content

Commit

Permalink
Fix form validator when Turnstile is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
magentix committed Apr 13, 2023
1 parent 6597597 commit 21c5450
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Config path updated
- CSP Whitelist added
- Fix form validator when Turnstile is disabled

## 100.1.1

Expand Down
11 changes: 10 additions & 1 deletion Observer/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\Session\Generic;
use Magento\Review\Controller\Product\Post as ReviewPost;
use PixelOpen\CloudflareTurnstile\Helper\Config;
use PixelOpen\CloudflareTurnstile\Model\Config\Source\Forms;
use PixelOpen\CloudflareTurnstile\Model\Validator;

Expand All @@ -47,6 +48,8 @@ class Validate implements ObserverInterface

protected Json $json;

protected Config $config;

/**
* @param ManagerInterface $messageManager
* @param Response $response
Expand All @@ -55,6 +58,7 @@ class Validate implements ObserverInterface
* @param Generic $reviewSession
* @param Validator $validator
* @param Json $json
* @param Config $config
*/
public function __construct(
ManagerInterface $messageManager,
Expand All @@ -63,7 +67,8 @@ public function __construct(
CustomerSession $customerSession,
Generic $reviewSession,
Validator $validator,
Json $json
Json $json,
Config $config
) {
$this->messageManager = $messageManager;
$this->response = $response;
Expand All @@ -72,6 +77,7 @@ public function __construct(
$this->reviewSession = $reviewSession;
$this->validator = $validator;
$this->json = $json;
$this->config = $config;
}

/**
Expand Down Expand Up @@ -130,6 +136,9 @@ public function getCfResponse(Request $request, ActionInterface $action): ?strin
*/
public function canValidate(Request $request, ActionInterface $action): bool
{
if (!$this->config->isEnabled()) {
return false;
}
if (!$request->isPost()) {
return false;
}
Expand Down

0 comments on commit 21c5450

Please sign in to comment.