From bb9a123a73ed3dfaeecc7c492f8014770f410cb7 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Wed, 9 Jan 2008 16:46:21 +0000 Subject: [PATCH] MDL-12373 - If you can see your user profile, but don't have moodle/course:viewparticipants, you get a link in the nav bar that takes you to an error message - this was repeated in other parts of the user profile that I had not noticed when I fixed this before. --- user/edit.php | 9 ++++++++- user/editadvanced.php | 15 ++++++++++++--- user/messageselect.php | 9 ++++++--- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/user/edit.php b/user/edit.php index db8a645f42..8baf42d53d 100644 --- a/user/edit.php +++ b/user/edit.php @@ -50,6 +50,11 @@ redirect($CFG->wwwroot . "/user/view.php?course={$course->id}"); } + if ($course->id == SITEID) { + $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context + } else { + $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context + } $systemcontext = get_context_instance(CONTEXT_SYSTEM); $personalcontext = get_context_instance(CONTEXT_USER, $user->id); @@ -145,7 +150,9 @@ $userfullname = fullname($user, true); $navlinks = array(); - $navlinks[] = array('name' => $strparticipants, 'link' => "index.php?id=$course->id", 'type' => 'misc'); + if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) { + $navlinks[] = array('name' => $strparticipants, 'link' => "index.php?id=$course->id", 'type' => 'misc'); + } $navlinks[] = array('name' => $userfullname, 'link' => "view.php?id=$user->id&course=$course->id", 'type' => 'misc'); diff --git a/user/editadvanced.php b/user/editadvanced.php index a03d52ed67..98812c0d55 100644 --- a/user/editadvanced.php +++ b/user/editadvanced.php @@ -17,16 +17,23 @@ } require_login($course->id); + if ($course->id == SITEID) { + $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context + } else { + $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context + } + $systemcontext = get_context_instance(CONTEXT_SYSTEM); + if ($id == -1) { // creating new user - require_capability('moodle/user:create', get_context_instance(CONTEXT_SYSTEM)); + require_capability('moodle/user:create', $systemcontext); $user = new object(); $user->id = -1; $user->auth = 'manual'; $user->confirmed = 1; } else { // editing existing user - require_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM)); + require_capability('moodle/user:update', $systemcontext); if (!$user = get_record('user', 'id', $id)) { error('User ID was incorrect'); } @@ -178,7 +185,9 @@ $userfullname = fullname($user, true); $navlinks = array(); - $navlinks[] = array('name' => $strparticipants, 'link' => "index.php?id=$course->id", 'type' => 'misc'); + if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) { + $navlinks[] = array('name' => $strparticipants, 'link' => "index.php?id=$course->id", 'type' => 'misc'); + } $navlinks[] = array('name' => $userfullname, 'link' => "view.php?id=$user->id&course=$course->id", 'type' => 'misc'); diff --git a/user/messageselect.php b/user/messageselect.php index 0228b632c2..fefe3a57cf 100644 --- a/user/messageselect.php +++ b/user/messageselect.php @@ -18,8 +18,9 @@ require_login(); - require_capability('moodle/course:bulkmessaging', get_context_instance(CONTEXT_COURSE, $id)); - + $coursecontext = get_context_instance(CONTEXT_COURSE, $id); // Course context + $systemcontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context + require_capability('moodle/course:bulkmessaging', $coursecontext); if (empty($SESSION->emailto)) { $SESSION->emailto = array(); @@ -63,7 +64,9 @@ } $navlinks = array(); - $navlinks[] = array('name' => get_string('participants'), 'link' => "index.php?id=$course->id", 'type' => 'misc'); + if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) { + $navlinks[] = array('name' => get_string('participants'), 'link' => "index.php?id=$course->id", 'type' => 'misc'); + } $navlinks[] = array('name' => $strtitle, 'link' => null, 'type' => 'misc'); $navigation = build_navigation($navlinks); -- 2.39.5