course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557. * Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories. * Enforce those correctly. (Note MDL 17502 is still outstanding.) * Don't screw up category sort order when you just edit name or description. * Niceties like where redirects go when you cancel or submit forms. * Make sure a global course creator can see the site admin block. * Don't allow a category to be made the child of one of its children! * General code cleanup to bring key files more in line with best pracitice. Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten. Merged from MOODLE_19_STABLE.
This commit is contained in:
@@ -5848,6 +5848,37 @@ function make_context_subobj($rec) {
|
||||
return $rec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do some basic, quick checks to see whether $rec->context looks like a
|
||||
* valid context object.
|
||||
*
|
||||
* @param object $rec a think that has a context, for example a course,
|
||||
* course category, course modules, etc.
|
||||
* @param integer $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
|
||||
* @return boolean whether $rec->context looks like the correct context object
|
||||
* for this thing.
|
||||
*/
|
||||
function is_context_subobj_valid($rec, $contextlevel) {
|
||||
return isset($rec->context) && isset($rec->context->id) &&
|
||||
isset($rec->context->path) && isset($rec->context->depth) &&
|
||||
isset($rec->context->contextlevel) && isset($rec->context->instanceid) &&
|
||||
$rec->context->contextlevel == $contextlevel && $rec->context->instanceid == $rec->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* When you have a record (for example a $category, $course, $user or $cm that may,
|
||||
* or may not, have come from a place that does make_context_subobj, you can use
|
||||
* this method to ensure that $rec->context is present and correct before you continue.
|
||||
*
|
||||
* @param object $rec a thing that has an associated context.
|
||||
* @param integer $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
|
||||
*/
|
||||
function ensure_context_subobj_present(&$rec, $contextlevel) {
|
||||
if (!is_context_subobj_valid($rec, $contextlevel)) {
|
||||
$rec->context = get_context_instance($contextlevel, $rec->id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch recent dirty contexts to know cheaply whether our $USER->access
|
||||
* is stale and needs to be reloaded.
|
||||
|
||||
Reference in New Issue
Block a user