From ebabae0f622c7e655c0432e18b9b87d0687bc834 Mon Sep 17 00:00:00 2001 From: kpitn Date: Tue, 20 Aug 2024 17:38:46 +0200 Subject: [PATCH 1/3] add missing delay variable in email --- Model/Customer/Notifier/MailSender.php | 5 +++++ Model/EraseEntityManagement.php | 2 +- view/frontend/email/erase_pending.html | 2 +- view/frontend/email/erase_pending_guest.html | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Model/Customer/Notifier/MailSender.php b/Model/Customer/Notifier/MailSender.php index 63564d7..74e3c16 100644 --- a/Model/Customer/Notifier/MailSender.php +++ b/Model/Customer/Notifier/MailSender.php @@ -15,6 +15,7 @@ use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Mail\Template\TransportBuilder; use Magento\Store\Model\StoreManagerInterface; +use Opengento\Gdpr\Model\EraseEntityManagement; use Opengento\Gdpr\Model\Notifier\AbstractMailSender; class MailSender extends AbstractMailSender implements SenderInterface @@ -24,6 +25,7 @@ class MailSender extends AbstractMailSender implements SenderInterface private StoreManagerInterface $storeManager; public function __construct( + protected EraseEntityManagement $entityManagement, View $customerViewHelper, TransportBuilder $transportBuilder, ScopeConfigInterface $scopeConfig, @@ -42,8 +44,11 @@ public function __construct( */ public function send(CustomerInterface $customer): void { + $delay = $this->entityManagement->resolveErasureDelay(); + $storeId = $customer->getStoreId() === null ? null : (int)$customer->getStoreId(); $vars = [ + 'delay' => $delay !== 0 ? $delay / 60 : 0, 'customer' => $customer, 'store' => $this->storeManager->getStore($customer->getStoreId()), 'customer_data' => [ diff --git a/Model/EraseEntityManagement.php b/Model/EraseEntityManagement.php index 18b5daa..f44ed74 100644 --- a/Model/EraseEntityManagement.php +++ b/Model/EraseEntityManagement.php @@ -98,7 +98,7 @@ private function retrieveScheduledAt(): string ); } - private function resolveErasureDelay(): int + public function resolveErasureDelay(): int { return (int)$this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_DELAY); } diff --git a/view/frontend/email/erase_pending.html b/view/frontend/email/erase_pending.html index a526e4d..3694748 100644 --- a/view/frontend/email/erase_pending.html +++ b/view/frontend/email/erase_pending.html @@ -19,7 +19,7 @@

{{trans "We have received a request to erase the information associated with your account at %store_name." store_name=$store.getFrontendName()}}

-

{{trans 'You can cancel the erase within %delay hours by logging into your account.' account_url=$this.getUrl($store,'customer/account/',[_nosid:1]) |raw}}

+

{{trans 'You can cancel the erase within %delay hours by logging into your account.' delay=$delay account_url=$this.getUrl($store,'customer/account/',[_nosid:1]) |raw}}

diff --git a/view/frontend/email/erase_pending_guest.html b/view/frontend/email/erase_pending_guest.html index e5d34c3..62350fb 100644 --- a/view/frontend/email/erase_pending_guest.html +++ b/view/frontend/email/erase_pending_guest.html @@ -19,7 +19,7 @@

{{trans "We have received a request to erase the information associated with your account at %store_name." store_name=$store.getFrontendName()}}

-

{{trans 'You can cancel the erase within %delay hours by logging into your account.' account_url=$this.getUrl($store,'customer/account/',[_nosid:1]) |raw}}

+

{{trans 'You can cancel the erase within %delay hours by logging into your account.' delay=$delay account_url=$this.getUrl($store,'customer/account/',[_nosid:1]) |raw}}

From 2234a18c6fbd505f603f111fb70b03145661c419 Mon Sep 17 00:00:00 2001 From: kpitn Date: Thu, 22 Aug 2024 09:16:54 +0200 Subject: [PATCH 2/3] refactoring get erasure delay --- Model/Config/Entity/Erasure.php | 15 +++++++++++++++ Model/Customer/Notifier/MailSender.php | 16 +++++----------- Model/EraseEntityManagement.php | 11 +++-------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Model/Config/Entity/Erasure.php b/Model/Config/Entity/Erasure.php index e651df0..57f98a7 100644 --- a/Model/Config/Entity/Erasure.php +++ b/Model/Config/Entity/Erasure.php @@ -18,6 +18,7 @@ class Erasure { private const CONFIG_PATH_ERASURE_MAX_AGE = 'gdpr/erasure/entity_max_age'; private const CONFIG_PATH_ERASURE_ALLOWED_STATES = 'gdpr/erasure/allowed_states'; + private const CONFIG_PATH_ERASURE_DELAY = 'gdpr/erasure/delay'; public function __construct( private ScopeConfigInterface $scopeConfig @@ -51,4 +52,18 @@ public function getAllowedStatesToErase(int|string|null $website = null): array $website )); } + + /** + * @param int|string|null $website + * + * @return int + */ + public function getDelay(int|string|null $website = null): int + { + return (int)$this->scopeConfig->getValue( + self::CONFIG_PATH_ERASURE_DELAY, + ScopeInterface::SCOPE_WEBSITE, + $website + ); + } } diff --git a/Model/Customer/Notifier/MailSender.php b/Model/Customer/Notifier/MailSender.php index 74e3c16..6aa4bd0 100644 --- a/Model/Customer/Notifier/MailSender.php +++ b/Model/Customer/Notifier/MailSender.php @@ -15,25 +15,19 @@ use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Mail\Template\TransportBuilder; use Magento\Store\Model\StoreManagerInterface; -use Opengento\Gdpr\Model\EraseEntityManagement; +use Opengento\Gdpr\Model\Config\Entity\Erasure; use Opengento\Gdpr\Model\Notifier\AbstractMailSender; class MailSender extends AbstractMailSender implements SenderInterface { - private View $customerViewHelper; - - private StoreManagerInterface $storeManager; - public function __construct( - protected EraseEntityManagement $entityManagement, - View $customerViewHelper, + private Erasure $erasureConfig, + private View $customerViewHelper, + private StoreManagerInterface $storeManager, TransportBuilder $transportBuilder, ScopeConfigInterface $scopeConfig, - StoreManagerInterface $storeManager, array $configPaths ) { - $this->customerViewHelper = $customerViewHelper; - $this->storeManager = $storeManager; parent::__construct($transportBuilder, $scopeConfig, $configPaths); } @@ -44,7 +38,7 @@ public function __construct( */ public function send(CustomerInterface $customer): void { - $delay = $this->entityManagement->resolveErasureDelay(); + $delay = $this->erasureConfig->getDelay(); $storeId = $customer->getStoreId() === null ? null : (int)$customer->getStoreId(); $vars = [ diff --git a/Model/EraseEntityManagement.php b/Model/EraseEntityManagement.php index f44ed74..f66bccf 100644 --- a/Model/EraseEntityManagement.php +++ b/Model/EraseEntityManagement.php @@ -18,13 +18,13 @@ use Opengento\Gdpr\Api\Data\EraseEntityInterfaceFactory; use Opengento\Gdpr\Api\EraseEntityManagementInterface; use Opengento\Gdpr\Api\EraseEntityRepositoryInterface; +use Opengento\Gdpr\Model\Config\Entity\Erasure; use Opengento\Gdpr\Service\Erase\ProcessorFactory; class EraseEntityManagement implements EraseEntityManagementInterface { - private const CONFIG_PATH_ERASURE_DELAY = 'gdpr/erasure/delay'; - public function __construct( + private Erasure $erasureConfig, private EraseEntityInterfaceFactory $eraseEntityFactory, private EraseEntityRepositoryInterface $eraseRepository, private ProcessorFactory $processorFactory, @@ -94,12 +94,7 @@ private function retrieveScheduledAt(): string { return $this->localeDate->gmtDate( DateTimeFormat::DATETIME_PHP_FORMAT, - $this->resolveErasureDelay() * 60 + $this->localeDate->gmtTimestamp() + $this->erasureConfig->getDelay() * 60 + $this->localeDate->gmtTimestamp() ); } - - public function resolveErasureDelay(): int - { - return (int)$this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_DELAY); - } } From 6e30512eab09b87ca2a3c04a853119b3304a098a Mon Sep 17 00:00:00 2001 From: kpitn Date: Thu, 22 Aug 2024 12:02:27 +0200 Subject: [PATCH 3/3] remove website parameter for getdelay function --- Model/Config/Entity/Erasure.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Model/Config/Entity/Erasure.php b/Model/Config/Entity/Erasure.php index 57f98a7..eb216d6 100644 --- a/Model/Config/Entity/Erasure.php +++ b/Model/Config/Entity/Erasure.php @@ -54,16 +54,10 @@ public function getAllowedStatesToErase(int|string|null $website = null): array } /** - * @param int|string|null $website - * * @return int */ - public function getDelay(int|string|null $website = null): int + public function getDelay(): int { - return (int)$this->scopeConfig->getValue( - self::CONFIG_PATH_ERASURE_DELAY, - ScopeInterface::SCOPE_WEBSITE, - $website - ); + return (int)$this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_DELAY, ScopeInterface::SCOPE_WEBSITE); } }