From c58d65e7483702c9eadfd62cc639a529cc182a07 Mon Sep 17 00:00:00 2001 From: Judx Date: Wed, 3 Jan 2024 15:29:08 +0200 Subject: [PATCH 1/3] Fixed configuration name typo --- .../Mage/Adminhtml/controllers/Permissions/UserController.php | 2 +- app/code/core/Mage/Core/etc/system.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php b/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php index c2fa224a18f..5be3c7c4a5a 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php @@ -151,7 +151,7 @@ public function saveAction() try { $model->save(); // Send notification to General and additional contacts (if declared) that a new admin user was created. - if (Mage::getStoreConfigFlag('admin/security/crate_admin_user_notification') && $isNew) { + if (Mage::getStoreConfigFlag('admin/security/create_admin_user_notification') && $isNew) { Mage::getModel('admin/user')->sendAdminNotification($model); } if ($uRoles = $this->getRequest()->getParam('roles', false)) { diff --git a/app/code/core/Mage/Core/etc/system.xml b/app/code/core/Mage/Core/etc/system.xml index 489b1e6fcf2..eecee197164 100644 --- a/app/code/core/Mage/Core/etc/system.xml +++ b/app/code/core/Mage/Core/etc/system.xml @@ -1256,7 +1256,7 @@ 0 0 - + This setting enable notification when new admin user created. select @@ -1265,7 +1265,7 @@ 1 0 0 - + The recommended value is 85, a higher value will increase the file size. You can set the value to 0 to disable image processing, but it may cause security risks. From 36b58f530f5f8ca0335e30557c619e01cfd13fd5 Mon Sep 17 00:00:00 2001 From: Judx Date: Wed, 3 Jan 2024 16:51:32 +0200 Subject: [PATCH 2/3] Add setup script and bump Mage_Core from 1.6.0.10 to 1.6.0.11 --- app/code/core/Mage/Core/etc/config.xml | 2 +- .../core_setup/upgrade-1.6.0.10-1.6.0.11.php | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 app/code/core/Mage/Core/sql/core_setup/upgrade-1.6.0.10-1.6.0.11.php diff --git a/app/code/core/Mage/Core/etc/config.xml b/app/code/core/Mage/Core/etc/config.xml index d7ce041219d..3673dd77475 100644 --- a/app/code/core/Mage/Core/etc/config.xml +++ b/app/code/core/Mage/Core/etc/config.xml @@ -17,7 +17,7 @@ - 1.6.0.10 + 1.6.0.11 diff --git a/app/code/core/Mage/Core/sql/core_setup/upgrade-1.6.0.10-1.6.0.11.php b/app/code/core/Mage/Core/sql/core_setup/upgrade-1.6.0.10-1.6.0.11.php new file mode 100644 index 00000000000..995c66eff9f --- /dev/null +++ b/app/code/core/Mage/Core/sql/core_setup/upgrade-1.6.0.10-1.6.0.11.php @@ -0,0 +1,41 @@ +startSetup(); + +$table = $installer->getTable('core/config_data'); + +if ($installer->getConnection()->isTableExists($table)) { + $oldPath = 'admin/security/crate_admin_user_notification'; + $newPath = 'admin/security/create_admin_user_notification'; + + $select = $installer->getConnection()->select() + ->from($table, ['config_id', 'path']) + ->where('path = ?', $oldPath); + + $rows = $installer->getConnection()->fetchAll($select); + + foreach ($rows as $row) { + $installer->getConnection()->update( + $table, + ['path' => $newPath], + ['config_id = ?' => $row['config_id']] + ); + } +} + +$installer->endSetup(); From 82c342362a1530412c5f8fece150e25ef5c74a08 Mon Sep 17 00:00:00 2001 From: Judx Date: Wed, 3 Jan 2024 17:28:09 +0200 Subject: [PATCH 3/3] set receiver email to new admin user create notification --- app/code/core/Mage/Admin/Model/User.php | 12 ++++--- .../Config/Backend/Email/Addressorempty.php | 32 +++++++++++++++++++ .../Permissions/UserController.php | 3 +- app/code/core/Mage/Core/etc/system.xml | 14 +++++++- 4 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Email/Addressorempty.php diff --git a/app/code/core/Mage/Admin/Model/User.php b/app/code/core/Mage/Admin/Model/User.php index b10e26a982f..ea19bfd9e31 100644 --- a/app/code/core/Mage/Admin/Model/User.php +++ b/app/code/core/Mage/Admin/Model/User.php @@ -733,17 +733,21 @@ protected function _getDateNow($dayOnly = false) * You can declare additional emails in Mage_Core general/additional_notification_emails/admin_user_create node. * * @param Mage_Admin_Model_User $user + * @param string|false $receiverEmail An optional receiver email address for the notification. Overrides default and additional emails. * @return $this */ - public function sendAdminNotification($user) + public function sendAdminNotification($user, $receiverEmail = false) { // define general contact Name and Email $generalContactName = Mage::getStoreConfig('trans_email/ident_general/name'); $generalContactEmail = Mage::getStoreConfig('trans_email/ident_general/email'); - // collect general and additional emails - $emails = $this->getUserCreateAdditionalEmail(); - $emails[] = $generalContactEmail; + // collect general and additional emails unless overridden + if ($receiverEmail && filter_var($receiverEmail, FILTER_VALIDATE_EMAIL)) { + $emails = [$receiverEmail]; + } else { + $emails = array_merge($this->getUserCreateAdditionalEmail(), [$generalContactEmail]); + } /** @var Mage_Core_Model_Email_Template_Mailer $mailer */ $mailer = Mage::getModel('core/email_template_mailer'); diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Email/Addressorempty.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Email/Addressorempty.php new file mode 100644 index 00000000000..8364dce4e60 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Email/Addressorempty.php @@ -0,0 +1,32 @@ +getValue(); + if ($value && !Zend_Validate::is($value, 'EmailAddress')) { + Mage::throwException(Mage::helper('adminhtml')->__('Invalid email address "%s".', $value)); + } + return $this; + } +} diff --git a/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php b/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php index 5be3c7c4a5a..a15d01487d4 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php @@ -152,7 +152,8 @@ public function saveAction() $model->save(); // Send notification to General and additional contacts (if declared) that a new admin user was created. if (Mage::getStoreConfigFlag('admin/security/create_admin_user_notification') && $isNew) { - Mage::getModel('admin/user')->sendAdminNotification($model); + $contactEmail = Mage::getStoreConfig('admin/security/create_admin_user_notification_email'); + Mage::getModel('admin/user')->sendAdminNotification($model, $contactEmail); } if ($uRoles = $this->getRequest()->getParam('roles', false)) { if (is_array($uRoles) && (count($uRoles) >= 1)) { diff --git a/app/code/core/Mage/Core/etc/system.xml b/app/code/core/Mage/Core/etc/system.xml index eecee197164..e46355cfc89 100644 --- a/app/code/core/Mage/Core/etc/system.xml +++ b/app/code/core/Mage/Core/etc/system.xml @@ -1258,7 +1258,7 @@ - This setting enable notification when new admin user created. + This setting enables notification when new admin user is created. select 10 adminhtml/system_config_source_enabledisable @@ -1266,6 +1266,18 @@ 0 0 + + + Email address to receive notifications when a new admin user is created. Defaults to the General Store email address if empty. + 1 + text + validate-email + adminhtml/system_config_backend_email_addressorempty + 11 + 1 + 0 + 0 + The recommended value is 85, a higher value will increase the file size. You can set the value to 0 to disable image processing, but it may cause security risks.