Skip to content

Commit 334d622

Browse files
committed
fix #99 Remove plugin account
1 parent d9fb29e commit 334d622

File tree

7 files changed

+70
-46
lines changed

7 files changed

+70
-46
lines changed

Controller/AbstractPrivacy.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,55 @@
77

88
namespace Opengento\Gdpr\Controller;
99

10-
use Magento\Customer\Controller\AccountInterface;
10+
use Magento\Customer\Model\Session;
11+
use Magento\Framework\App\RequestInterface;
12+
use Magento\Framework\App\Response\Http;
13+
use Magento\Framework\Controller\ResultFactory;
14+
use Magento\Framework\Exception\NotFoundException;
15+
use Magento\Framework\Message\ManagerInterface;
16+
use Opengento\Gdpr\Model\Config;
1117

12-
abstract class AbstractPrivacy extends AbstractAction implements AccountInterface
18+
/**
19+
* This class is introduced to handle customer authentication verification.
20+
* We can't use the default AccountInterface or AccountPlugin
21+
* as they requires the action to inherit the default Magento AbstractAction
22+
* which is deprecated and which suffer of performance issues
23+
*/
24+
abstract class AbstractPrivacy extends AbstractAction
1325
{
26+
/**
27+
* @var Session
28+
*/
29+
protected $customerSession;
30+
31+
/**
32+
* @var Http
33+
*/
34+
private $response;
35+
36+
public function __construct(
37+
RequestInterface $request,
38+
ResultFactory $resultFactory,
39+
ManagerInterface $messageManager,
40+
Config $config,
41+
Session $customerSession,
42+
Http $response
43+
) {
44+
$this->customerSession = $customerSession;
45+
$this->response = $response;
46+
parent::__construct($request, $resultFactory, $messageManager, $config);
47+
}
48+
49+
public function execute()
50+
{
51+
return $this->customerSession->authenticate() ? $this->defaultAction() : $this->response;
52+
}
53+
54+
/**
55+
* @throws NotFoundException
56+
*/
57+
private function defaultAction()
58+
{
59+
return $this->isAllowed() ? $this->executeAction() : $this->forwardNoRoute();
60+
}
1461
}

Controller/Privacy/Download.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\App\Action\HttpGetActionInterface;
1313
use Magento\Framework\App\Filesystem\DirectoryList;
1414
use Magento\Framework\App\RequestInterface;
15+
use Magento\Framework\App\Response\Http;
1516
use Magento\Framework\App\Response\Http\FileFactory;
1617
use Magento\Framework\Controller\Result\Redirect;
1718
use Magento\Framework\Controller\ResultFactory;
@@ -35,24 +36,19 @@ class Download extends AbstractPrivacy implements HttpGetActionInterface
3536
*/
3637
private $exportRepository;
3738

38-
/**
39-
* @var Session
40-
*/
41-
private $customerSession;
42-
4339
public function __construct(
4440
RequestInterface $request,
4541
ResultFactory $resultFactory,
4642
ManagerInterface $messageManager,
4743
Config $config,
44+
Http $response,
45+
Session $customerSession,
4846
FileFactory $fileFactory,
49-
ExportEntityRepositoryInterface $exportRepository,
50-
Session $customerSession
47+
ExportEntityRepositoryInterface $exportRepository
5148
) {
5249
$this->fileFactory = $fileFactory;
5350
$this->exportRepository = $exportRepository;
54-
$this->customerSession = $customerSession;
55-
parent::__construct($request, $resultFactory, $messageManager, $config);
51+
parent::__construct($request, $resultFactory, $messageManager, $config, $customerSession, $response);
5652
}
5753

5854
protected function isAllowed(): bool

Controller/Privacy/Erase.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Customer\Model\Session;
1111
use Magento\Framework\App\Action\HttpGetActionInterface;
1212
use Magento\Framework\App\RequestInterface;
13+
use Magento\Framework\App\Response\Http;
1314
use Magento\Framework\Controller\Result\Redirect;
1415
use Magento\Framework\Controller\ResultFactory;
1516
use Magento\Framework\Message\ManagerInterface;
@@ -20,11 +21,6 @@
2021

