Skip to content

Commit

Permalink
Merge branch 'MDL-67853-master' of https://github.com/crazyserver/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyatregubov committed Jan 27, 2022
2 parents 86282be + d195956 commit 57fe1a3
Show file tree
Hide file tree
Showing 62 changed files with 1,174 additions and 756 deletions.
87 changes: 34 additions & 53 deletions admin/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,69 +48,52 @@
foreach ($providers as $provider) {
$componentproviderbase = $provider->component.'_'.$provider->name;
$disableprovidersetting = $componentproviderbase.'_disable';
$providerdisabled = false;
if (!isset($form->$disableprovidersetting)) {
$providerdisabled = true;
$newpreferences[$disableprovidersetting] = 1;
} else {
$newpreferences[$disableprovidersetting] = 0;
}

foreach (array('permitted', 'loggedin', 'loggedoff') as $setting) {
$value = null;
$componentprovidersetting = $componentproviderbase.'_'.$setting;
if ($setting == 'permitted') {
// If we deal with permitted select element, we need to create individual
// setting for each possible processor. Note that this block will
// always be processed first after entring parental foreach iteration
// so we can change form values on this stage.
foreach ($processors as $processor) {
$value = '';
if (isset($form->{$componentprovidersetting}[$processor->name])) {
$value = $form->{$componentprovidersetting}[$processor->name];
}
// Ensure that loggedin loggedoff options are set correctly for this permission.
if (($value == 'disallowed') || $providerdisabled) {
// It might be better to unset them, but I can't figure out why that cause error.
$form->{$componentproviderbase.'_loggedin'}[$processor->name] = 0;
$form->{$componentproviderbase.'_loggedoff'}[$processor->name] = 0;
} else if ($value == 'forced') {
$form->{$componentproviderbase.'_loggedin'}[$processor->name] = 1;
$form->{$componentproviderbase.'_loggedoff'}[$processor->name] = 1;
}
// Record the site preference.
$newpreferences[$processor->name.'_provider_'.$componentprovidersetting] = $value;
}
} else {
$newsettings = array();
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.
$newsettings = array_keys(array_filter($form->{$componentprovidersetting}));
$componentprovidersetting = $componentproviderbase.'_locked';
foreach ($processors as $processor) {
$value = 0;
if (isset($form->{$componentprovidersetting}[$processor->name])) {
$value = $form->{$componentprovidersetting}[$processor->name];
if ($value == 'on') {
$value = 1;
}
}

// 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;
}
}
}
// Record the site preference.
$newpreferences[$processor->name.'_provider_'.$componentprovidersetting] = $value;
}

$componentprovidersetting = $componentproviderbase.'_enabled';
$newsettings = [];
if (isset($form->$componentprovidersetting)) {
// Store defined comma-separated processors as setting value.
// Using array_filter eliminates elements set to 0 above.
$newsettings = array_keys(array_filter($form->{$componentprovidersetting}));
}

$value = join(',', $newsettings);
if (empty($value)) {
$value = null;
// 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;
}
}
if ($setting != 'permitted') {
// We have already recoded site preferences for 'permitted' type.
$newpreferences['message_provider_'.$componentprovidersetting] = $value;
}
}

$value = join(',', $newsettings);
if (empty($value)) {
$value = null;
}

// Record the site preference.
$newpreferences['message_provider_'.$componentprovidersetting] = $value;
}

// Update database.
Expand Down Expand Up @@ -142,8 +125,6 @@

// Page settings
$PAGE->set_context(context_system::instance());
$PAGE->requires->js_init_call('M.core_message.init_defaultoutputs');

$renderer = $PAGE->get_renderer('core', 'message');

// Display the page.
Expand Down
10 changes: 5 additions & 5 deletions admin/tool/dataprivacy/db/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@
// Notify Data Protection Officer about incoming data requests.
'contactdataprotectionofficer' => [
'defaults' => [
'popup' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF,
'email' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF,
'popup' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_ENABLED,
'email' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_ENABLED,
],
'capability' => 'tool/dataprivacy:managedatarequests'
],

// Notify user about the processing results of their data request.
'datarequestprocessingresults' => [
'defaults' => [
'popup' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF,
'email' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF,
'popup' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_ENABLED,
'email' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_ENABLED,
]
],

