Fixed some issues with listing categories and other rights issues

This commit is contained in:
PMKuipers 2024-02-02 23:36:56 +01:00
parent 5a88761f22
commit 29c8dd9aa4
3 changed files with 6 additions and 8 deletions

File diff suppressed because one or more lines are too long

View file

@ -188,7 +188,7 @@ export function init(contextid,categoryid,options) {
}).catch(notification.exception); }).catch(notification.exception);
call([{ call([{
methodname: 'local_treestudyplan_map_categories', methodname: 'local_treestudyplan_map_categories',
args: {} args: { }
}])[0].then(function(response){ }])[0].then(function(response){
app.courses = response; app.courses = response;
}).catch(notification.exception); }).catch(notification.exception);

View file

@ -95,10 +95,7 @@ class courseservice extends \external_api {
public static function map_categories($rootid = 0) { public static function map_categories($rootid = 0) {
global $CFG, $DB; global $CFG, $DB;
$root = \core_course_category::get($rootid); $root = \core_course_category::get($rootid,\MUST_EXIST,true);
$context = $root->get_context();
// Make sure the user has access to the context for editing purposes.
webservicehelper::require_capabilities(self::CAP_EDIT, $context);
// Determine top categories from provided context. // Determine top categories from provided context.
@ -115,6 +112,7 @@ class courseservice extends \external_api {
$children = [$root]; $children = [$root];
} }
$list = [];
foreach ($children as $cat) { foreach ($children as $cat) {
$list[] = static::map_category($cat, false); $list[] = static::map_category($cat, false);
} }
@ -357,7 +355,7 @@ class courseservice extends \external_api {
if ($ctx->contextlevel == CONTEXT_SYSTEM) { if ($ctx->contextlevel == CONTEXT_SYSTEM) {
$cat = \core_course_category::top(); $cat = \core_course_category::top();
} else if ($ctx->contextlevel == CONTEXT_COURSECAT) { } else if ($ctx->contextlevel == CONTEXT_COURSECAT) {
$cat = \core_course_category::get($ctx->instanceid); $cat = \core_course_category::get($ctx->instanceid,\MUST_EXIST,true);
} }
$cats[] = $cat; $cats[] = $cat;
if ($operation == "edit" && $ctxid == $refctxid) { if ($operation == "edit" && $ctxid == $refctxid) {
@ -458,7 +456,7 @@ class courseservice extends \external_api {
if ($ctx->contextlevel == CONTEXT_SYSTEM) { if ($ctx->contextlevel == CONTEXT_SYSTEM) {
$cat = \core_course_category::top(); $cat = \core_course_category::top();
} else if ($ctx->contextlevel == CONTEXT_COURSECAT) { } else if ($ctx->contextlevel == CONTEXT_COURSECAT) {
$cat = \core_course_category::get($ctx->instanceid); $cat = \core_course_category::get($ctx->instanceid,\MUST_EXIST,true);
} }
$cats[] = $cat; $cats[] = $cat;
if ($operation == "view" && $ctxid == $refctxid) { if ($operation == "view" && $ctxid == $refctxid) {