Merge branch 'MDL-65620-38' of git://github.com/aanabit/moodle into MOODLE_38_STABLE

This commit is contained in:
Adrian Greeve
2019-12-05 09:26:43 +08:00
3 changed files with 139 additions and 11 deletions
+31 -11
View File
@@ -33,13 +33,17 @@ $allprocessors = get_message_processors();
$processors = array_filter($allprocessors, function($processor) {
return $processor->enabled;
});
$disabledprocessors = array_filter($allprocessors, function($processor) {
return !$processor->enabled;
});
// Fetch message providers.
$providers = get_message_providers();
// Fetch the manage message outputs interface.
$preferences = get_message_output_default_preferences();
if (($form = data_submitted()) && confirm_sesskey()) {
$preferences = array();
$newpreferences = array();
// Prepare default message outputs settings.
foreach ($providers as $provider) {
$componentproviderbase = $provider->component.'_'.$provider->name;
@@ -47,9 +51,9 @@ if (($form = data_submitted()) && confirm_sesskey()) {
$providerdisabled = false;
if (!isset($form->$disableprovidersetting)) {
$providerdisabled = true;
$preferences[$disableprovidersetting] = 1;
$newpreferences[$disableprovidersetting] = 1;
} else {
$preferences[$disableprovidersetting] = 0;
$newpreferences[$disableprovidersetting] = 0;
}
foreach (array('permitted', 'loggedin', 'loggedoff') as $setting) {
@@ -75,20 +79,36 @@ if (($form = data_submitted()) && confirm_sesskey()) {
$form->{$componentproviderbase.'_loggedoff'}[$processor->name] = 1;
}
// Record the site preference.
$preferences[$processor->name.'_provider_'.$componentprovidersetting] = $value;
$newpreferences[$processor->name.'_provider_'.$componentprovidersetting] = $value;
}
} else if (property_exists($form, $componentprovidersetting)) {
// We must be processing loggedin or loggedoff checkboxes. Store
// defained comma-separated processors as setting value.
// Using array_filter eliminates elements set to 0 above.
$value = join(',', array_keys(array_filter($form->{$componentprovidersetting})));
} else {
$newsettings = array();
if (array_key_exists($componentprovidersetting, $form)) {
// We must be processing loggedin or loggedoff checkboxes.
// Store defained comma-separated processors as setting value.
// Using array_filter eliminates elements set to 0 above.
$newsettings = array_keys(array_filter($form->{$componentprovidersetting}));
}
// Let's join existing setting values for disabled processors.
$property = 'message_provider_'.$componentprovidersetting;
if (property_exists($preferences, $property)) {
$existingsetting = $preferences->$property;
foreach ($disabledprocessors as $disable) {
if (strpos($existingsetting, $disable->name) > -1) {
$newsettings[] = $disable->name;
}
}
}
$value = join(',', $newsettings);
if (empty($value)) {
$value = null;
}
}
if ($setting != 'permitted') {
// We have already recoded site preferences for 'permitted' type.
$preferences['message_provider_'.$componentprovidersetting] = $value;
$newpreferences['message_provider_'.$componentprovidersetting] = $value;
}
}
}
@@ -102,7 +122,7 @@ if (($form = data_submitted()) && confirm_sesskey()) {
\core_message\api::update_processor_status($processor, $enabled);
}
foreach ($preferences as $name => $value) {
foreach ($newpreferences as $name => $value) {
set_config($name, $value, 'message');
}
$transaction->allow_commit();
@@ -212,6 +212,11 @@ class behat_core_generator extends behat_generator_base {
'datagenerator' => 'analytics_model',
'required' => ['target', 'indicators', 'timesplitting', 'enabled'],
],
'user preferences' => [
'datagenerator' => 'user_preferences',
'required' => array('user', 'preference', 'value'),
'switchids' => array('user' => 'userid')
],
];
}
@@ -801,4 +806,14 @@ class behat_core_generator extends behat_generator_base {
protected function process_analytics_model($data) {
\core_analytics\manager::create_declared_model($data);
}
/**
* Set a preference value for user
*
* @param array $data
* @return void
*/
protected function process_user_preferences(array $data) {
set_user_preference($data['preference'], $data['value'], $data['userid']);
}
}
@@ -0,0 +1,93 @@
@core @core_message @javascript
Feature: Manage notification preferences - Email
In order to be notified of messages
As a user
I need to be able to update my messaging notification preferences
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And the following config values are set as admin:
| messaging | 1 |
Scenario: Disable email notifications for everybody
Given I log in as "admin"
When I navigate to "Messaging > Notification settings" in site administration
And I set the field "email" to "0"
And I press "Save changes"
And I log out
And I log in as "student1"
And I open messaging
And I open messaging settings preferences
Then I should not see "Notification preferences"
And I should not see "Email"
Scenario: Enable email notifications
# Disable email default value
Given the following "user preferences" exist:
| user | preference | value |
| student1 | message_provider_moodle_instantmessage_loggedin | none |
| student1 | message_provider_moodle_instantmessage_loggedoff | none |
When I log in as "admin"
And I navigate to "Messaging > Notification settings" in site administration
And I set the field "email" to "1"
And I press "Save changes"
And I log out
And I log in as "student1"
And I open messaging
And I open messaging settings preferences
Then I should see "Notification preferences"
And I should see "Email"
And the field "Email" matches value "0"
And I set the field "Email" to "1"
And I follow "Preferences" in the user menu
And I click on "Message preferences" "link"
And the field "Email" matches value "1"
Scenario: Disable email notifications
Given I log in as "admin"
When I navigate to "Messaging > Notification settings" in site administration
And I set the field "email" to "1"
And I press "Save changes"
And I log out
And I log in as "student1"
And I open messaging
And I open messaging settings preferences
Then I should see "Notification preferences"
And I should see "Email"
And the field "Email" matches value "1"
And I set the field "Email" to "0"
And I follow "Preferences" in the user menu
And I click on "Message preferences" "link"
And the field "Email" matches value "0"
Scenario: Config jabber
Given the following config values are set as admin:
| jabberhost | jabber.org |
| jabberusername | moodlemessageservice |
| jabberpassword | password |
When I log in as "admin"
And I navigate to "Messaging > Notification settings" in site administration
And I set the field "jabber" to "1"
And I press "Save changes"
And I click on "Settings" "link" in the "Jabber" "table_row"
And I navigate to "Messaging > Notification settings" in site administration
And I press "Save changes"
And I log out
And I log in as "student1"
And I open messaging
And I open messaging settings preferences
Then I should not see "Notification preferences"
And I should not see "Jabber"
And I open the notification popover
And I follow "Notification preferences"
And I click on "Jabber" "link"
And I should see "Jabber ID"
And I set the field "jabber_jabberid" to "student1@jabber.org"
And I click on "Save changes" "button" in the ".modal-dialog" "css_element"
And I am on homepage
And I open messaging
And I open messaging settings preferences
And I should see "Notification preferences"
And I should see "Jabber"