MDL-63211 core: added notification when contact request is made

This commit is contained in:
Mark Nelson
2018-10-03 11:58:39 +08:00
parent 892aad5185
commit be016b0144
6 changed files with 50 additions and 8 deletions
+2
View File
@@ -71,6 +71,8 @@ $string['managemessageoutputs'] = 'Manage message outputs';
$string['messageoutputs'] = 'Message outputs';
$string['messagepreferences'] = 'Message preferences';
$string['message'] = 'Message';
$string['messagecontactrequestsnotification'] = '{$a} wants to be added as a contact';
$string['messagecontactrequestsnotificationsubject'] = '{$a} wants to be added as a contact';
$string['messagepreferences'] = 'Message preferences';
$string['messages'] = 'Messages';
$string['messagingdatahasnotbeenmigrated'] = 'Your messages are temporarily unavailable due to upgrades in the messaging infrastructure. Please wait for them to be migrated.';
+1
View File
@@ -1194,6 +1194,7 @@ $string['messageprovider:courserequested'] = 'Course creation request notificati
$string['messageprovider:courserequestrejected'] = 'Course creation request rejection notification';
$string['messageprovider:errors'] = 'Important errors with the site';
$string['messageprovider:errors_help'] = 'These are important errors that an administrator should know about.';
$string['messageprovider:messagecontactrequests'] = 'Message contact requests notification';
$string['messageprovider:notices'] = 'Notices about minor problems';
$string['messageprovider:notices_help'] = 'These are notices that an administrator might be interested in seeing.';
$string['messageprovider:insights'] = 'Insights generated by prediction models';
+9 -1
View File
@@ -105,5 +105,13 @@ $messageproviders = array (
// User insights.
'insights' => array (
'capability' => 'moodle/analytics:listinsights'
)
),
// Message contact requests.
'messagecontactrequests' => [
'defaults' => [
'popup' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF,
'email' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDOFF,
]
],
);
+25
View File
@@ -1324,6 +1324,31 @@ class api {
$request->timecreated = time();
$DB->insert_record('message_contact_requests', $request);
// Send a notification.
$userfrom = \core_user::get_user($userid);
$userfromfullname = fullname($userfrom);
$userto = \core_user::get_user($requesteduserid);
$url = new \moodle_url('/message/pendingcontactrequests.php');
$subject = get_string('messagecontactrequestsnotificationsubject', 'core_message', $userfromfullname);
$fullmessage = get_string('messagecontactrequestsnotification', 'core_message', $userfromfullname);
$message = new \core\message\message();
$message->courseid = SITEID;
$message->component = 'moodle';
$message->name = 'messagecontactrequests';
$message->notification = 1;
$message->userfrom = $userfrom;
$message->userto = $userto;
$message->subject = $subject;
$message->fullmessage = text_to_html($fullmessage);
$message->fullmessageformat = FORMAT_HTML;
$message->fullmessagehtml = $fullmessage;
$message->smallmessage = '';
$message->contexturl = $url->out(false);
message_send($message);
}
+12 -6
View File
@@ -509,8 +509,8 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide
// There should be two conversation members.
$this->assertEquals(2, $DB->count_records('message_conversation_members'));
// There should be two notifications.
$this->assertEquals(2, $DB->count_records('notifications'));
// There should be two notifications + one for the contact request.
$this->assertEquals(3, $DB->count_records('notifications'));
provider::delete_data_for_all_users_in_context($systemcontext);
@@ -585,8 +585,8 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide
// There should be two conversation members.
$this->assertEquals(2, $DB->count_records('message_conversation_members'));
// There should be three notifications.
$this->assertEquals(3, $DB->count_records('notifications'));
// There should be three notifications + two for the contact requests.
$this->assertEquals(5, $DB->count_records('notifications'));
$systemcontext = \context_system::instance();
$contextlist = new \core_privacy\local\request\approved_contextlist($user1, 'core_message',
@@ -631,8 +631,14 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide
$mcm = reset($mcms);
$this->assertEquals($user2->id, $mcm->userid);
$this->assertCount(1, $notifications);
$notification = reset($notifications);
$this->assertCount(2, $notifications);
ksort($notifications);
$notification = array_shift($notifications);
$this->assertEquals($user2->id, $notification->useridfrom);
$this->assertEquals($user4->id, $notification->useridto);
$notification = array_shift($notifications);
$this->assertEquals($user2->id, $notification->useridfrom);
$this->assertEquals($user3->id, $notification->useridto);
}
+1 -1
View File
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2018092800.04; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2018092800.05; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.