From dff98d33168c5df003b9c1bf469465bc88c8af44 Mon Sep 17 00:00:00 2001 From: Serge Gauthier Date: Wed, 30 Mar 2016 13:35:09 -0400 Subject: [PATCH] MDL-53590 tool_lp: Error when teacher view student course competencies --- admin/tool/lp/classes/api.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/admin/tool/lp/classes/api.php b/admin/tool/lp/classes/api.php index 8cc60f4a8c4..cf263967d80 100644 --- a/admin/tool/lp/classes/api.php +++ b/admin/tool/lp/classes/api.php @@ -3490,9 +3490,14 @@ class api { $uc = new user_competency($uc); } - if (!$uc || !$uc->can_read()) { - throw new required_capability_exception($uc->get_context(), 'tool/lp:usercompetencyview', 'nopermissions', ''); + $coursecontext = context_course::instance($courseid); + $capabilities = array('tool/lp:coursecompetencyview', 'tool/lp:coursecompetencymanage'); + if (!has_any_capability($capabilities, $coursecontext)) { + throw new required_capability_exception($context, 'tool/lp:coursecompetencyview', 'nopermissions', ''); + } else if (!user_competency::can_read_user_in_course($uc->get_userid(), $courseid)) { + throw new required_capability_exception($context, 'tool/lp:usercompetencyview', 'nopermissions', ''); } + // Validate the course, this will throw an exception if not valid. self::validate_course($courseid);