Commit b583995b authored by webchick's avatar webchick

Issue #494518 by c4doug, edrupal, Rob C, a_thakur, YesCT, mcrittenden: Added...

Issue #494518 by c4doug, edrupal, Rob C, a_thakur, YesCT, mcrittenden: Added Allow for custom user registration approval email address.
parent b1575f34
......@@ -99,4 +99,54 @@ function testUserAdmin() {
$this->assertEqual($account1->status, 1, 'User D unblocked');
$this->assertMail("to", $account1->mail, "Activation mail sent to user D");
}
/**
* Tests the alternate notification e-mail address for user mails.
*/
function testNotificationEmailAddress() {
// Test that the Notification E-mail address field is on the config page.
$admin_user = $this->drupalCreateUser(array('administer users'));
$this->drupalLogin($admin_user);
$this->drupalGet('admin/config/people/accounts');
$this->assertRaw('id="edit-mail-notification-address"', 'Notification E-mail address field exists');
$this->drupalLogout();
// Test custom user registration approval email address(es).
$config = config('user.settings');
// Allow users to register with admin approval.
$config
->set('verify_mail', TRUE)
->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)
->save();
// Set the site and notification email addresses.
$system = config('system.site');
$server_address = $this->randomName() . '@example.com';
$notify_address = $this->randomName() . '@example.com';
$system
->set('mail', $server_address)
->set('mail_notification', $notify_address)
->save();
// Register a new user account.
$edit = array();
$edit['name'] = $name = $this->randomName();
$edit['mail'] = $mail = $edit['name'] . '@example.com';
$this->drupalPost('user/register', $edit, t('Create new account'));
$subject = 'Account details for ' . $edit['name'] . ' at ' . $system->get('name') . ' (pending admin approval)';
// Ensure that admin notification mail is sent to the configured
// Notification E-mail address.
$admin_mail = $this->drupalGetMails(array(
'to' => $notify_address,
'from' => $server_address,
'subject' => $subject,
));
$this->assertTrue(count($admin_mail), 'New user mail to admin is sent to configured Notification E-mail address');
// Ensure that user notification mail is sent from the configured
// Notification E-mail address.
$user_mail = $this->drupalGetMails(array(
'to' => $edit['mail'],
'from' => $notify_address,
'subject' => $subject,
));
$this->assertTrue(count($user_mail), 'New user mail to user is sent from configured Notification E-mail address');
}
}
......@@ -394,6 +394,15 @@ function user_admin_settings($form, &$form_state) {
'#default_value' => $config->get('signatures'),
);
// Default notifications address.
$form['mail_notification_address'] = array(
'#type' => 'email',
'#title' => t('Notification e-mail address'),
'#default_value' => config('system.site')->get('mail_notification'),
'#description' => t("The e-mail address to be used as the 'from' address for all account notifications listed below. If <em>'Visitors, but administrator approval is required'</em> is selected above, a notification email will also be sent to this address for any new registrations. Leave empty to use the default system e-mail address <em>(%site-email).</em>", array('%site-email' => config('system.site')->get('mail'))),
'#maxlength' => 180,
);
$form['email'] = array(
'#type' => 'vertical_tabs',
'#title' => t('E-mails'),
......@@ -662,6 +671,9 @@ function user_admin_settings_submit($form, &$form_state) {
->set('status_canceled.body', $form_state['values']['user_mail_status_canceled_body'])
->set('status_canceled.subject', $form_state['values']['user_mail_status_canceled_subject'])
->save();
config('system.site')
->set('mail_notification', $form_state['values']['mail_notification_address'])
->save();
}
/**
......
......@@ -2417,14 +2417,21 @@ function _user_mail_notify($op, $account, $langcode = NULL) {
if ($notify || ($op != 'status_canceled' && $op != 'status_blocked')) {
$params['account'] = $account;
$langcode = $langcode ? $langcode : user_preferred_langcode($account);
$mail = drupal_mail('user', $op, $account->mail, $langcode, $params);
// Get the custom site notification email to use as the from email address
// if it has been set.
$site_mail = config('system.site')->get('mail_notification');
// If the custom site notification email has not been set, we use the site
// default for this.
if (empty($site_mail)) {
$site_mail = config('system.site')->get('mail');
}
if (empty($site_mail)) {
$site_mail = ini_get('sendmail_from');
}
$mail = drupal_mail('user', $op, $account->mail, $langcode, $params, $site_mail);
if ($op == 'register_pending_approval') {
// If a user registered requiring admin approval, notify the admin, too.
// We use the site default language for this.
$site_mail = config('system.site')->get('mail');
if (empty($site_mail)) {
$site_mail = ini_get('sendmail_from');
}
drupal_mail('user', 'register_pending_approval_admin', $site_mail, language_default()->langcode, $params);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment