Improvements to switchroles
1) You can have separate switchroles active in every course 2) Admins get a better view (doanything is supressed when switchroles active)
This commit is contained in:
+11
-8
@@ -301,10 +301,13 @@ function has_capability($capability, $context=NULL, $userid=NULL, $doanything=tr
|
||||
}
|
||||
|
||||
if ($doanything) {
|
||||
|
||||
// Check site
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||
if (isset($capabilities[$sitecontext->id]['moodle/site:doanything'])) {
|
||||
return (0 < $capabilities[$sitecontext->id]['moodle/site:doanything']);
|
||||
if (empty($USER->switchrole[$context->id])) { // Ignore site setting if switchrole is active
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||
if (isset($capabilities[$sitecontext->id]['moodle/site:doanything'])) {
|
||||
return (0 < $capabilities[$sitecontext->id]['moodle/site:doanything']);
|
||||
}
|
||||
}
|
||||
|
||||
switch ($context->aggregatelevel) {
|
||||
@@ -2650,9 +2653,9 @@ function role_switch($roleid, $context) {
|
||||
|
||||
/// If we can't use this or are already using it or no role was specified then bail completely and reset
|
||||
if (empty($roleid) || !has_capability('moodle/role:switchroles', $context)
|
||||
|| !empty($USER->switchrole) || !confirm_sesskey()) {
|
||||
load_user_capability(); // Reset all permissions to normal
|
||||
unset($USER->switchrole); // Delete old capabilities
|
||||
|| !empty($USER->switchrole[$context->id]) || !confirm_sesskey()) {
|
||||
load_user_capability('', $context); // Reset all permissions for this context to normal
|
||||
unset($USER->switchrole[$context->id]); // Delete old capabilities
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2671,7 +2674,7 @@ function role_switch($roleid, $context) {
|
||||
|
||||
/// We have a valid roleid that this user can switch to, so let's set up the session
|
||||
|
||||
$USER->switchrole = $roleid; // So we know later what state we are in
|
||||
$USER->switchrole[$context->id] = $roleid; // So we know later what state we are in
|
||||
|
||||
unset($USER->capabilities[$context->id]); // Delete old capabilities
|
||||
|
||||
@@ -2681,7 +2684,7 @@ function role_switch($roleid, $context) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Add some capabilities we are really going to always need, even if the role doesn't have them!
|
||||
/// Add some permissions we are really going to always need, even if the role doesn't have them!
|
||||
|
||||
$USER->capabilities[$context->id]['moodle/course:view'] = CAP_ALLOW;
|
||||
|
||||
|
||||
+4
-2
@@ -2604,14 +2604,16 @@ function user_login_string($course=NULL, $user=NULL) {
|
||||
// $course->id is not defined during installation
|
||||
return '';
|
||||
} else if (isset($user->id) and $user->id) {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
|
||||
$fullname = fullname($user, true);
|
||||
$username = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id\">$fullname</a>";
|
||||
if (isset($user->username) && $user->username == 'guest') {
|
||||
$loggedinas = $realuserinfo.get_string('loggedinasguest').
|
||||
" (<a target=\"{$CFG->framename}\" href=\"$wwwroot/login/index.php\">".get_string('login').'</a>)';
|
||||
} else if (!empty($user->switchrole)) {
|
||||
} else if (!empty($user->switchrole[$context->id])) {
|
||||
$rolename = '';
|
||||
if ($role = get_record('role', 'id', $user->switchrole)) {
|
||||
if ($role = get_record('role', 'id', $user->switchrole[$context->id])) {
|
||||
$rolename = ': '.format_string($role->name);
|
||||
}
|
||||
$loggedinas = get_string('loggedinas', 'moodle', $username).$rolename.
|
||||
|
||||
Reference in New Issue
Block a user