From a5e26e1940a04713d2df2e9d20c66579067ba7b2 Mon Sep 17 00:00:00 2001 From: Sebastian Kull Date: Wed, 9 Mar 2022 10:30:38 +0100 Subject: [PATCH 01/24] CABPI-199: send e-mail to newly created admin user --- .../Plugin/SendAdminCreatedMailPlugin.php | 118 ++++++++++++++++++ .../AdminAdobeIms/etc/adminhtml/di.xml | 5 + app/code/Magento/AdminAdobeIms/etc/config.xml | 4 + .../AdminAdobeIms/etc/email_templates.xml | 18 +++ .../email/admin_adobe_ims_email_footer.html | 25 ++++ .../email/admin_adobe_ims_email_header.html | 59 +++++++++ .../new_admin_adobe_ims_admin_created.html | 38 ++++++ 7 files changed, 267 insertions(+) create mode 100644 app/code/Magento/AdminAdobeIms/Plugin/SendAdminCreatedMailPlugin.php create mode 100644 app/code/Magento/AdminAdobeIms/etc/email_templates.xml create mode 100644 app/code/Magento/AdminAdobeIms/view/adminhtml/email/admin_adobe_ims_email_footer.html create mode 100644 app/code/Magento/AdminAdobeIms/view/adminhtml/email/admin_adobe_ims_email_header.html create mode 100644 app/code/Magento/AdminAdobeIms/view/adminhtml/email/new_admin_adobe_ims_admin_created.html diff --git a/app/code/Magento/AdminAdobeIms/Plugin/SendAdminCreatedMailPlugin.php b/app/code/Magento/AdminAdobeIms/Plugin/SendAdminCreatedMailPlugin.php new file mode 100644 index 0000000000000..f909aa7295539 --- /dev/null +++ b/app/code/Magento/AdminAdobeIms/Plugin/SendAdminCreatedMailPlugin.php @@ -0,0 +1,118 @@ + + * @link https://www.techdivision.com/ + */ +class SendAdminCreatedMailPlugin +{ + /** + * @var TransportBuilder + */ + private TransportBuilder $transportBuilder; + + /** + * @var ConfigInterface + */ + private ConfigInterface $config; + + /** + * @var ImsConfig + */ + private ImsConfig $imsConfig; + + /** + * @var StoreManagerInterface + */ + private StoreManagerInterface $storeManager; + + /** + * @param TransportBuilder $transportBuilder + * @param ConfigInterface $config + * @param ImsConfig $imsConfig + * @param StoreManagerInterface $storeManager + */ + public function __construct( + TransportBuilder $transportBuilder, + ConfigInterface $config, + ImsConfig $imsConfig, + StoreManagerInterface $storeManager + ) { + $this->transportBuilder = $transportBuilder; + $this->config = $config; + $this->imsConfig = $imsConfig; + $this->storeManager = $storeManager; + } + + /** + * @param Notificator $subject + * @param null $result + * @param UserInterface $user + * @return void + * @throws MailException + * @throws NoSuchEntityException + */ + public function afterSendCreated(Notificator $subject, $result, UserInterface $user): void + { + if (!$this->imsConfig->enabled()) { + return; + } + + $this->sendNotificationEmail( + [ + 'user' => $user, + 'store' => $this->storeManager->getStore( + Store::DEFAULT_STORE_ID + ) + ], + $user->getEmail(), + $user->getFirstName() . ' ' . $user->getLastName() + ); + } + + /** + * Send welcome e-mail to created user. + * + * @param array $templateVars + * @param string $toEmail + * @param string $toName + * @throws MailException + * + * @return void + */ + private function sendNotificationEmail( + array $templateVars, + string $toEmail, + string $toName + ): void { + $transport = $this->transportBuilder + ->setTemplateIdentifier('admin_emails_new_user_created_template') + ->setTemplateModel(BackendTemplate::class) + ->setTemplateOptions([ + 'area' => FrontNameResolver::AREA_CODE, + 'store' => Store::DEFAULT_STORE_ID + ]) + ->setTemplateVars($templateVars) + ->setFrom( + $this->config->getValue('admin/emails/forgot_email_identity') + ) + ->addTo($toEmail, $toName) + ->getTransport(); + $transport->sendMessage(); + } +} diff --git a/app/code/Magento/AdminAdobeIms/etc/adminhtml/di.xml b/app/code/Magento/AdminAdobeIms/etc/adminhtml/di.xml index 42a6eb460c21d..4345bdf79e017 100644 --- a/app/code/Magento/AdminAdobeIms/etc/adminhtml/di.xml +++ b/app/code/Magento/AdminAdobeIms/etc/adminhtml/di.xml @@ -23,4 +23,9 @@ + + + + diff --git a/app/code/Magento/AdminAdobeIms/etc/config.xml b/app/code/Magento/AdminAdobeIms/etc/config.xml index df9c5683e2312..60788ee551f9f 100644 --- a/app/code/Magento/AdminAdobeIms/etc/config.xml +++ b/app/code/Magento/AdminAdobeIms/etc/config.xml @@ -15,6 +15,10 @@ https://ims-na1-stg1.adobelogin.com/ims/token + + admin_adobe_ims_email_header_template + admin_adobe_ims_email_footer_template + diff --git a/app/code/Magento/AdminAdobeIms/etc/email_templates.xml b/app/code/Magento/AdminAdobeIms/etc/email_templates.xml new file mode 100644 index 0000000000000..f018821683de9 --- /dev/null +++ b/app/code/Magento/AdminAdobeIms/etc/email_templates.xml @@ -0,0 +1,18 @@ + + + +