MDL-53437 tool_lp: Hide competencies in CM edit when user cannot manage

This commit is contained in:
Frederic Massart
2016-04-18 10:58:58 +08:00
parent 286a609ff0
commit fe0ea87906
+7
View File
@@ -437,6 +437,8 @@ function tool_lp_coursemodule_standard_elements($formwrapper, $mform) {
if (!\tool_lp\api::is_enabled()) {
return;
} else if (!has_capability('tool/lp:coursecompetencymanage', $formwrapper->get_context())) {
return;
}
$mform->addElement('header', 'competenciessection', get_string('competencies', 'tool_lp'));
@@ -472,6 +474,11 @@ function tool_lp_coursemodule_edit_post_actions($data, $course) {
return $data;
}
// It seems like the form did not contain any of the form fields, we can return.
if (!isset($data->competency_rule) && !isset($data->competencies)) {
return $data;
}
// We bypass the API here and go direct to the persistent layer - because we don't want to do permission
// checks here - we need to load the real list of existing course module competencies.
$existing = \tool_lp\course_module_competency::list_course_module_competencies($data->coursemodule);