From 3a5cfc1f593559660e18e5772e562c75db4be094 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 22 Mar 2016 17:22:18 +0000 Subject: [PATCH] MDL-53589 badges: fix capability check --- badges/lib.php | 10 ++-------- lib/deprecatedlib.php | 8 +------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/badges/lib.php b/badges/lib.php index 6e1be220e8d..4c2a0ff7a9b 100644 --- a/badges/lib.php +++ b/badges/lib.php @@ -45,13 +45,7 @@ function core_badges_myprofile_navigation(\core_user\output\myprofile\tree $tree // Add category. This node should appear after 'contact' so that administration block appears towards the end. Refer MDL-49928. $category = new core_user\output\myprofile\category('badges', get_string('badges', 'badges'), 'contact'); $tree->add_category($category); - - // Determine context. - if (isloggedin()) { - $context = context_user::instance($USER->id); - } else { - $context = context_system::instance(); - } + $context = context_user::instance($user->id); $courseid = empty($course) ? 0 : $course->id; if ($USER->id == $user->id || has_capability('moodle/badges:viewotherbadges', $context)) { @@ -78,4 +72,4 @@ function core_badges_myprofile_navigation(\core_user\output\myprofile\tree $tree } } } -} \ No newline at end of file +} diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index d09fcc0a520..aa8c325f816 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -2145,13 +2145,7 @@ function profile_display_badges($userid, $courseid = 0) { require_once($CFG->dirroot . '/badges/renderer.php'); debugging('profile_display_badges() is deprecated.', DEBUG_DEVELOPER); - - // Determine context. - if (isloggedin()) { - $context = context_user::instance($USER->id); - } else { - $context = context_system::instance(); - } + $context = context_user::instance($userid); if ($USER->id == $userid || has_capability('moodle/badges:viewotherbadges', $context)) { $records = badges_get_user_badges($userid, $courseid, null, null, null, true);