Skip to content

Commit

Permalink
MDL-49763 webservices: Handle correctly deleted users for ratings
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Apr 10, 2015
1 parent d755125 commit d982713
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions rating/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,19 @@ public static function get_item_ratings($contextlevel, $instanceid, $component,
if ($rating->rating > $maxrating) {
$rating->rating = $maxrating;
}
$usercontext = context_user::instance($rating->userid);
$profileimageurl = moodle_url::make_webservice_pluginfile_url($usercontext->id, 'user', 'icon', null, '/', 'f1');

$profileimageurl = '';
// We can have ratings from deleted users. In this case, those users don't have a valid context.
$usercontext = context_user::instance($rating->userid, IGNORE_MISSING);
if ($usercontext) {
$profileimageurl = moodle_url::make_webservice_pluginfile_url($usercontext->id, 'user', 'icon', null,
'/', 'f1')->out(false);
}

$result = array();
$result['id'] = $rating->id;
$result['userid'] = $rating->userid;
$result['userpictureurl'] = $profileimageurl->out(false);
$result['userpictureurl'] = $profileimageurl;
$result['userfullname'] = fullname($rating);
$result['rating'] = $scalemenu[$rating->rating];
$result['timemodified'] = $rating->timemodified;
Expand Down
3 changes: 3 additions & 0 deletions rating/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public function test_get_item_ratings() {
$rating2->timemodified = time() + 1;
$rating2->id = $DB->insert_record('rating', $rating2);

// Delete teacher2, we must still receive the ratings.
delete_user($teacher2);

// Teachers can see all the ratings.
$this->setUser($teacher1);

Expand Down

0 comments on commit d982713

Please sign in to comment.