Skip to content

Commit 15fde18

Browse files
committed
Fix settings scope + notifications
1 parent 8c8db88 commit 15fde18

35 files changed

+425
-484
lines changed

Block/Adminhtml/Order/Edit/EraseButton.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

Block/Adminhtml/Order/Edit/ExportButton.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

Controller/AbstractPrivacy.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

Controller/Adminhtml/AbstractAction.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

Controller/Adminhtml/Guest/Erase.php

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,62 @@
88
namespace Opengento\Gdpr\Controller\Adminhtml\Guest;
99

1010
use Exception;
11-
use Magento\Backend\App\Action\Context;
12-
use Magento\Backend\Model\View\Result\Redirect;
11+
use Magento\Backend\Model\View\Result\RedirectFactory;
1312
use Magento\Framework\App\Action\HttpPostActionInterface;
14-
use Magento\Framework\Controller\ResultFactory;
13+
use Magento\Framework\App\RequestInterface;
14+
use Magento\Framework\App\ResponseInterface;
15+
use Magento\Framework\Controller\ResultInterface;
1516
use Magento\Framework\Exception\LocalizedException;
17+
use Magento\Framework\Exception\NoSuchEntityException;
18+
use Magento\Framework\Message\ManagerInterface;
1619
use Magento\Framework\Phrase;
20+
use Magento\Sales\Api\OrderRepositoryInterface;
21+
use Magento\Store\Model\StoreManagerInterface;
1722
use Opengento\Gdpr\Api\EraseEntityManagementInterface;
1823
use Opengento\Gdpr\Api\EraseEntityRepositoryInterface;
19-
use Opengento\Gdpr\Controller\Adminhtml\AbstractAction;
2024
use Opengento\Gdpr\Model\Config;
2125

22-
class Erase extends AbstractAction implements HttpPostActionInterface
26+
class Erase implements HttpPostActionInterface
2327
{
2428
public const ADMIN_RESOURCE = 'Opengento_Gdpr::order_erase';
2529

2630
public function __construct(
27-
Context $context,
28-
Config $config,
31+
private RequestInterface $request,
32+
private ManagerInterface $messageManager,
33+
private StoreManagerInterface $storeManager,
34+
private OrderRepositoryInterface $orderRepository,
2935
private EraseEntityManagementInterface $eraseEntityManagement,
3036
private EraseEntityRepositoryInterface $eraseEntityRepository,
31-
) {
32-
parent::__construct($context, $config);
33-
}
37+
private Config $config,
38+
private RedirectFactory $redirectFactory,
39+
) {}
3440

35-
protected function executeAction()
41+
public function execute(): ResultInterface|ResponseInterface
3642
{
3743
try {
38-
$this->eraseEntityManagement->process(
39-
$this->eraseEntityRepository->getByEntity((int)$this->getRequest()->getParam('id'), 'order')
40-
);
41-
$this->messageManager->addSuccessMessage(new Phrase('You erased the order.'));
44+
$orderId = (int)$this->request->getParam('id');
45+
if ($this->isOrderErasureEnabled($orderId)) {
46+
$this->eraseEntityManagement->process(
47+
$this->eraseEntityRepository->getByEntity($orderId, 'order')
48+
);
49+
$this->messageManager->addSuccessMessage(new Phrase('You erased the order.'));
50+
}
4251
} catch (LocalizedException $e) {
4352
$this->messageManager->addErrorMessage($e->getMessage());
4453
} catch (Exception $e) {
4554
$this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.'));
4655
}
4756

48-
/** @var Redirect $resultRedirect */
49-
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
57+
return $this->redirectFactory->create()->setPath('sales/order/index');
58+
}
5059

51-
return $resultRedirect->setPath('sales/order/index');
60+
/**
61+
* @throws NoSuchEntityException
62+
*/
63+
private function isOrderErasureEnabled(int $orderId): bool
64+
{
65+
return $this->config->isErasureEnabled(
66+
$this->storeManager->getStore($this->orderRepository->get($orderId)->getStoreId())->getWebsiteId()
67+
);
5268
}
5369
}

Controller/Adminhtml/Guest/Export.php

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,73 @@
88
namespace Opengento\Gdpr\Controller\Adminhtml\Guest;
99

