Skip to content

Commit

Permalink
MDL-63211 core: added notification when contact request is made
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Oct 3, 2018
1 parent 892aad5 commit be016b0
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lang/en/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
$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.';
Expand Down
1 change: 1 addition & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,7 @@
$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';
Expand Down
10 changes: 9 additions & 1 deletion lib/db/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,13 @@
// 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 changes: 25 additions & 0 deletions message/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,31 @@ public static function create_contact_request(int $userid, int $requesteduserid)
$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);
}


Expand Down
18 changes: 12 additions & 6 deletions message/tests/privacy_provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ public function test_delete_data_for_all_users_in_context() {
// 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);

Expand Down Expand Up @@ -585,8 +585,8 @@ public function test_delete_data_for_user() {
// 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',
Expand Down Expand Up @@ -631,8 +631,14 @@ public function test_delete_data_for_user() {
$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);
}
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit be016b0

Please sign in to comment.