mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
navigation MDL-23852 Added is_role_switched method to accesslib and implemented use of it
This commit is contained in:
parent
00fa663431
commit
f5c1e62149
@ -5285,13 +5285,28 @@ function role_switch($roleid, $context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the user has switched roles within the given course.
|
||||
*
|
||||
* Note: You can only switch roles within the course, hence it takes a courseid
|
||||
* rather than a context. On that note Petr volunteered to implement this across
|
||||
* all other contexts, all requests for this should be forwarded to him ;)
|
||||
*
|
||||
* @param int $courseid The id of the course to check
|
||||
* @return bool True if the user has switched roles within the course.
|
||||
*/
|
||||
function is_role_switched($courseid) {
|
||||
global $USER;
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid, MUST_EXIST);
|
||||
return (!empty($USER->access['rsw'][$context->path]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get any role that has an override on exact context
|
||||
*
|
||||
* @global object
|
||||
* @param object $context
|
||||
* @return array
|
||||
* @global moodle_database
|
||||
* @param stdClass $context The context to check
|
||||
* @return array An array of roles
|
||||
*/
|
||||
function get_roles_with_override_on_context($context) {
|
||||
global $DB;
|
||||
|
@ -2318,7 +2318,7 @@ function require_login($courseorid = NULL, $autologinguest = true, $cm = NULL, $
|
||||
if ($course->id == SITEID) {
|
||||
// frontpage can not be hidden
|
||||
} else {
|
||||
if (!empty($USER->access['rsw'][$coursecontext->path])) {
|
||||
if (is_role_switched($course->id)) {
|
||||
// when switching roles ignore the hidden flag - user had to be in course to do the switch
|
||||
} else {
|
||||
if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
|
||||
|
@ -982,7 +982,8 @@ class global_navigation extends navigation_node {
|
||||
// If the user is not enrolled then we only want to show the
|
||||
// course node and not populate it.
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
if (!is_enrolled($coursecontext) && !has_capability('moodle/course:view', $coursecontext)) {
|
||||
// Not enrolled, can't view, and hasn't switched roles
|
||||
if (!is_enrolled($coursecontext) && !has_capability('moodle/course:view', $coursecontext) && !is_role_switched($course->id)) {
|
||||
$coursenode->make_active();
|
||||
$canviewcourseprofile = false;
|
||||
break;
|
||||
@ -1525,6 +1526,14 @@ class global_navigation extends navigation_node {
|
||||
$usersnode->action = new moodle_url('/user/index.php', array('id'=>$course->id));
|
||||
$userviewurl = new moodle_url('/user/profile.php', $baseargs);
|
||||
}
|
||||
if (!$usersnode) {
|
||||
// We should NEVER get here, if the course hasn't been populated
|
||||
// with a participants node then the navigaiton either wasn't generated
|
||||
// for it (you are missing a require_login or set_context call) or
|
||||
// you don't have access.... in the interests of no leaking informatin
|
||||
// we simply quit...
|
||||
return false;
|
||||
}
|
||||
// Add a branch for the current user
|
||||
$usernode = $usersnode->add(fullname($user, true), $userviewurl, self::TYPE_USER, null, $user->id);
|
||||
|
||||
|
@ -421,7 +421,7 @@ class core_renderer extends renderer_base {
|
||||
if (isguestuser()) {
|
||||
$loggedinas = $realuserinfo.get_string('loggedinasguest').
|
||||
" (<a href=\"$loginurl\">".get_string('login').'</a>)';
|
||||
} else if (!empty($USER->access['rsw'][$context->path])) {
|
||||
} else if (is_role_switched($course->id)) { // Has switched roles
|
||||
$rolename = '';
|
||||
if ($role = $DB->get_record('role', array('id'=>$USER->access['rsw'][$context->path]))) {
|
||||
$rolename = ': '.format_string($role->name);
|
||||
|
@ -59,6 +59,7 @@ if (isguestuser($user)) {
|
||||
}
|
||||
|
||||
$PAGE->set_context($coursecontext);
|
||||
$PAGE->set_course($course);
|
||||
$PAGE->set_pagetype('course-view-' . $course->format); // To get the blocks exactly like the course
|
||||
$PAGE->add_body_class('path-user'); // So we can style it independently
|
||||
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
|
||||
@ -73,14 +74,12 @@ if (!$currentuser
|
||||
// please note this is just a guess!
|
||||
require_login();
|
||||
$isparent = true;
|
||||
|
||||
} else {
|
||||
// normal course
|
||||
require_login($course);
|
||||
// what to do with users temporary accessing this course? shoudl they see the details?
|
||||
}
|
||||
|
||||
|
||||
$strpersonalprofile = get_string('personalprofile');
|
||||
$strparticipants = get_string("participants");
|
||||
$struser = get_string("user");
|
||||
|
Loading…
x
Reference in New Issue
Block a user