Skip to content

Commit

Permalink
Merged changes from 1.8 for "course creators" problem MDL-8093
Browse files Browse the repository at this point in the history
  • Loading branch information
moodler committed Mar 30, 2007
1 parent 12e9143 commit cf47a79
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions user/index.php
Expand Up @@ -254,20 +254,36 @@
}
}

$sitecontext = get_context_instance(CONTEXT_SYSTEM);

$rolenames = array();
$avoidroles = array();


if ($roles = get_roles_used_in_context($context)) {

// We should exclude "admin" users (those with "doanything" at site level) because

// We should ONLY allow roles with moodle/course:view because otherwise we get little niggly issues
// like MDL-8093
// We should further exclude "admin" users (those with "doanything" at site level) because
// Otherwise they appear in every participant list

$sitecontext = get_context_instance(CONTEXT_SYSTEM);
$canviewroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $context);
$doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $sitecontext);

foreach ($roles as $role) {
if (!isset($canviewroles[$role->id])) { // Avoid this role (eg course creator)
$avoidroles[] = $role->id;
unset($roles[$role->id]);
continue;
}
if (isset($doanythingroles[$role->id])) { // Avoid this role (ie admin)
$avoidroles[] = $role->id;
unset($roles[$role->id]);
continue;
}
}

foreach ($roles as $role) {
$rolenames[$role->id] = strip_tags(format_string($role->name)); // Used in menus etc later on
}
}
Expand Down Expand Up @@ -344,19 +360,15 @@

$hiddensql = has_capability('moodle/role:viewhiddenassigns', $context)? '':' AND r.hidden = 0 ';

// excluse users with these admin role assignments
if ($doanythingroles) {
// exclude users with roles we are avoiding
if ($avoidroles) {
$adminroles = 'AND r.roleid NOT IN (';

foreach ($doanythingroles as $aroleid=>$role) {
$adminroles .= "$aroleid,";
}
$adminroles = rtrim($adminroles,",");
$adminroles .= implode(',', $avoidroles);
$adminroles .= ')';
} else {
$adminroles = '';
}

// join on 2 conditions
// otherwise we run into the problem of having records in ul table, but not relevant course
// and user record is not pulled out
Expand Down

0 comments on commit cf47a79

Please sign in to comment.