// Notify Data Protection Officer about exceptions.
'notifyexceptions' => [
'defaults' => [
'email' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF,
'email' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_ENABLED,
],
'capability' => 'tool/dataprivacy:managedatarequests'
],
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/mobile/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function test_pre_processor_message_send_callback() {
set_config('allowedemaildomains', 'example.com');

$DB->set_field_select('message_processors', 'enabled', 0, "name <> 'email'");
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'email', $user2);

// Extra content for all types of messages.
$message = new \core\message\message();
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/monitor/tests/behat/subscription.feature
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Feature: tool_monitor_subscriptions
Given I log in as "admin"
And I follow "Preferences" in the user menu
And I click on "Notification preferences" "link" in the "#page-content" "css_element"
And I click on "//td[@data-processor-name='popup']//label[@data-state='loggedin']" "xpath_element" in the "Notifications of rule subscriptions" "table_row"
And I click on "//td[@data-processor-name='popup']//div[@class='preference-state']" "xpath_element" in the "Notifications of rule subscriptions" "table_row"
And I wait until the page is ready
And I follow "Preferences" in the user menu
And I follow "Event monitoring"
Expand All @@ -124,7 +124,7 @@ Feature: tool_monitor_subscriptions
Given I log in as "teacher1"
And I follow "Preferences" in the user menu
And I click on "Notification preferences" "link" in the "#page-content" "css_element"
And I click on "//td[@data-processor-name='popup']//label[@data-state='loggedin']" "xpath_element" in the "Notifications of rule subscriptions" "table_row"
And I click on "//td[@data-processor-name='popup']//div[@class='preference-state']" "xpath_element" in the "Notifications of rule subscriptions" "table_row"
And I wait until the page is ready
And I follow "Preferences" in the user menu
And I follow "Event monitoring"
Expand Down
38 changes: 36 additions & 2 deletions backup/util/dbops/restore_dbops.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,41 @@ public static function create_included_users($basepath, $restoreid, $userid,
$preference = (object)$preference;
// Prepare the record and insert it
$preference->userid = $newuserid;
$status = $DB->insert_record('user_preferences', $preference);

// Translate _loggedin / _loggedoff message user preferences to _enabled. (MDL-67853)
// This code cannot be removed.
if (preg_match('/message_provider_.*/', $preference->name)) {
$nameparts = explode('_', $preference->name);
$name = array_pop($nameparts);

if ($name == 'loggedin' || $name == 'loggedoff') {
$preference->name = implode('_', $nameparts).'_enabled';

$existingpreference = $DB->get_record('user_preferences',
['name' => $preference->name , 'userid' => $newuserid]);
// Merge both values.
if ($existingpreference) {
$values = [];

if (!empty($existingpreference->value) && $existingpreference->value != 'none') {
$values = explode(',', $existingpreference->value);
}

if (!empty($preference->value) && $preference->value != 'none') {
$values = array_merge(explode(',', $preference->value), $values);
$values = array_unique($values);
}

$existingpreference->value = empty($values) ? 'none' : implode(',', $values);

$DB->update_record('user_preferences', $existingpreference);
continue;
}
}
}
// End translating loggedin / loggedoff message user preferences.

$DB->insert_record('user_preferences', $preference);
}
}
// Special handling for htmleditor which was converted to a preference.
Expand All @@ -1311,7 +1345,7 @@ public static function create_included_users($basepath, $restoreid, $userid,
$preference->userid = $newuserid;
$preference->name = 'htmleditor';
$preference->value = 'textarea';
$status = $DB->insert_record('user_preferences', $preference);
$DB->insert_record('user_preferences', $preference);
}
}