1010
use Exception;
11-
use Magento\Backend\App\Action\Context;
12-
use Magento\Backend\Model\View\Result\Redirect;
11+
use Magento\Backend\Model\View\Result\RedirectFactory;
12+
use Magento\Framework\App\Action\HttpGetActionInterface;
1313
use Magento\Framework\App\Filesystem\DirectoryList;
14+
use Magento\Framework\App\RequestInterface;
1415
use Magento\Framework\App\Response\Http\FileFactory;
1516
use Magento\Framework\App\ResponseInterface;
16-
use Magento\Framework\Controller\ResultFactory;
1717
use Magento\Framework\Controller\ResultInterface;
1818
use Magento\Framework\Exception\LocalizedException;
19+
use Magento\Framework\Exception\NoSuchEntityException;
20+
use Magento\Framework\Message\ManagerInterface;
1921
use Magento\Framework\Phrase;
22+
use Magento\Sales\Api\OrderRepositoryInterface;
23+
use Magento\Store\Model\StoreManagerInterface;
2024
use Opengento\Gdpr\Api\ExportEntityManagementInterface;
2125
use Opengento\Gdpr\Api\ExportEntityRepositoryInterface;
22-
use Opengento\Gdpr\Controller\Adminhtml\AbstractAction;
2326
use Opengento\Gdpr\Model\Config;
2427

25-
class Export extends AbstractAction
28+
class Export implements HttpGetActionInterface
2629
{
2730
public const ADMIN_RESOURCE = 'Opengento_Gdpr::order_export';
2831

2932
public function __construct(
30-
Context $context,
31-
Config $config,
33+
private RequestInterface $request,
34+
private ManagerInterface $messageManager,
35+
private StoreManagerInterface $storeManager,
36+
private OrderRepositoryInterface $orderRepository,
3237
private ExportEntityManagementInterface $exportEntityManagement,
3338
private ExportEntityRepositoryInterface $exportEntityRepository,
39+
private Config $config,
40+
private RedirectFactory $redirectFactory,
3441
private FileFactory $fileFactory
35-
) {
36-
parent::__construct($context, $config);
37-
}
42+
) {}
3843

39-
protected function executeAction(): ResultInterface|ResponseInterface
44+
public function execute(): ResultInterface|ResponseInterface
4045
{
4146
try {
42-
$exportEntity = $this->exportEntityManagement->export(
43-
$this->exportEntityRepository->getByEntity((int)$this->getRequest()->getParam('id'), 'order')
44-
);
47+
$orderId = (int)$this->request->getParam('id');
48+
if ($this->isOrderExportEnabled($orderId)) {
49+
$exportEntity = $this->exportEntityManagement->export(
50+
$this->exportEntityRepository->getByEntity($orderId, 'order')
51+
);
4552

46-
return $this->fileFactory->create(
47-
'guest_privacy_data_' . $exportEntity->getEntityId() . '.zip',
48-
[
49-
'type' => 'filename',
50-
'value' => $exportEntity->getFilePath(),
51-
],
52-
DirectoryList::TMP
53-
);
53+
return $this->fileFactory->create(
54+
'guest_privacy_data_' . $exportEntity->getEntityId() . '.zip',
55+
[
56+
'type' => 'filename',
57+
'value' => $exportEntity->getFilePath(),
58+
],
59+
DirectoryList::TMP
60+
);
61+
}
5462
} catch (LocalizedException $e) {
5563
$this->messageManager->addErrorMessage($e->getMessage());
5664
} catch (Exception $e) {
5765
$this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.'));
5866
}
5967

60-
/** @var Redirect $resultRedirect */
61-
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
68+
return $this->redirectFactory->create()->setRefererOrBaseUrl();
69+
}
6270

63-
return $resultRedirect->setRefererOrBaseUrl();
71+
/**
72+
* @throws NoSuchEntityException
73+
*/
74+
private function isOrderExportEnabled(int $orderId): bool
75+
{
76+
return $this->config->isErasureEnabled(
77+
$this->storeManager->getStore($this->orderRepository->get($orderId)->getStoreId())->getWebsiteId()
78+
);
6479
}
6580
}

0 commit comments

Comments
 (0)