MDL-23219 check permissions: show relevant role-assignments.

Adding this list of role assignments should make it much easier for
admins to work out why, when the permissions shown in the check
permisisons page are now what they expect.

I thought about making the links go more directly to, for example, the
assign roles pages for each context, but because of things like
enrolments in courses that is hard. It is only two clicks to go to the
context, then click the right link in the settings block there.

I also re-orderd some of the code in check.php to try to get all the DB
code before all the output code.
This commit is contained in:
Tim Hunt
2012-07-13 15:23:18 +01:00
parent 9a7c3d5fea
commit d8f23e09f2
3 changed files with 88 additions and 5 deletions
+56
View File
@@ -2981,6 +2981,53 @@ function get_user_roles(context $context, $userid = 0, $checkparentcontexts = tr
return $DB->get_records_sql($sql ,$params);
}
/**
* Like get_user_roles, but adds in the authenticated user role, and the front
* page roles, if applicable.
*
* @param context $context the context.
* @param int $userid optional. Defaults to $USER->id
* @return array of objects with fields ->userid, ->contextid and ->roleid.
*/
function get_user_roles_with_special(context $context, $userid = 0) {
global $CFG, $USER;
if (empty($userid)) {
if (empty($USER->id)) {
return array();
}
$userid = $USER->id;
}
$ras = get_user_roles($context, $userid);
// Add front-page role if relevant.
$defaultfrontpageroleid = isset($CFG->defaultfrontpageroleid) ? $CFG->defaultfrontpageroleid : 0;
$isfrontpage = ($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID) ||
is_inside_frontpage($context);
if ($defaultfrontpageroleid && $isfrontpage) {
$frontpagecontext = context_course::instance(SITEID);
$ra = new stdClass();
$ra->userid = $userid;
$ra->contextid = $frontpagecontext->id;
$ra->roleid = $defaultfrontpageroleid;
$ras[] = $ra;
}
// Add authenticated user role if relevant.
$defaultuserroleid = isset($CFG->defaultuserroleid) ? $CFG->defaultuserroleid : 0;
if ($defaultuserroleid && !isguestuser($userid)) {
$systemcontext = context_system::instance();
$ra = new stdClass();
$ra->userid = $userid;
$ra->contextid = $systemcontext->id;
$ra->roleid = $defaultuserroleid;
$ras[] = $ra;
}
return $ras;
}
/**
* Creates a record in the role_allow_override table
*
@@ -4093,6 +4140,15 @@ function role_get_name($role, context_course $coursecontext) {
}
}
/**
* Get all the localised role names for a context.
* @param context $context the context
* @param array of role objects with a ->localname field containing the context-specific role name.
*/
function role_get_names(context $context) {
return role_fix_names(get_all_roles(), $context);
}
/**
* Prepare list of roles for display, apply aliases and format text
*