2122
class Erase extends AbstractPrivacy implements HttpGetActionInterface
2223
{
23-
/**
24-
* @var Session
25-
*/
26-
private $session;
27-
2824
/**
2925
* @var EraseEntityCheckerInterface
3026
*/
@@ -35,12 +31,12 @@ public function __construct(
3531
ResultFactory $resultFactory,
3632
ManagerInterface $messageManager,
3733
Config $config,
38-
Session $session,
34+
Session $customerSession,
35+
Http $response,
3936
EraseEntityCheckerInterface $eraseCustomerChecker
4037
) {
41-
$this->session = $session;
4238
$this->eraseCustomerChecker = $eraseCustomerChecker;
43-
parent::__construct($request, $resultFactory, $messageManager, $config);
39+
parent::__construct($request, $resultFactory, $messageManager, $config, $customerSession, $response);
4440
}
4541

4642
protected function isAllowed(): bool

Controller/Privacy/ErasePost.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Customer\Model\Session;
1313
use Magento\Framework\App\Action\HttpPostActionInterface;
1414
use Magento\Framework\App\RequestInterface;
15+
use Magento\Framework\App\Response\Http;
1516
use Magento\Framework\Controller\Result\Redirect;
1617
use Magento\Framework\Controller\ResultFactory;
1718
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
@@ -33,11 +34,6 @@ class ErasePost extends AbstractPrivacy implements HttpPostActionInterface
3334
*/
3435
private $authentication;
3536

36-
/**
37-
* @var Session
38-
*/
39-
private $customerSession;
40-
4137
/**
4238
* @var ActionInterface
4339
*/
@@ -53,16 +49,16 @@ public function __construct(
5349
ResultFactory $resultFactory,
5450
ManagerInterface $messageManager,
5551
Config $config,
56-
AuthenticationInterface $authentication,
5752
Session $customerSession,
53+
Http $response,
54+
AuthenticationInterface $authentication,
5855
ActionInterface $action,
5956
ContextBuilder $actionContextBuilder
6057
) {
6158
$this->authentication = $authentication;
62-
$this->customerSession = $customerSession;
6359
$this->action = $action;
6460
$this->actionContextBuilder = $actionContextBuilder;
65-
parent::__construct($request, $resultFactory, $messageManager, $config);
61+
parent::__construct($request, $resultFactory, $messageManager, $config, $customerSession, $response);
6662
}
6763

6864
protected function isAllowed(): bool

Controller/Privacy/Export.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Customer\Model\Session;
1212
use Magento\Framework\App\Action\HttpGetActionInterface;
1313
use Magento\Framework\App\RequestInterface;
14+
use Magento\Framework\App\Response\Http;
1415
use Magento\Framework\Controller\Result\Redirect;
1516
use Magento\Framework\Controller\ResultFactory;
1617
use Magento\Framework\Exception\AlreadyExistsException;
@@ -35,24 +36,19 @@ class Export extends AbstractPrivacy implements HttpGetActionInterface
3536
*/
3637
private $actionContextBuilder;
3738

38-
/**
39-
* @var Session
40-
*/
41-
private $customerSession;
42-
4339
public function __construct(
4440
RequestInterface $request,
4541
ResultFactory $resultFactory,
4642
ManagerInterface $messageManager,
4743
Config $config,
44+
Session $customerSession,
45+
Http $response,
4846
ActionInterface $action,
49-
ContextBuilder $actionContextBuilder,
50-
Session $customerSession
47+
ContextBuilder $actionContextBuilder
5148
) {
5249
$this->action = $action;
5350
$this->actionContextBuilder = $actionContextBuilder;
54-
$this->customerSession = $customerSession;
55-
parent::__construct($request, $resultFactory, $messageManager, $config);
51+
parent::__construct($request, $resultFactory, $messageManager, $config, $customerSession, $response);
5652
}
5753

5854
protected function isAllowed(): bool

Controller/Privacy/UndoErase.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Customer\Model\Session;
1212
use Magento\Framework\App\Action\HttpPostActionInterface;
1313
use Magento\Framework\App\RequestInterface;
14+
use Magento\Framework\App\Response\Http;
1415
use Magento\Framework\Controller\Result\Redirect;
1516
use Magento\Framework\Controller\ResultFactory;
1617
use Magento\Framework\Exception\LocalizedException;
@@ -24,11 +25,6 @@
2425

2526
class UndoErase extends AbstractPrivacy implements HttpPostActionInterface
2627
{
27-
/**
28-
* @var Session
29-
*/
30-
private $customerSession;
31-
3228
/**
3329
* @var ActionInterface
3430
*/
@@ -45,13 +41,13 @@ public function __construct(
4541
ManagerInterface $messageManager,
4642
Config $config,
4743
Session $customerSession,
44+
Http $response,
4845
ActionInterface $action,
4946
ContextBuilder $actionContextBuilder
5047
) {
51-
$this->customerSession = $customerSession;
5248
$this->action = $action;
5349
$this->actionContextBuilder = $actionContextBuilder;
54-
parent::__construct($request, $resultFactory, $messageManager, $config);
50+
parent::__construct($request, $resultFactory, $messageManager, $config, $customerSession, $response);
5551
}
5652

5753
protected function isAllowed(): bool

etc/frontend/di.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@
4040
</virtualType>
4141
<preference for="Opengento\Gdpr\Model\Action\PerformedByInterface" type="Opengento\Gdpr\Model\Action\PerformedBy\FrontUser"/>
4242
<preference for="Opengento\Gdpr\Api\EraseEntityManagementInterface" type="Opengento\Gdpr\Model\Erase\SecureEraseEntityManagement"/>
43-
<type name="Opengento\Gdpr\Controller\AbstractPrivacy">
44-
<plugin name="customer_account" type="Magento\Customer\Controller\Plugin\Account"/>
45-
</type>
4643
<type name="Opengento\Gdpr\Controller\AbstractGuest">
4744
<arguments>
4845
<argument name="orderLoader" xsi:type="object">Magento\Sales\Controller\Guest\OrderLoader</argument>

0 commit comments

Comments
 (0)