From 84f533b3c34071376775e27a7e2f48b85cabf222 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Mon, 23 Jan 2012 10:27:47 +0700 Subject: [PATCH 1/2] MDL-29615 message: added the ability for admins to restrict users ability to set where their email message notifications go --- admin/settings/subsystems.php | 4 +++- lang/en/admin.php | 2 ++ message/output/email/lang/en/message_email.php | 1 + message/output/email/message_output_email.php | 13 ++++++++++--- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/admin/settings/subsystems.php b/admin/settings/subsystems.php index 00ffb21dc5a..28bdebb6107 100644 --- a/admin/settings/subsystems.php +++ b/admin/settings/subsystems.php @@ -20,6 +20,8 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page $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 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page $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)); -} \ No newline at end of file +} diff --git a/lang/en/admin.php b/lang/en/admin.php index 153dcb7cd87..dbf6a26d7cc 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -242,6 +242,7 @@ $string['configmaxevents'] = 'Events to Lookahead'; $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['mediapluginyoutube'] = 'Enable YouTube links filter'; $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'; diff --git a/message/output/email/lang/en/message_email.php b/message/output/email/lang/en/message_email.php index ae06d11d976..2cc5b404cb8 100644 --- a/message/output/email/lang/en/message_email.php +++ b/message/output/email/lang/en/message_email.php @@ -32,6 +32,7 @@ $string['configsmtphosts'] = 'Give the full name of one or more local SMTP serve $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'; diff --git a/message/output/email/message_output_email.php b/message/output/email/message_output_email.php index 80262db6e5e..0e5590282ee 100644 --- a/message/output/email/message_output_email.php +++ b/message/output/email/message_output_email.php @@ -57,7 +57,10 @@ class message_output_email extends message_output { //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 @@ class message_output_email extends message_output { * @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)) { From 8900213b922c577639b339618268c948052cda4f Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Wed, 1 Feb 2012 09:26:53 +0700 Subject: [PATCH 2/2] MDL-29615 message: reversed the default for messagingallowemailoverride and added upgrade code so upgraded sites maintain consistent behaviour --- admin/settings/subsystems.php | 2 +- lib/db/upgrade.php | 10 ++++++++++ version.php | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/admin/settings/subsystems.php b/admin/settings/subsystems.php index 28bdebb6107..7c70af3bf18 100644 --- a/admin/settings/subsystems.php +++ b/admin/settings/subsystems.php @@ -20,7 +20,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page $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('messagingallowemailoverride', new lang_string('messagingallowemailoverride', 'admin'), new lang_string('configmessagingallowemailoverride','admin'), 0)); $optionalsubsystems->add(new admin_setting_configcheckbox('enablestats', new lang_string('enablestats', 'admin'), new lang_string('configenablestats', 'admin'), 0)); diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index ca60e07cd10..2c28ba359ef 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -135,6 +135,16 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2012020200.03); } + if ($oldversion < 2012020200.06) { + // Previously we always allowed users to override their email address via the messaging system + // We have now added a setting to allow admins to turn this this ability on and off + // While this setting defaults to 0 (off) we're setting it to 1 (on) to maintain the behaviour for upgrading sites + set_config('messagingallowemailoverride', 1); + + // Main savepoint reached + upgrade_main_savepoint(true, 2012020200.06); + } + return true; } diff --git a/version.php b/version.php index 21aad43de07..57eeace1a10 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2012020200.05; // YYYYMMDD = weekly release date of this DEV branch +$version = 2012020200.06; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes