Browse files

MDL-29615 message: added the ability for admins to restrict users abi…

…lity to set where their email message notifications go
  • Loading branch information...
1 parent 216f6d8 commit 84f533b3c34071376775e27a7e2f48b85cabf222 @andyjdavis andyjdavis committed Jan 23, 2012
View
4 admin/settings/subsystems.php
@@ -20,6 +20,8 @@
$options = array(DAYSECS=>new lang_string('secondstotime86400'), WEEKSECS=>new lang_string('secondstotime604800'), 2620800=>new lang_string('nummonths', 'moodle', 1), 15724800=>new lang_string('nummonths', 'moodle', 6),0=>new lang_string('never'));
$optionalsubsystems->add(new admin_setting_configselect('messagingdeletereadnotificationsdelay', new lang_string('messagingdeletereadnotificationsdelay', 'admin'), new lang_string('configmessagingdeletereadnotificationsdelay', 'admin'), 604800, $options));
+ $optionalsubsystems->add(new admin_setting_configcheckbox('messagingallowemailoverride', new lang_string('messagingallowemailoverride', 'admin'), new lang_string('configmessagingallowemailoverride','admin'), 1));
+
$optionalsubsystems->add(new admin_setting_configcheckbox('enablestats', new lang_string('enablestats', 'admin'), new lang_string('configenablestats', 'admin'), 0));
$optionalsubsystems->add(new admin_setting_configcheckbox('enablerssfeeds', new lang_string('enablerssfeeds', 'admin'), new lang_string('configenablerssfeeds', 'admin'), 0));
@@ -45,4 +47,4 @@
$optionalsubsystems->add(new admin_setting_configcheckbox('enableplagiarism', new lang_string('enableplagiarism','plagiarism'), new lang_string('configenableplagiarism','plagiarism'), 0));
$optionalsubsystems->add(new admin_setting_configcheckbox('enablecssoptimiser', new lang_string('enablecssoptimiser','admin'), new lang_string('enablecssoptimiser_desc','admin'), 0));
-}
+}
View
2 lang/en/admin.php
@@ -242,6 +242,7 @@
$string['configmemcachedhosts'] = 'For memcached. Comma-separated list of hosts that are running the memcached daemon. Use IP addresses to avoid DNS latency. memcached does not behave well if you add/remove hosts on a running setup.';
$string['configmemcachedpconn'] = 'For memcached. Use persistent connections. Use carefully -- it can make Apache/PHP crash after a restart of the memcached daemon.';
$string['configmessaging'] = 'Should the messaging system between site users be enabled?';
+$string['configmessagingallowemailoverride'] = 'Allow users to have email message notifications sent to an email address other than the email address in their profile';
$string['configmessaginghidereadnotifications'] = 'Hide read notifications of events like forum posts when viewing messaging history';
$string['configmessagingdeletereadnotificationsdelay'] = 'Read notifications can be deleted to save space. How long after a notification is read can it be deleted?';
$string['configminpassworddigits'] = 'Passwords must have at least these many digits.';
@@ -662,6 +663,7 @@
$string['memcachedhosts'] = 'memcached hosts';
$string['memcachedpconn'] = 'memcached use persistent connections';
$string['messaging'] = 'Enable messaging system';
+$string['messagingallowemailoverride'] = 'Notification email override';
$string['messaginghidereadnotifications'] = 'Hide read notifications';
$string['messagingdeletereadnotificationsdelay'] = 'Delete read notifications';
$string['minpassworddigits'] = 'Digits';
View
1 message/output/email/lang/en/message_email.php
@@ -32,6 +32,7 @@
$string['configsmtpmaxbulk'] = 'Maximum number of messages sent per SMTP session. Grouping messages may speed up the sending of emails. Values lower than 2 force creation of new SMTP session for each email.';
$string['configsmtpuser'] = 'If you have specified an SMTP server above, and the server requires authentication, then enter the username and password here.';
$string['email'] = 'Send email notifications to';
+$string['ifemailleftempty'] = 'Leave empty to send notifications to {$a}';
$string['mailnewline'] = 'Newline characters in mail';
$string['noreplyaddress'] = 'No-reply address';
$string['pluginname'] = 'Email';
View
13 message/output/email/message_output_email.php
@@ -57,7 +57,10 @@ function send_message($eventdata) {
//check if the recipient has a different email address specified in their messaging preferences Vs their user profile
$emailmessagingpreference = get_user_preferences('message_processor_email_email', null, $eventdata->userto);
$emailmessagingpreference = clean_param($emailmessagingpreference, PARAM_EMAIL);
- if (!empty($emailmessagingpreference)) {
+
+ // If the recipient has set an email address in their preferences use that instead of the one in their profile
+ // but only if overriding the notification email address is allowed
+ if (!empty($emailmessagingpreference) && !empty($CFG->messagingallowemailoverride)) {
//clone to avoid altering the actual user object
$recipient = clone($eventdata->userto);
$recipient->email = $emailmessagingpreference;
@@ -74,13 +77,17 @@ function send_message($eventdata) {
* @param object $mform preferences form class
*/
function config_form($preferences){
- global $USER, $OUTPUT;
+ global $USER, $OUTPUT, $CFG;
+
+ if (empty($CFG->messagingallowemailoverride)) {
+ return null;
+ }
$inputattributes = array('size'=>'30', 'name'=>'email_email', 'value'=>$preferences->email_email);
$string = get_string('email','message_email') . ': ' . html_writer::empty_tag('input', $inputattributes);
if (empty($preferences->email_email) && !empty($preferences->userdefaultemail)) {
- $string .= ' ('.get_string('default').': '.s($preferences->userdefaultemail).')';
+ $string .= get_string('ifemailleftempty', 'message_email', $preferences->userdefaultemail);
}
if (!empty($preferences->email_email) && !validate_email($preferences->email_email)) {

0 comments on commit 84f533b

Please sign in to comment.