Skip to content

Commit

Permalink
Fix settings scope + notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Aug 4, 2024
1 parent 8c8db88 commit 15fde18
Show file tree
Hide file tree
Showing 35 changed files with 425 additions and 484 deletions.
56 changes: 0 additions & 56 deletions Block/Adminhtml/Order/Edit/EraseButton.php

This file was deleted.

40 changes: 0 additions & 40 deletions Block/Adminhtml/Order/Edit/ExportButton.php

This file was deleted.

56 changes: 0 additions & 56 deletions Controller/AbstractPrivacy.php

This file was deleted.

56 changes: 0 additions & 56 deletions Controller/Adminhtml/AbstractAction.php

This file was deleted.

52 changes: 34 additions & 18 deletions Controller/Adminhtml/Guest/Erase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,62 @@
namespace Opengento\Gdpr\Controller\Adminhtml\Guest;

use Exception;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\View\Result\Redirect;
use Magento\Backend\Model\View\Result\RedirectFactory;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\Phrase;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Store\Model\StoreManagerInterface;
use Opengento\Gdpr\Api\EraseEntityManagementInterface;
use Opengento\Gdpr\Api\EraseEntityRepositoryInterface;
use Opengento\Gdpr\Controller\Adminhtml\AbstractAction;
use Opengento\Gdpr\Model\Config;

class Erase extends AbstractAction implements HttpPostActionInterface
class Erase implements HttpPostActionInterface
{
public const ADMIN_RESOURCE = 'Opengento_Gdpr::order_erase';

public function __construct(
Context $context,
Config $config,
private RequestInterface $request,

Check failure on line 31 in Controller/Adminhtml/Guest/Erase.php

View workflow job for this annotation

GitHub Actions / M2 Coding Standard

PHP syntax error: syntax error, unexpected 'private' (T_PRIVATE), expecting variable (T_VARIABLE)
private ManagerInterface $messageManager,
private StoreManagerInterface $storeManager,
private OrderRepositoryInterface $orderRepository,
private EraseEntityManagementInterface $eraseEntityManagement,
private EraseEntityRepositoryInterface $eraseEntityRepository,
) {
parent::__construct($context, $config);
}
private Config $config,
private RedirectFactory $redirectFactory,
) {}

protected function executeAction()
public function execute(): ResultInterface|ResponseInterface
{
try {
$this->eraseEntityManagement->process(
$this->eraseEntityRepository->getByEntity((int)$this->getRequest()->getParam('id'), 'order')
);
$this->messageManager->addSuccessMessage(new Phrase('You erased the order.'));
$orderId = (int)$this->request->getParam('id');
if ($this->isOrderErasureEnabled($orderId)) {
$this->eraseEntityManagement->process(
$this->eraseEntityRepository->getByEntity($orderId, 'order')
);
$this->messageManager->addSuccessMessage(new Phrase('You erased the order.'));
}
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (Exception $e) {
$this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.'));
}

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

return $resultRedirect->setPath('sales/order/index');
/**
* @throws NoSuchEntityException
*/
private function isOrderErasureEnabled(int $orderId): bool
{
return $this->config->isErasureEnabled(
$this->storeManager->getStore($this->orderRepository->get($orderId)->getStoreId())->getWebsiteId()
);
}
}
65 changes: 40 additions & 25 deletions Controller/Adminhtml/Guest/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,73 @@
namespace Opengento\Gdpr\Controller\Adminhtml\Guest;

use Exception;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\View\Result\Redirect;
use Magento\Backend\Model\View\Result\RedirectFactory;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\Response\Http\FileFactory;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\Phrase;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Store\Model\StoreManagerInterface;
use Opengento\Gdpr\Api\ExportEntityManagementInterface;
use Opengento\Gdpr\Api\ExportEntityRepositoryInterface;
use Opengento\Gdpr\Controller\Adminhtml\AbstractAction;
use Opengento\Gdpr\Model\Config;

class Export extends AbstractAction
class Export implements HttpGetActionInterface
{
public const ADMIN_RESOURCE = 'Opengento_Gdpr::order_export';

public function __construct(

Check warning on line 32 in Controller/Adminhtml/Guest/Export.php

View workflow job for this annotation

GitHub Actions / M2 Coding Standard

Empty FUNCTION statement detected
Context $context,
Config $config,
private RequestInterface $request,

Check failure on line 33 in Controller/Adminhtml/Guest/Export.php

View workflow job for this annotation

GitHub Actions / M2 Coding Standard

PHP syntax error: syntax error, unexpected 'private' (T_PRIVATE), expecting variable (T_VARIABLE)

Check warning on line 33 in Controller/Adminhtml/Guest/Export.php

View workflow job for this annotation

GitHub Actions / M2 Coding Standard

Line indented incorrectly; expected 4 spaces, found 8
private ManagerInterface $messageManager,

Check warning on line 34 in Controller/Adminhtml/Guest/Export.php

View workflow job for this annotation

GitHub Actions / M2 Coding Standard

Line indented incorrectly; expected 4 spaces, found 8
private StoreManagerInterface $storeManager,

Check warning on line 35 in Controller/Adminhtml/Guest/Export.php

View workflow job for this annotation

GitHub Actions / M2 Coding Standard

Line indented incorrectly; expected 4 spaces, found 8
private OrderRepositoryInterface $orderRepository,

Check warning on line 36 in Controller/Adminhtml/Guest/Export.php

View workflow job for this annotation

GitHub Actions / M2 Coding Standard

Line indented incorrectly; expected 4 spaces, found 8
private ExportEntityManagementInterface $exportEntityManagement,

Check warning on line 37 in Controller/Adminhtml/Guest/Export.php

View workflow job for this annotation

GitHub Actions / M2 Coding Standard

Line indented incorrectly; expected 4 spaces, found 8
private ExportEntityRepositoryInterface $exportEntityRepository,

Check warning on line 38 in Controller/Adminhtml/Guest/Export.php

View workflow job for this annotation

GitHub Actions / M2 Coding Standard

Line indented incorrectly; expected 4 spaces, found 8
private Config $config,

Check warning on line 39 in Controller/Adminhtml/Guest/Export.php

View workflow job for this annotation

GitHub Actions / M2 Coding Standard

Line indented incorrectly; expected 4 spaces, found 8
private RedirectFactory $redirectFactory,

Check warning on line 40 in Controller/Adminhtml/Guest/Export.php

View workflow job for this annotation

GitHub Actions / M2 Coding Standard

Line indented incorrectly; expected 4 spaces, found 8
private FileFactory $fileFactory

Check warning on line 41 in Controller/Adminhtml/Guest/Export.php

View workflow job for this annotation

GitHub Actions / M2 Coding Standard

Line indented incorrectly; expected 4 spaces, found 8
) {
parent::__construct($context, $config);
}
) {}

protected function executeAction(): ResultInterface|ResponseInterface
public function execute(): ResultInterface|ResponseInterface
{
try {
$exportEntity = $this->exportEntityManagement->export(
$this->exportEntityRepository->getByEntity((int)$this->getRequest()->getParam('id'), 'order')
);
$orderId = (int)$this->request->getParam('id');
if ($this->isOrderExportEnabled($orderId)) {
$exportEntity = $this->exportEntityManagement->export(
$this->exportEntityRepository->getByEntity($orderId, 'order')
);

return $this->fileFactory->create(
'guest_privacy_data_' . $exportEntity->getEntityId() . '.zip',
[
'type' => 'filename',
'value' => $exportEntity->getFilePath(),
],
DirectoryList::TMP
);
return $this->fileFactory->create(
'guest_privacy_data_' . $exportEntity->getEntityId() . '.zip',
[
'type' => 'filename',
'value' => $exportEntity->getFilePath(),
],
DirectoryList::TMP
);
}
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (Exception $e) {
$this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.'));
}

/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $this->redirectFactory->create()->setRefererOrBaseUrl();
}

return $resultRedirect->setRefererOrBaseUrl();
/**
* @throws NoSuchEntityException
*/
private function isOrderExportEnabled(int $orderId): bool
{
return $this->config->isErasureEnabled(
$this->storeManager->getStore($this->orderRepository->get($orderId)->getStoreId())->getWebsiteId()
);
}
}
Loading

0 comments on commit 15fde18

Please sign in to comment.