Expand Down
2 changes: 1 addition & 1 deletion badges/tests/badgeslib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public function test_badge_awards() {
$sink = $this->redirectMessages();

$DB->set_field_select('message_processors', 'enabled', 0, "name <> 'email'");
set_user_preference('message_provider_moodle_badgerecipientnotice_loggedoff', 'email', $user1);
set_user_preference('message_provider_moodle_badgerecipientnotice_enabled', 'email', $user1);

$badge->issue($user1->id, false);
$this->assertDebuggingCalled(); // Expect debugging while baking a badge via phpunit.
Expand Down
7 changes: 7 additions & 0 deletions lang/en/deprecated.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,10 @@ navmethod,core_grades
dropdown,core_grades
tabs,core_grades
combo,core_grades
defaults,core_message
loggedin_help,core_message
loggedindescription,core_message
loggedoff_help,core_message
loggedoffdescription,core_message
sendingvia,core_message
sendingviawhen,core_message
21 changes: 14 additions & 7 deletions lang/en/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
$string['conversationactions'] = 'Conversation actions menu';
$string['decline'] = 'Decline';
$string['defaultmessageoutputs'] = 'Notification settings';
$string['defaults'] = 'Defaults';
$string['deleteallconfirm'] = "Are you sure you would like to delete this entire conversation? This will not delete it for other conversation participants.";
$string['deleteallmessages'] = "Delete all messages";
$string['deleteallselfconfirm'] = "Are you sure you would like to delete this entire personal conversation?";
Expand Down Expand Up @@ -93,11 +92,7 @@
$string['isnotinyourcontacts'] = '{$a} is not in your contacts';
$string['loadmore'] = 'Load more';
$string['loggedin'] = 'Online';
$string['loggedin_help'] = 'Configure how you would like to receive notifications when you are logged into Moodle';
$string['loggedindescription'] = 'When you are logged into Moodle';
$string['loggedoff'] = 'Offline';
$string['loggedoff_help'] = 'Configure how you would like to receive notifications when you are not logged into Moodle';
$string['loggedoffdescription'] = 'When you are not logged into Moodle';
$string['managemessageoutputs'] = 'Default notification preferences';
$string['messageoutputs'] = 'Notification plugins';
$string['messagepreferences'] = 'Message preferences';
Expand Down Expand Up @@ -213,6 +208,9 @@
$string['privacy:request:preference:set'] = 'The value of the setting \'{$a->name}\' was \'{$a->value}\'';
$string['privacy:export:conversationprefix'] = 'Conversation: ';
$string['processorsettings'] = 'Processor settings';
$string['providerenabled'] = 'Sending "{$a}" enabled status';
$string['providerprocesorislocked'] = '"{$a->provider}" on "{$a->processor}" is locked';
$string['providerprocesorisdisallowed'] = '"{$a->provider}" on "{$a->processor}" is disallowed';
$string['removecontact'] = 'Remove contact';
$string['removecontactconfirm'] = 'Are you sure you want to remove {$a} from your contacts?';
$string['removecoursefilter'] = 'Remove filter for course {$a}';
Expand All @@ -231,9 +229,9 @@
$string['selfconversationdefaultmessage'] = 'Save draft messages, links, notes etc. to access later.';
$string['send'] = 'Send';
$string['sender'] = '{$a}:';
$string['sendingvia'] = 'Sending "{$a->provider}" via "{$a->processor}"';
$string['sendingviawhen'] = 'Sending "{$a->provider}" via "{$a->processor}" when {$a->state}';
$string['sendcontactrequest'] = 'Send contact request';
$string['sendingviaenabled'] = 'Sending "{$a->provider}" via "{$a->processor}" enabled status';
$string['sendingvialocked'] = 'Sending "{$a->provider}" via "{$a->processor}" locked status';
$string['sendmessage'] = 'Send message';
$string['sendbulkmessage'] = 'Send message to {$a} people';
$string['sendbulkmessagesingle'] = 'Send message to 1 person';
Expand Down Expand Up @@ -279,3 +277,12 @@
// Deprecated since Moodle 3.9.
$string['messagecontactrequestsnotification'] = '{$a} is requesting to be added as a contact.';
$string['messagecontactrequestsnotificationsubject'] = 'Contact request from {$a}';

// Deprecated since Moodle 4.0.
$string['defaults'] = 'Defaults';
$string['loggedin_help'] = 'Configure how you would like to receive notifications when you are logged into Moodle';
$string['loggedindescription'] = 'When you are logged into Moodle';
$string['loggedoff_help'] = 'Configure how you would like to receive notifications when you are not logged into Moodle';
$string['loggedoffdescription'] = 'When you are not logged into Moodle';
$string['sendingvia'] = 'Sending "{$a->provider}" via "{$a->processor}"';
$string['sendingviawhen'] = 'Sending "{$a->provider}" via "{$a->processor}" when {$a->state}';
Loading

0 comments on commit 57fe1a3

Please sign in to comment.