MDL-53483 tool_lp: Normalise the names of capabilities

This commit is contained in:
Serge Gauthier 2016-03-24 10:52:05 -04:00 committed by Frederic Massart
parent a4f1b030f2
commit 44e8cba48e
20 changed files with 202 additions and 170 deletions

View file

@ -401,7 +401,7 @@ class api {
/** /**
* Read a the details for a single competency and return a record. * Read a the details for a single competency and return a record.
* *
* Requires tool/lp:competencyread capability at the system context. * Requires tool/lp:competencyview capability at the system context.
* *
* @param int $id The id of the competency to read. * @param int $id The id of the competency to read.
* @param bool $includerelated Include related tags or not. * @param bool $includerelated Include related tags or not.
@ -413,8 +413,8 @@ class api {
// First we do a permissions check. // First we do a permissions check.
$context = $competency->get_context(); $context = $competency->get_context();
if (!has_any_capability(array('tool/lp:competencyread', 'tool/lp:competencymanage'), $context)) { if (!has_any_capability(array('tool/lp:competencyview', 'tool/lp:competencymanage'), $context)) {
throw new required_capability_exception($context, 'tool/lp:competencyread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:competencyview', 'nopermissions', '');
} }
// OK - all set. // OK - all set.
@ -431,7 +431,7 @@ class api {
/** /**
* Perform a text search based and return all results and their parents. * Perform a text search based and return all results and their parents.
* *
* Requires tool/lp:competencyread capability at the framework context. * Requires tool/lp:competencyview capability at the framework context.
* *
* @param string $textsearch A string to search for. * @param string $textsearch A string to search for.
* @param int $competencyframeworkid The id of the framework to limit the search. * @param int $competencyframeworkid The id of the framework to limit the search.
@ -443,8 +443,8 @@ class api {
// First we do a permissions check. // First we do a permissions check.
$context = $framework->get_context(); $context = $framework->get_context();
if (!has_any_capability(array('tool/lp:competencyread', 'tool/lp:competencymanage'), $context)) { if (!has_any_capability(array('tool/lp:competencyview', 'tool/lp:competencymanage'), $context)) {
throw new required_capability_exception($context, 'tool/lp:competencyread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:competencyview', 'nopermissions', '');
} }
// OK - all set. // OK - all set.
@ -455,7 +455,7 @@ class api {
/** /**
* Perform a search based on the provided filters and return a paginated list of records. * Perform a search based on the provided filters and return a paginated list of records.
* *
* Requires tool/lp:competencyread capability at some context. * Requires tool/lp:competencyview capability at some context.
* *
* @param array $filters A list of filters to apply to the list. * @param array $filters A list of filters to apply to the list.
* @param string $sort The column to sort on * @param string $sort The column to sort on
@ -474,8 +474,8 @@ class api {
} }
// First we do a permissions check. // First we do a permissions check.
if (!has_any_capability(array('tool/lp:competencyread', 'tool/lp:competencymanage'), $context)) { if (!has_any_capability(array('tool/lp:competencyview', 'tool/lp:competencymanage'), $context)) {
throw new required_capability_exception($context, 'tool/lp:competencyread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:competencyview', 'nopermissions', '');
} }
// OK - all set. // OK - all set.
@ -485,7 +485,7 @@ class api {
/** /**
* Perform a search based on the provided filters and return a paginated list of records. * Perform a search based on the provided filters and return a paginated list of records.
* *
* Requires tool/lp:competencyread capability at some context. * Requires tool/lp:competencyview capability at some context.
* *
* @param array $filters A list of filters to apply to the list. * @param array $filters A list of filters to apply to the list.
* @return int * @return int
@ -500,8 +500,8 @@ class api {
} }
// First we do a permissions check. // First we do a permissions check.
if (!has_any_capability(array('tool/lp:competencyread', 'tool/lp:competencymanage'), $context)) { if (!has_any_capability(array('tool/lp:competencyview', 'tool/lp:competencymanage'), $context)) {
throw new required_capability_exception($context, 'tool/lp:competencyread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:competencyview', 'nopermissions', '');
} }
// OK - all set. // OK - all set.
@ -691,7 +691,7 @@ class api {
/** /**
* Read a the details for a single competency framework and return a record. * Read a the details for a single competency framework and return a record.
* *
* Requires tool/lp:competencyread capability at the system context. * Requires tool/lp:competencyview capability at the system context.
* *
* @param int $id The id of the framework to read. * @param int $id The id of the framework to read.
* @return competency_framework * @return competency_framework
@ -699,8 +699,8 @@ class api {
public static function read_framework($id) { public static function read_framework($id) {
static::require_enabled(); static::require_enabled();
$framework = new competency_framework($id); $framework = new competency_framework($id);
if (!has_any_capability(array('tool/lp:competencyread', 'tool/lp:competencymanage'), $framework->get_context())) { if (!has_any_capability(array('tool/lp:competencyview', 'tool/lp:competencymanage'), $framework->get_context())) {
throw new required_capability_exception($framework->get_context(), 'tool/lp:competencyread', 'nopermissions', ''); throw new required_capability_exception($framework->get_context(), 'tool/lp:competencyview', 'nopermissions', '');
} }
return $framework; return $framework;
} }
@ -717,8 +717,8 @@ class api {
if (!is_object($framework)) { if (!is_object($framework)) {
$framework = new competency_framework($framework); $framework = new competency_framework($framework);
} }
if (!has_any_capability(array('tool/lp:competencyread', 'tool/lp:competencymanage'), $framework->get_context())) { if (!has_any_capability(array('tool/lp:competencyview', 'tool/lp:competencymanage'), $framework->get_context())) {
throw new required_capability_exception($framework->get_context(), 'tool/lp:competencyread', 'nopermissions', ''); throw new required_capability_exception($framework->get_context(), 'tool/lp:competencyview', 'nopermissions', '');
} }
\tool_lp\event\competency_framework_viewed::create_from_framework($framework)->trigger(); \tool_lp\event\competency_framework_viewed::create_from_framework($framework)->trigger();
return true; return true;
@ -737,8 +737,8 @@ class api {
$competency = new competency($competency); $competency = new competency($competency);
} }
if (!has_any_capability(array('tool/lp:competencyread', 'tool/lp:competencymanage'), $competency->get_context())) { if (!has_any_capability(array('tool/lp:competencyview', 'tool/lp:competencymanage'), $competency->get_context())) {
throw new required_capability_exception($competency->get_context(), 'tool/lp:competencyread', 'nopermissions', ''); throw new required_capability_exception($competency->get_context(), 'tool/lp:competencyview', 'nopermissions', '');
} }
\tool_lp\event\competency_viewed::create_from_competency($competency)->trigger(); \tool_lp\event\competency_viewed::create_from_competency($competency)->trigger();
@ -748,7 +748,7 @@ class api {
/** /**
* Perform a search based on the provided filters and return a paginated list of records. * Perform a search based on the provided filters and return a paginated list of records.
* *
* Requires tool/lp:competencyread capability at the system context. * Requires tool/lp:competencyview capability at the system context.
* *
* @param string $sort The column to sort on * @param string $sort The column to sort on
* @param string $order ('ASC' or 'DESC') * @param string $order ('ASC' or 'DESC')
@ -771,10 +771,10 @@ class api {
// Get all the relevant contexts. // Get all the relevant contexts.
$contexts = self::get_related_contexts($context, $includes, $contexts = self::get_related_contexts($context, $includes,
array('tool/lp:competencyread', 'tool/lp:competencymanage')); array('tool/lp:competencyview', 'tool/lp:competencymanage'));
if (empty($contexts)) { if (empty($contexts)) {
throw new required_capability_exception($context, 'tool/lp:competencyread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:competencyview', 'nopermissions', '');
} }
// OK - all set. // OK - all set.
@ -800,7 +800,7 @@ class api {
/** /**
* Perform a search based on the provided filters and return a paginated list of records. * Perform a search based on the provided filters and return a paginated list of records.
* *
* Requires tool/lp:competencyread capability at the system context. * Requires tool/lp:competencyview capability at the system context.
* *
* @param context $context The parent context of the frameworks. * @param context $context The parent context of the frameworks.
* @param string $includes Defines what other contexts to fetch frameworks from. * @param string $includes Defines what other contexts to fetch frameworks from.
@ -816,10 +816,10 @@ class api {
// Get all the relevant contexts. // Get all the relevant contexts.
$contexts = self::get_related_contexts($context, $includes, $contexts = self::get_related_contexts($context, $includes,
array('tool/lp:competencyread', 'tool/lp:competencymanage')); array('tool/lp:competencyview', 'tool/lp:competencymanage'));
if (empty($contexts)) { if (empty($contexts)) {
throw new required_capability_exception($context, 'tool/lp:competencyread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:competencyview', 'nopermissions', '');
} }
// OK - all set. // OK - all set.
@ -909,7 +909,7 @@ class api {
} }
$context = context_course::instance($course->id); $context = context_course::instance($course->id);
$capabilities = array('tool/lp:coursecompetencyread', 'tool/lp:coursecompetencymanage'); $capabilities = array('tool/lp:coursecompetencyview', 'tool/lp:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) { if (!has_any_capability($capabilities, $context)) {
continue; continue;
} }
@ -936,9 +936,9 @@ class api {
$coursecontext = context_course::instance($courseid); $coursecontext = context_course::instance($courseid);
// We will not check each module - course permissions should be enough. // We will not check each module - course permissions should be enough.
$capabilities = array('tool/lp:coursecompetencyread', 'tool/lp:coursecompetencymanage'); $capabilities = array('tool/lp:coursecompetencyview', 'tool/lp:coursecompetencymanage');
if (!has_any_capability($capabilities, $coursecontext)) { if (!has_any_capability($capabilities, $coursecontext)) {
throw new required_capability_exception($coursecontext, 'tool/lp:coursecompetencyread', 'nopermissions', ''); throw new required_capability_exception($coursecontext, 'tool/lp:coursecompetencyview', 'nopermissions', '');
} }
$cmlist = course_module_competency::list_course_modules($competencyid, $courseid); $cmlist = course_module_competency::list_course_modules($competencyid, $courseid);
@ -968,9 +968,9 @@ class api {
self::validate_course_module($cm); self::validate_course_module($cm);
$context = context_module::instance($cm->id); $context = context_module::instance($cm->id);
$capabilities = array('tool/lp:coursecompetencyread', 'tool/lp:coursecompetencymanage'); $capabilities = array('tool/lp:coursecompetencyview', 'tool/lp:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) { if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'tool/lp:coursecompetencyread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:coursecompetencyview', 'nopermissions', '');
} }
$result = array(); $result = array();
@ -999,7 +999,7 @@ class api {
// Now check permissions on each course. // Now check permissions on each course.
foreach ($courses as $id => $course) { foreach ($courses as $id => $course) {
$context = context_course::instance($course->id); $context = context_course::instance($course->id);
$capabilities = array('tool/lp:coursecompetencyread', 'tool/lp:coursecompetencymanage'); $capabilities = array('tool/lp:coursecompetencyview', 'tool/lp:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) { if (!has_any_capability($capabilities, $context)) {
unset($courses[$id]); unset($courses[$id]);
continue; continue;
@ -1028,9 +1028,9 @@ class api {
// First we do a permissions check. // First we do a permissions check.
$context = context_course::instance($courseid); $context = context_course::instance($courseid);
$capabilities = array('tool/lp:coursecompetencyread', 'tool/lp:coursecompetencymanage'); $capabilities = array('tool/lp:coursecompetencyview', 'tool/lp:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) { if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'tool/lp:coursecompetencyread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:coursecompetencyview', 'nopermissions', '');
} }
// OK - all set. // OK - all set.
@ -1057,9 +1057,9 @@ class api {
self::validate_course($course); self::validate_course($course);
$context = context_course::instance($course->id); $context = context_course::instance($course->id);
$capabilities = array('tool/lp:coursecompetencyread', 'tool/lp:coursecompetencymanage'); $capabilities = array('tool/lp:coursecompetencyview', 'tool/lp:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) { if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'tool/lp:coursecompetencyread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:coursecompetencyview', 'nopermissions', '');
} }
$result = array(); $result = array();
@ -1137,9 +1137,9 @@ class api {
self::validate_course_module($cm); self::validate_course_module($cm);
$context = context_module::instance($cm->id); $context = context_module::instance($cm->id);
$capabilities = array('tool/lp:coursecompetencyread', 'tool/lp:coursecompetencymanage'); $capabilities = array('tool/lp:coursecompetencyview', 'tool/lp:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) { if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'tool/lp:coursecompetencyread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:coursecompetencyview', 'nopermissions', '');
} }
$result = array(); $result = array();
@ -1172,9 +1172,9 @@ class api {
// First we do a permissions check. // First we do a permissions check.
$context = context_course::instance($courseid); $context = context_course::instance($courseid);
$capabilities = array('tool/lp:coursecompetencyread', 'tool/lp:coursecompetencymanage'); $capabilities = array('tool/lp:coursecompetencyview', 'tool/lp:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) { if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'tool/lp:coursecompetencyread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:coursecompetencyview', 'nopermissions', '');
} else if (!user_competency::can_read_user_in_course($userid, $courseid)) { } else if (!user_competency::can_read_user_in_course($userid, $courseid)) {
throw new required_capability_exception($context, 'tool/lp:usercompetencyview', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:usercompetencyview', 'nopermissions', '');
} }
@ -1208,9 +1208,9 @@ class api {
$context = context_course::instance($courseid); $context = context_course::instance($courseid);
$onlyvisible = 1; $onlyvisible = 1;
$capabilities = array('tool/lp:coursecompetencyread', 'tool/lp:coursecompetencymanage'); $capabilities = array('tool/lp:coursecompetencyview', 'tool/lp:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) { if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'tool/lp:coursecompetencyread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:coursecompetencyview', 'nopermissions', '');
} else if (!user_competency::can_read_user_in_course($userid, $courseid)) { } else if (!user_competency::can_read_user_in_course($userid, $courseid)) {
throw new required_capability_exception($context, 'tool/lp:usercompetencyview', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:usercompetencyview', 'nopermissions', '');
} }
@ -1836,7 +1836,7 @@ class api {
/** /**
* Read a the details for a single learning plan template and return a record. * Read a the details for a single learning plan template and return a record.
* *
* Requires tool/lp:templateread capability at the system context. * Requires tool/lp:templateview capability at the system context.
* *
* @param int $id The id of the template to read. * @param int $id The id of the template to read.
* @return template * @return template
@ -1848,7 +1848,7 @@ class api {
// First we do a permissions check. // First we do a permissions check.
if (!$template->can_read()) { if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($template->get_context(), 'tool/lp:templateview', 'nopermissions', '');
} }
// OK - all set. // OK - all set.
@ -1858,7 +1858,7 @@ class api {
/** /**
* Perform a search based on the provided filters and return a paginated list of records. * Perform a search based on the provided filters and return a paginated list of records.
* *
* Requires tool/lp:templateread capability at the system context. * Requires tool/lp:templateview capability at the system context.
* *
* @param string $sort The column to sort on * @param string $sort The column to sort on
* @param string $order ('ASC' or 'DESC') * @param string $order ('ASC' or 'DESC')
@ -1879,11 +1879,11 @@ class api {
// Get all the relevant contexts. // Get all the relevant contexts.
$contexts = self::get_related_contexts($context, $includes, $contexts = self::get_related_contexts($context, $includes,
array('tool/lp:templateread', 'tool/lp:templatemanage')); array('tool/lp:templateview', 'tool/lp:templatemanage'));
// First we do a permissions check. // First we do a permissions check.
if (empty($contexts)) { if (empty($contexts)) {
throw new required_capability_exception($context, 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:templateview', 'nopermissions', '');
} }
// Make the order by. // Make the order by.
@ -1907,7 +1907,7 @@ class api {
/** /**
* Perform a search based on the provided filters and return how many results there are. * Perform a search based on the provided filters and return how many results there are.
* *
* Requires tool/lp:templateread capability at the system context. * Requires tool/lp:templateview capability at the system context.
* *
* @param context $context The parent context of the frameworks. * @param context $context The parent context of the frameworks.
* @param string $includes Defines what other contexts to fetch frameworks from. * @param string $includes Defines what other contexts to fetch frameworks from.
@ -1923,10 +1923,10 @@ class api {
// First we do a permissions check. // First we do a permissions check.
$contexts = self::get_related_contexts($context, $includes, $contexts = self::get_related_contexts($context, $includes,
array('tool/lp:templateread', 'tool/lp:templatemanage')); array('tool/lp:templateview', 'tool/lp:templatemanage'));
if (empty($contexts)) { if (empty($contexts)) {
throw new required_capability_exception($context, 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:templateview', 'nopermissions', '');
} }
// OK - all set. // OK - all set.
@ -1947,9 +1947,9 @@ class api {
$context = context_system::instance(); $context = context_system::instance();
$onlyvisible = 1; $onlyvisible = 1;
$capabilities = array('tool/lp:templateread', 'tool/lp:templatemanage'); $capabilities = array('tool/lp:templateview', 'tool/lp:templatemanage');
if (!has_any_capability($capabilities, $context)) { if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:templateview', 'nopermissions', '');
} }
if (has_capability('tool/lp:templatemanage', $context)) { if (has_capability('tool/lp:templatemanage', $context)) {
@ -1972,9 +1972,9 @@ class api {
$context = context_system::instance(); $context = context_system::instance();
$onlyvisible = 1; $onlyvisible = 1;
$capabilities = array('tool/lp:templateread', 'tool/lp:templatemanage'); $capabilities = array('tool/lp:templateview', 'tool/lp:templatemanage');
if (!has_any_capability($capabilities, $context)) { if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:templateview', 'nopermissions', '');
} }
if (has_capability('tool/lp:templatemanage', $context)) { if (has_capability('tool/lp:templatemanage', $context)) {
@ -2001,7 +2001,7 @@ class api {
} }
if (!$template->can_read()) { if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($template->get_context(), 'tool/lp:templateview', 'nopermissions', '');
} }
// OK - all set. // OK - all set.
@ -2022,7 +2022,7 @@ class api {
} }
if (!$template->can_read()) { if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($template->get_context(), 'tool/lp:templateview', 'nopermissions', '');
} }
// OK - all set. // OK - all set.
@ -2044,7 +2044,7 @@ class api {
} }
if (!$template->can_read()) { if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($template->get_context(), 'tool/lp:templateview', 'nopermissions', '');
} }
// OK - all set. // OK - all set.
@ -2409,7 +2409,7 @@ class api {
// The user must be able to view the template to use it as a base for a plan. // The user must be able to view the template to use it as a base for a plan.
if (!$template->can_read()) { if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($template->get_context(), 'tool/lp:templateview', 'nopermissions', '');
} }
// Can not create plan from a hidden template. // Can not create plan from a hidden template.
if ($template->get_visible() == false) { if ($template->get_visible() == false) {
@ -2475,7 +2475,7 @@ class api {
// The user must be able to view the template to use it as a base for a plan. // The user must be able to view the template to use it as a base for a plan.
if (!$template->can_read()) { if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($template->get_context(), 'tool/lp:templateview', 'nopermissions', '');
} }
// Can not create plan from a hidden template. // Can not create plan from a hidden template.
@ -3326,7 +3326,7 @@ class api {
$context = context_user::instance($userid); $context = context_user::instance($userid);
$uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid)); $uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
if (!$uc || !$uc->can_read()) { if (!$uc || !$uc->can_read()) {
throw new required_capability_exception($context, 'tool/lp:usercompetencyread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:usercompetencyview', 'nopermissions', '');
} else if ($uc->get_status() != user_competency::STATUS_WAITING_FOR_REVIEW) { } else if ($uc->get_status() != user_competency::STATUS_WAITING_FOR_REVIEW) {
throw new coding_exception('The competency can not be cancel review request at this stage.'); throw new coding_exception('The competency can not be cancel review request at this stage.');
} else if (!$uc->can_request_review()) { } else if (!$uc->can_request_review()) {
@ -3357,7 +3357,7 @@ class api {
} }
if (!$uc->can_read()) { if (!$uc->can_read()) {
throw new required_capability_exception($uc->get_context(), 'tool/lp:usercompetencyread', 'nopermissions', ''); throw new required_capability_exception($uc->get_context(), 'tool/lp:usercompetencyview', 'nopermissions', '');
} else if ($uc->get_status() != user_competency::STATUS_IDLE) { } else if ($uc->get_status() != user_competency::STATUS_IDLE) {
throw new coding_exception('The competency can not be sent for review at this stage.'); throw new coding_exception('The competency can not be sent for review at this stage.');
} else if (!$uc->can_request_review()) { } else if (!$uc->can_request_review()) {
@ -3386,7 +3386,7 @@ class api {
$context = context_user::instance($userid); $context = context_user::instance($userid);
$uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid)); $uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
if (!$uc || !$uc->can_read()) { if (!$uc || !$uc->can_read()) {
throw new required_capability_exception($context, 'tool/lp:usercompetencyread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:usercompetencyview', 'nopermissions', '');
} else if ($uc->get_status() != user_competency::STATUS_WAITING_FOR_REVIEW) { } else if ($uc->get_status() != user_competency::STATUS_WAITING_FOR_REVIEW) {
throw new coding_exception('The competency review can not be started at this stage.'); throw new coding_exception('The competency review can not be started at this stage.');
} else if (!$uc->can_review()) { } else if (!$uc->can_review()) {
@ -3414,7 +3414,7 @@ class api {
$context = context_user::instance($userid); $context = context_user::instance($userid);
$uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid)); $uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
if (!$uc || !$uc->can_read()) { if (!$uc || !$uc->can_read()) {
throw new required_capability_exception($context, 'tool/lp:usercompetencyread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:usercompetencyview', 'nopermissions', '');
} else if ($uc->get_status() != user_competency::STATUS_IN_REVIEW) { } else if ($uc->get_status() != user_competency::STATUS_IN_REVIEW) {
throw new coding_exception('The competency review can not be stopped at this stage.'); throw new coding_exception('The competency review can not be stopped at this stage.');
} else if (!$uc->can_review()) { } else if (!$uc->can_review()) {
@ -3443,7 +3443,7 @@ class api {
} }
if (!$uc || !$uc->can_read()) { if (!$uc || !$uc->can_read()) {
throw new required_capability_exception($uc->get_context(), 'tool/lp:usercompetencyread', 'nopermissions', ''); throw new required_capability_exception($uc->get_context(), 'tool/lp:usercompetencyview', 'nopermissions', '');
} }
\tool_lp\event\user_competency_viewed::create_from_user_competency_viewed($uc)->trigger(); \tool_lp\event\user_competency_viewed::create_from_user_competency_viewed($uc)->trigger();
@ -3465,7 +3465,7 @@ class api {
} }
if (!$uc || !$uc->can_read()) { if (!$uc || !$uc->can_read()) {
throw new required_capability_exception($uc->get_context(), 'tool/lp:usercompetencyread', 'nopermissions', ''); throw new required_capability_exception($uc->get_context(), 'tool/lp:usercompetencyview', 'nopermissions', '');
} }
$plan = new plan($planid); $plan = new plan($planid);
if ($plan->get_status() == plan::STATUS_COMPLETE) { if ($plan->get_status() == plan::STATUS_COMPLETE) {
@ -3491,7 +3491,7 @@ class api {
} }
if (!$uc || !$uc->can_read()) { if (!$uc || !$uc->can_read()) {
throw new required_capability_exception($uc->get_context(), 'tool/lp:usercompetencyread', 'nopermissions', ''); throw new required_capability_exception($uc->get_context(), 'tool/lp:usercompetencyview', 'nopermissions', '');
} }
// Validate the course, this will throw an exception if not valid. // Validate the course, this will throw an exception if not valid.
self::validate_course($courseid); self::validate_course($courseid);
@ -3514,7 +3514,7 @@ class api {
} }
if (!$ucp || !user_competency::can_read_user($ucp->get_userid())) { if (!$ucp || !user_competency::can_read_user($ucp->get_userid())) {
throw new required_capability_exception($ucp->get_context(), 'tool/lp:usercompetencyread', 'nopermissions', ''); throw new required_capability_exception($ucp->get_context(), 'tool/lp:usercompetencyview', 'nopermissions', '');
} }
$plan = new plan($ucp->get_planid()); $plan = new plan($ucp->get_planid());
if ($plan->get_status() != plan::STATUS_COMPLETE) { if ($plan->get_status() != plan::STATUS_COMPLETE) {
@ -3538,7 +3538,7 @@ class api {
$template = new template($templateid); $template = new template($templateid);
if (!$template->can_read()) { if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($template->get_context(), 'tool/lp:templateview', 'nopermissions', '');
} }
// OK - all set. // OK - all set.
@ -3555,8 +3555,8 @@ class api {
static::require_enabled(); static::require_enabled();
$competency = new competency($competencyid); $competency = new competency($competencyid);
if (!has_any_capability(array('tool/lp:competencyread', 'tool/lp:competencymanage'), $competency->get_context())) { if (!has_any_capability(array('tool/lp:competencyview', 'tool/lp:competencymanage'), $competency->get_context())) {
throw new required_capability_exception($competency->get_context(), 'tool/lp:competencyread', 'nopermissions', ''); throw new required_capability_exception($competency->get_context(), 'tool/lp:competencyview', 'nopermissions', '');
} }
return $competency->get_related_competencies(); return $competency->get_related_competencies();
@ -3620,7 +3620,7 @@ class api {
if (!$userevidence->can_read()) { if (!$userevidence->can_read()) {
$context = $userevidence->get_context(); $context = $userevidence->get_context();
throw new required_capability_exception($context, 'tool/lp:userevidenceread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:userevidenceview', 'nopermissions', '');
} }
return $userevidence; return $userevidence;
@ -3736,7 +3736,7 @@ class api {
static::require_enabled(); static::require_enabled();
if (!user_evidence::can_read_user($userid)) { if (!user_evidence::can_read_user($userid)) {
$context = context_user::instance($userid); $context = context_user::instance($userid);
throw new required_capability_exception($context, 'tool/lp:userevidenceread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:userevidenceview', 'nopermissions', '');
} }
$evidence = user_evidence::get_records(array('userid' => $userid), 'name'); $evidence = user_evidence::get_records(array('userid' => $userid), 'name');
@ -4545,8 +4545,8 @@ class api {
// Throws exception if competency not in plan. // Throws exception if competency not in plan.
$competency = $uc->get_competency(); $competency = $uc->get_competency();
$competencycontext = $competency->get_context(); $competencycontext = $competency->get_context();
if (!has_any_capability(array('tool/lp:competencyread', 'tool/lp:competencymanage'), $competencycontext)) { if (!has_any_capability(array('tool/lp:competencyview', 'tool/lp:competencymanage'), $competencycontext)) {
throw new required_capability_exception($competencycontext, 'tool/lp:competencyread', 'nopermissions', ''); throw new required_capability_exception($competencycontext, 'tool/lp:competencyview', 'nopermissions', '');
} }
$action = evidence::ACTION_OVERRIDE; $action = evidence::ACTION_OVERRIDE;
@ -4613,8 +4613,8 @@ class api {
// Throws exception if competency not in plan. // Throws exception if competency not in plan.
$competency = $plan->get_competency($competencyid); $competency = $plan->get_competency($competencyid);
$competencycontext = $competency->get_context(); $competencycontext = $competency->get_context();
if (!has_any_capability(array('tool/lp:competencyread', 'tool/lp:competencymanage'), $competencycontext)) { if (!has_any_capability(array('tool/lp:competencyview', 'tool/lp:competencymanage'), $competencycontext)) {
throw new required_capability_exception($competencycontext, 'tool/lp:competencyread', 'nopermissions', ''); throw new required_capability_exception($competencycontext, 'tool/lp:competencyview', 'nopermissions', '');
} }
$action = evidence::ACTION_OVERRIDE; $action = evidence::ACTION_OVERRIDE;
@ -4691,8 +4691,8 @@ class api {
// Check that competency is in course and visible to the current user. // Check that competency is in course and visible to the current user.
$competency = course_competency::get_competency($course->id, $competencyid); $competency = course_competency::get_competency($course->id, $competencyid);
$competencycontext = $competency->get_context(); $competencycontext = $competency->get_context();
if (!has_any_capability(array('tool/lp:competencyread', 'tool/lp:competencymanage'), $competencycontext)) { if (!has_any_capability(array('tool/lp:competencyview', 'tool/lp:competencymanage'), $competencycontext)) {
throw new required_capability_exception($competencycontext, 'tool/lp:competencyread', 'nopermissions', ''); throw new required_capability_exception($competencycontext, 'tool/lp:competencyview', 'nopermissions', '');
} }
// Check that the user is enrolled in the course, and is "gradable". // Check that the user is enrolled in the course, and is "gradable".
@ -4738,7 +4738,7 @@ class api {
/** /**
* Count the plans in the template, filtered by status. * Count the plans in the template, filtered by status.
* *
* Requires tool/lp:templateread capability at the system context. * Requires tool/lp:templateview capability at the system context.
* *
* @param mixed $templateorid The id or the template. * @param mixed $templateorid The id or the template.
* @param int $status One of the plan status constants (or 0 for all plans). * @param int $status One of the plan status constants (or 0 for all plans).
@ -4752,7 +4752,7 @@ class api {
// First we do a permissions check. // First we do a permissions check.
if (!$template->can_read()) { if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($template->get_context(), 'tool/lp:templateview', 'nopermissions', '');
} }
return plan::count_records_for_template($template->get_id(), $status); return plan::count_records_for_template($template->get_id(), $status);
@ -4761,7 +4761,7 @@ class api {
/** /**
* Count the user-completency-plans in the template, optionally filtered by proficiency. * Count the user-completency-plans in the template, optionally filtered by proficiency.
* *
* Requires tool/lp:templateread capability at the system context. * Requires tool/lp:templateview capability at the system context.
* *
* @param mixed $templateorid The id or the template. * @param mixed $templateorid The id or the template.
* @param mixed $proficiency If true, filter by proficiency, if false filter by not proficient, if null - no filter. * @param mixed $proficiency If true, filter by proficiency, if false filter by not proficient, if null - no filter.
@ -4775,7 +4775,7 @@ class api {
// First we do a permissions check. // First we do a permissions check.
if (!$template->can_read()) { if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($template->get_context(), 'tool/lp:templateview', 'nopermissions', '');
} }
return user_competency_plan::count_records_for_template($template->get_id(), $proficiency); return user_competency_plan::count_records_for_template($template->get_id(), $proficiency);
@ -4784,7 +4784,7 @@ class api {
/** /**
* List the plans in the template, filtered by status. * List the plans in the template, filtered by status.
* *
* Requires tool/lp:templateread capability at the system context. * Requires tool/lp:templateview capability at the system context.
* *
* @param mixed $templateorid The id or the template. * @param mixed $templateorid The id or the template.
* @param int $status One of the plan status constants (or 0 for all plans). * @param int $status One of the plan status constants (or 0 for all plans).
@ -4800,7 +4800,7 @@ class api {
// First we do a permissions check. // First we do a permissions check.
if (!$template->can_read()) { if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($template->get_context(), 'tool/lp:templateview', 'nopermissions', '');
} }
return plan::get_records_for_template($template->get_id(), $status, $skip, $limit); return plan::get_records_for_template($template->get_id(), $status, $skip, $limit);
@ -4809,7 +4809,7 @@ class api {
/** /**
* Get the most often not completed competency for this template. * Get the most often not completed competency for this template.
* *
* Requires tool/lp:templateread capability at the system context. * Requires tool/lp:templateview capability at the system context.
* *
* @param mixed $templateorid The id or the template. * @param mixed $templateorid The id or the template.
* @param int $skip The number of records to skip * @param int $skip The number of records to skip
@ -4824,7 +4824,7 @@ class api {
// First we do a permissions check. // First we do a permissions check.
if (!$template->can_read()) { if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($template->get_context(), 'tool/lp:templateview', 'nopermissions', '');
} }
return user_competency_plan::get_least_proficient_competencies_for_template($template->get_id(), $skip, $limit); return user_competency_plan::get_least_proficient_competencies_for_template($template->get_id(), $skip, $limit);
@ -4833,7 +4833,7 @@ class api {
/** /**
* Template event viewed. * Template event viewed.
* *
* Requires tool/lp:templateread capability at the system context. * Requires tool/lp:templateview capability at the system context.
* *
* @param mixed $templateorid The id or the template. * @param mixed $templateorid The id or the template.
* @return boolean * @return boolean
@ -4847,7 +4847,7 @@ class api {
// First we do a permissions check. // First we do a permissions check.
if (!$template->can_read()) { if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($template->get_context(), 'tool/lp:templateview', 'nopermissions', '');
} }
// Trigger a template viewed event. // Trigger a template viewed event.

View file

@ -106,7 +106,7 @@ class framework_autocomplete extends MoodleQuickForm_autocomplete {
list($insql, $inparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'param'); list($insql, $inparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'param');
$frameworks = competency_framework::get_records_select("id $insql", $inparams, 'shortname'); $frameworks = competency_framework::get_records_select("id $insql", $inparams, 'shortname');
foreach ($frameworks as $framework) { foreach ($frameworks as $framework) {
if (!has_any_capability(array('tool/lp:competencyread', 'tool/lp:competencymanage'), $framework->get_context())) { if (!has_any_capability(array('tool/lp:competencyview', 'tool/lp:competencymanage'), $framework->get_context())) {
continue; continue;
} else if ($this->onlyvisible && !$framework->get_visible()) { } else if ($this->onlyvisible && !$framework->get_visible()) {
continue; continue;

View file

@ -62,7 +62,7 @@ class template_cohorts_table extends table_sql {
// This object should not be used without the right permissions. // This object should not be used without the right permissions.
if (!$template->can_read()) { if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($template->get_context(), 'tool/lp:templateview', 'nopermissions', '');
} }
// Set protected properties. // Set protected properties.

View file

@ -62,7 +62,7 @@ class template_plans_table extends table_sql {
// This object should not be used without the right permissions. // This object should not be used without the right permissions.
if (!$template->can_read()) { if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($template->get_context(), 'tool/lp:templateview', 'nopermissions', '');
} }
// Set protected properties. // Set protected properties.

View file

@ -133,7 +133,7 @@ class template extends persistent {
* @return bool * @return bool
*/ */
public static function can_read_context($context) { public static function can_read_context($context) {
return has_capability('tool/lp:templateread', $context) || self::can_manage_context($context); return has_capability('tool/lp:templateview', $context) || self::can_manage_context($context);
} }
/** /**

View file

@ -187,7 +187,7 @@ class user_evidence extends persistent {
public static function can_read_user($evidenceuserid) { public static function can_read_user($evidenceuserid) {
$context = context_user::instance($evidenceuserid); $context = context_user::instance($evidenceuserid);
$capabilities = array('tool/lp:userevidenceread'); $capabilities = array('tool/lp:userevidenceview');
return has_any_capability($capabilities, $context) || self::can_manage_user($evidenceuserid); return has_any_capability($capabilities, $context) || self::can_manage_user($evidenceuserid);
} }

View file

@ -36,7 +36,7 @@ $capabilities = array(
'manager' => CAP_ALLOW 'manager' => CAP_ALLOW
) )
), ),
'tool/lp:competencyread' => array( 'tool/lp:competencyview' => array(
'captype' => 'read', 'captype' => 'read',
'contextlevel' => CONTEXT_COURSECAT, 'contextlevel' => CONTEXT_COURSECAT,
'archetypes' => array( 'archetypes' => array(
@ -78,7 +78,7 @@ $capabilities = array(
), ),
'clonepermissionsfrom' => 'moodle/course:isincompletionreports' 'clonepermissionsfrom' => 'moodle/course:isincompletionreports'
), ),
'tool/lp:coursecompetencyread' => array( 'tool/lp:coursecompetencyview' => array(
'captype' => 'read', 'captype' => 'read',
'contextlevel' => CONTEXT_COURSE, 'contextlevel' => CONTEXT_COURSE,
'archetypes' => array( 'archetypes' => array(
@ -229,7 +229,7 @@ $capabilities = array(
), ),
'clonepermissionsfrom' => 'moodle/site:config' 'clonepermissionsfrom' => 'moodle/site:config'
), ),
'tool/lp:templateread' => array( 'tool/lp:templateview' => array(
'captype' => 'read', 'captype' => 'read',
'contextlevel' => CONTEXT_COURSECAT, 'contextlevel' => CONTEXT_COURSECAT,
'archetypes' => array( 'archetypes' => array(
@ -252,7 +252,7 @@ $capabilities = array(
), ),
'clonepermissionsfrom' => 'moodle/block:view' 'clonepermissionsfrom' => 'moodle/block:view'
), ),
'tool/lp:userevidenceread' => array( 'tool/lp:userevidenceview' => array(
'captype' => 'read', 'captype' => 'read',
'contextlevel' => CONTEXT_USER, 'contextlevel' => CONTEXT_USER,
'archetypes' => array( 'archetypes' => array(

View file

@ -45,7 +45,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load a summary of a competency framework.', 'description' => 'Load a summary of a competency framework.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:competencyread', 'capabilities' => 'tool/lp:competencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_duplicate_competency_framework' => array( 'tool_lp_duplicate_competency_framework' => array(
@ -81,7 +81,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load a list of a competency frameworks.', 'description' => 'Load a list of a competency frameworks.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:competencyread', 'capabilities' => 'tool/lp:competencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_count_competency_frameworks' => array( 'tool_lp_count_competency_frameworks' => array(
@ -90,7 +90,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Count a list of a competency frameworks.', 'description' => 'Count a list of a competency frameworks.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:competencyread', 'capabilities' => 'tool/lp:competencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_competency_framework_viewed' => array( 'tool_lp_competency_framework_viewed' => array(
@ -99,7 +99,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Log event competency framework viewed', 'description' => 'Log event competency framework viewed',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:competencyread', 'capabilities' => 'tool/lp:competencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_data_for_competency_frameworks_manage_page' => array( 'tool_lp_data_for_competency_frameworks_manage_page' => array(
@ -108,7 +108,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load the data for the competency frameworks manage page template', 'description' => 'Load the data for the competency frameworks manage page template',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:competencyread', 'capabilities' => 'tool/lp:competencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_create_competency' => array( 'tool_lp_create_competency' => array(
@ -126,7 +126,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load a summary of a competency.', 'description' => 'Load a summary of a competency.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:competencyread', 'capabilities' => 'tool/lp:competencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_competency_viewed' => array( 'tool_lp_competency_viewed' => array(
@ -135,7 +135,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Log event competency viewed', 'description' => 'Log event competency viewed',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:competencyread', 'capabilities' => 'tool/lp:competencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_delete_competency' => array( 'tool_lp_delete_competency' => array(
@ -162,7 +162,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load competency data for summary template.', 'description' => 'Load competency data for summary template.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:competencyread', 'capabilities' => 'tool/lp:competencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_list_competencies' => array( 'tool_lp_list_competencies' => array(
@ -171,7 +171,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load a list of a competencies.', 'description' => 'Load a list of a competencies.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:competencyread', 'capabilities' => 'tool/lp:competencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_list_competencies_in_template' => array( 'tool_lp_list_competencies_in_template' => array(
@ -180,7 +180,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load a list of a competencies for a given template.', 'description' => 'Load a list of a competencies for a given template.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:competencyread', 'capabilities' => 'tool/lp:competencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_count_competencies' => array( 'tool_lp_count_competencies' => array(
@ -189,7 +189,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Count a list of a competencies.', 'description' => 'Count a list of a competencies.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:competencyread', 'capabilities' => 'tool/lp:competencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_count_competencies_in_template' => array( 'tool_lp_count_competencies_in_template' => array(
@ -198,7 +198,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Count a list of a competencies for a given template.', 'description' => 'Count a list of a competencies for a given template.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:competencyread', 'capabilities' => 'tool/lp:competencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_search_competencies' => array( 'tool_lp_search_competencies' => array(
@ -207,7 +207,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Search a list of a competencies.', 'description' => 'Search a list of a competencies.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:competencyread', 'capabilities' => 'tool/lp:competencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_data_for_competencies_manage_page' => array( 'tool_lp_data_for_competencies_manage_page' => array(
@ -216,7 +216,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load the data for the competencies manage page template', 'description' => 'Load the data for the competencies manage page template',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:competencyread', 'capabilities' => 'tool/lp:competencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_set_parent_competency' => array( 'tool_lp_set_parent_competency' => array(
@ -252,7 +252,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'List the competencies in a course', 'description' => 'List the competencies in a course',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:coursecompetencyread', 'capabilities' => 'tool/lp:coursecompetencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_list_courses_using_competency' => array( 'tool_lp_list_courses_using_competency' => array(
@ -261,7 +261,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'List the courses using a competency', 'description' => 'List the courses using a competency',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:coursecompetencyread', 'capabilities' => 'tool/lp:coursecompetencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_count_competencies_in_course' => array( 'tool_lp_count_competencies_in_course' => array(
@ -270,7 +270,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'List the competencies in a course', 'description' => 'List the competencies in a course',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:coursecompetencyread', 'capabilities' => 'tool/lp:coursecompetencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_count_courses_using_competency' => array( 'tool_lp_count_courses_using_competency' => array(
@ -279,7 +279,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'List the courses using a competency', 'description' => 'List the courses using a competency',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:coursecompetencyread', 'capabilities' => 'tool/lp:coursecompetencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_add_competency_to_course' => array( 'tool_lp_add_competency_to_course' => array(
@ -333,7 +333,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load the data for the course competencies page template.', 'description' => 'Load the data for the course competencies page template.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:coursecompetencyread', 'capabilities' => 'tool/lp:coursecompetencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_data_for_template_competencies_page' => array( 'tool_lp_data_for_template_competencies_page' => array(
@ -342,7 +342,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load the data for the template competencies page template.', 'description' => 'Load the data for the template competencies page template.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:templateread', 'capabilities' => 'tool/lp:templateview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_reorder_course_competency' => array( 'tool_lp_reorder_course_competency' => array(
@ -387,7 +387,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load a summary of a learning plan template.', 'description' => 'Load a summary of a learning plan template.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:templateread', 'capabilities' => 'tool/lp:templateview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_delete_template' => array( 'tool_lp_delete_template' => array(
@ -414,7 +414,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load a list of a learning plan templates.', 'description' => 'Load a list of a learning plan templates.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:templateread', 'capabilities' => 'tool/lp:templateview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_list_templates_using_competency' => array( 'tool_lp_list_templates_using_competency' => array(
@ -423,7 +423,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load a list of a learning plan templates for a given competency.', 'description' => 'Load a list of a learning plan templates for a given competency.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:templateread', 'capabilities' => 'tool/lp:templateview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_count_templates' => array( 'tool_lp_count_templates' => array(
@ -432,7 +432,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Count a list of a learning plan templates.', 'description' => 'Count a list of a learning plan templates.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:templateread', 'capabilities' => 'tool/lp:templateview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_count_templates_using_competency' => array( 'tool_lp_count_templates_using_competency' => array(
@ -441,7 +441,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Count a list of a learning plan templates for a given competency.', 'description' => 'Count a list of a learning plan templates for a given competency.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:templateread', 'capabilities' => 'tool/lp:templateview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_data_for_templates_manage_page' => array( 'tool_lp_data_for_templates_manage_page' => array(
@ -450,7 +450,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load the data for the learning plan templates manage page template', 'description' => 'Load the data for the learning plan templates manage page template',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:templateread', 'capabilities' => 'tool/lp:templateview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_create_plan' => array( 'tool_lp_create_plan' => array(
@ -630,7 +630,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Check if a template has related data', 'description' => 'Check if a template has related data',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:templateread', 'capabilities' => 'tool/lp:templateview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_get_scale_values' => array( 'tool_lp_get_scale_values' => array(
@ -666,7 +666,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load the data for the related competencies template.', 'description' => 'Load the data for the related competencies template.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:competencyread', 'capabilities' => 'tool/lp:competencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_search_users' => array( 'tool_lp_search_users' => array(
@ -695,7 +695,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Read an evidence of prior learning.', 'description' => 'Read an evidence of prior learning.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:userevidenceread', 'capabilities' => 'tool/lp:userevidenceview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_delete_user_evidence' => array( 'tool_lp_delete_user_evidence' => array(
@ -713,7 +713,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load the data for the user evidence list page template', 'description' => 'Load the data for the user evidence list page template',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:userevidenceread', 'capabilities' => 'tool/lp:userevidenceview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_data_for_user_evidence_page' => array( 'tool_lp_data_for_user_evidence_page' => array(
@ -722,7 +722,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load the data for the user evidence page template', 'description' => 'Load the data for the user evidence page template',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:userevidenceread', 'capabilities' => 'tool/lp:userevidenceview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_create_user_evidence_competency' => array( 'tool_lp_create_user_evidence_competency' => array(
@ -731,7 +731,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Create an evidence of prior learning relationship with a competency.', 'description' => 'Create an evidence of prior learning relationship with a competency.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:userevidencemanageown, tool/lp:competencyread', 'capabilities' => 'tool/lp:userevidencemanageown, tool/lp:competencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_delete_user_evidence_competency' => array( 'tool_lp_delete_user_evidence_competency' => array(
@ -869,7 +869,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load a summary of a user competency.', 'description' => 'Load a summary of a user competency.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:coursecompetencyread', 'capabilities' => 'tool/lp:coursecompetencyview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_unlink_plan_from_template' => array( 'tool_lp_unlink_plan_from_template' => array(
@ -887,7 +887,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Log event template viewed', 'description' => 'Log event template viewed',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:templateread', 'capabilities' => 'tool/lp:templateview',
'ajax' => true, 'ajax' => true,
), ),
'tool_lp_request_review_of_user_evidence_linked_competencies' => array( 'tool_lp_request_review_of_user_evidence_linked_competencies' => array(

View file

@ -204,10 +204,10 @@ $string['locatecompetency'] = 'Locate competency';
$string['lp:competencymanage'] = 'Manage competency frameworks'; $string['lp:competencymanage'] = 'Manage competency frameworks';
$string['lp:competencysuggestgrade'] = 'Suggest competency grade'; $string['lp:competencysuggestgrade'] = 'Suggest competency grade';
$string['lp:competencygrade'] = 'Set competency grade'; $string['lp:competencygrade'] = 'Set competency grade';
$string['lp:competencyread'] = 'View competency frameworks'; $string['lp:competencyview'] = 'View competency frameworks';
$string['lp:coursecompetencygradable'] = 'Receive competency marks'; $string['lp:coursecompetencygradable'] = 'Receive competency marks';
$string['lp:coursecompetencymanage'] = 'Manage course competencies'; $string['lp:coursecompetencymanage'] = 'Manage course competencies';
$string['lp:coursecompetencyread'] = 'View course competencies'; $string['lp:coursecompetencyview'] = 'View course competencies';
$string['lp:plancomment'] = 'Comment on a learning plan'; $string['lp:plancomment'] = 'Comment on a learning plan';
$string['lp:plancommentown'] = 'Comment on own learning plan'; $string['lp:plancommentown'] = 'Comment on own learning plan';
$string['lp:planmanage'] = 'Manage learning plans'; $string['lp:planmanage'] = 'Manage learning plans';
@ -222,7 +222,7 @@ $string['lp:planviewdraft'] = 'View draft learning plans';
$string['lp:planviewown'] = 'View own learning plans'; $string['lp:planviewown'] = 'View own learning plans';
$string['lp:planviewowndraft'] = 'View own draft learning plans'; $string['lp:planviewowndraft'] = 'View own draft learning plans';
$string['lp:templatemanage'] = 'Manage templates'; $string['lp:templatemanage'] = 'Manage templates';
$string['lp:templateread'] = 'View template'; $string['lp:templateview'] = 'View template';
$string['lp:usercompetencycomment'] = 'Comment on a user competency'; $string['lp:usercompetencycomment'] = 'Comment on a user competency';
$string['lp:usercompetencycommentown'] = 'Comment on own user competency'; $string['lp:usercompetencycommentown'] = 'Comment on own user competency';
$string['lp:usercompetencyrequestreview'] = 'Request the review of a user competency'; $string['lp:usercompetencyrequestreview'] = 'Request the review of a user competency';
@ -231,7 +231,7 @@ $string['lp:usercompetencyreview'] = 'Review a user competency';
$string['lp:usercompetencyview'] = 'View a user competency'; $string['lp:usercompetencyview'] = 'View a user competency';
$string['lp:userevidencemanage'] = 'Manage evidence of prior learning'; $string['lp:userevidencemanage'] = 'Manage evidence of prior learning';
$string['lp:userevidencemanageown'] = 'Manage own evidence of prior learning'; $string['lp:userevidencemanageown'] = 'Manage own evidence of prior learning';
$string['lp:userevidenceread'] = 'View evidence of prior learning of a user'; $string['lp:userevidenceview'] = 'View evidence of prior learning of a user';
$string['managecompetenciesandframeworks'] = 'Manage competencies and frameworks'; $string['managecompetenciesandframeworks'] = 'Manage competencies and frameworks';
$string['messageprovider:user_competency_comment'] = 'Comment posted on a competency.'; $string['messageprovider:user_competency_comment'] = 'Comment posted on a competency.';
$string['messageprovider:plan_comment'] = 'Comment posted on a learning plan.'; $string['messageprovider:plan_comment'] = 'Comment posted on a learning plan.';

View file

@ -31,7 +31,7 @@ $context = context::instance_by_id($pagecontextid);
require_login(0, false); require_login(0, false);
\tool_lp\api::require_enabled(); \tool_lp\api::require_enabled();
if (!\tool_lp\template::can_read_context($context)) { if (!\tool_lp\template::can_read_context($context)) {
throw new required_capability_exception($context, 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:templateview', 'nopermissions', '');
} }
$url = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid)); $url = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));

View file

@ -37,7 +37,7 @@ $canmanagetemplate = $template->can_manage();
$duedatereached = $template->get_duedate() > 0 && $template->get_duedate() < time(); $duedatereached = $template->get_duedate() > 0 && $template->get_duedate() < time();
if (!$canreadtemplate) { if (!$canreadtemplate) {
throw new required_capability_exception($context, 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:templateview', 'nopermissions', '');
} }
// Set up the page. // Set up the page.

View file

@ -35,7 +35,7 @@ $context = $template->get_context();
$canreadtemplate = $template->can_read(); $canreadtemplate = $template->can_read();
$canmanagetemplate = $template->can_manage(); $canmanagetemplate = $template->can_manage();
if (!$canreadtemplate) { if (!$canreadtemplate) {
throw new required_capability_exception($context, 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:templateview', 'nopermissions', '');
} }
// Set up the page. // Set up the page.

View file

@ -35,7 +35,7 @@ $pagecontext = context::instance_by_id($pagecontextid);
$template = \tool_lp\api::read_template($templateid); $template = \tool_lp\api::read_template($templateid);
$context = $template->get_context(); $context = $template->get_context();
if (!$template->can_read()) { if (!$template->can_read()) {
throw new required_capability_exception($context, 'tool/lp:templateread', 'nopermissions', ''); throw new required_capability_exception($context, 'tool/lp:templateview', 'nopermissions', '');
} }
// Trigger a template viewed event. // Trigger a template viewed event.

View file

@ -79,18 +79,18 @@ class tool_lp_api_testcase extends advanced_testcase {
$sysctx = context_system::instance(); $sysctx = context_system::instance();
$roleallow = create_role('Allow', 'allow', 'Allow read'); $roleallow = create_role('Allow', 'allow', 'Allow read');
assign_capability('tool/lp:competencyread', CAP_ALLOW, $roleallow, $sysctx->id); assign_capability('tool/lp:competencyview', CAP_ALLOW, $roleallow, $sysctx->id);
role_assign($roleallow, $user->id, $sysctx->id); role_assign($roleallow, $user->id, $sysctx->id);
$roleprevent = create_role('Prevent', 'prevent', 'Prevent read'); $roleprevent = create_role('Prevent', 'prevent', 'Prevent read');
assign_capability('tool/lp:competencyread', CAP_PROHIBIT, $roleprevent, $sysctx->id); assign_capability('tool/lp:competencyview', CAP_PROHIBIT, $roleprevent, $sysctx->id);
role_assign($roleprevent, $user->id, $cat2ctx->id); role_assign($roleprevent, $user->id, $cat2ctx->id);
accesslib_clear_all_caches_for_unit_testing(); accesslib_clear_all_caches_for_unit_testing();
$this->setUser($user); $this->setUser($user);
$this->assertFalse(has_capability('tool/lp:competencyread', $cat2ctx)); $this->assertFalse(has_capability('tool/lp:competencyview', $cat2ctx));
$requiredcap = array('tool/lp:competencyread'); $requiredcap = array('tool/lp:competencyview');
$expected = array(); $expected = array();
$this->assertEquals($expected, api::get_related_contexts($cat2ctx, 'self', $requiredcap)); $this->assertEquals($expected, api::get_related_contexts($cat2ctx, 'self', $requiredcap));
@ -140,18 +140,18 @@ class tool_lp_api_testcase extends advanced_testcase {
$sysctx = context_system::instance(); $sysctx = context_system::instance();
$roleallow = create_role('Allow', 'allow', 'Allow read'); $roleallow = create_role('Allow', 'allow', 'Allow read');
assign_capability('tool/lp:templateread', CAP_ALLOW, $roleallow, $sysctx->id); assign_capability('tool/lp:templateview', CAP_ALLOW, $roleallow, $sysctx->id);
role_assign($roleallow, $user->id, $sysctx->id); role_assign($roleallow, $user->id, $sysctx->id);
$roleprevent = create_role('Prevent', 'prevent', 'Prevent read'); $roleprevent = create_role('Prevent', 'prevent', 'Prevent read');
assign_capability('tool/lp:templateread', CAP_PROHIBIT, $roleprevent, $sysctx->id); assign_capability('tool/lp:templateview', CAP_PROHIBIT, $roleprevent, $sysctx->id);
role_assign($roleprevent, $user->id, $cat2ctx->id); role_assign($roleprevent, $user->id, $cat2ctx->id);
accesslib_clear_all_caches_for_unit_testing(); accesslib_clear_all_caches_for_unit_testing();
$this->setUser($user); $this->setUser($user);
$this->assertFalse(has_capability('tool/lp:templateread', $cat2ctx)); $this->assertFalse(has_capability('tool/lp:templateview', $cat2ctx));
$requiredcap = array('tool/lp:templateread'); $requiredcap = array('tool/lp:templateview');
$expected = array(); $expected = array();
$this->assertEquals($expected, api::get_related_contexts($cat2ctx, 'self', $requiredcap)); $this->assertEquals($expected, api::get_related_contexts($cat2ctx, 'self', $requiredcap));
@ -3973,7 +3973,7 @@ class tool_lp_api_testcase extends advanced_testcase {
assign_capability('tool/lp:usercompetencyview', CAP_ALLOW, $canviewucrole, $sysctx->id); assign_capability('tool/lp:usercompetencyview', CAP_ALLOW, $canviewucrole, $sysctx->id);
$cannotviewcomp = $dg->create_role(); $cannotviewcomp = $dg->create_role();
assign_capability('tool/lp:competencyread', CAP_PROHIBIT, $cannotviewcomp, $sysctx->id); assign_capability('tool/lp:competencyview', CAP_PROHIBIT, $cannotviewcomp, $sysctx->id);
$canmanagecomp = $dg->create_role(); $canmanagecomp = $dg->create_role();
assign_capability('tool/lp:competencymanage', CAP_ALLOW, $canmanagecomp, $sysctx->id); assign_capability('tool/lp:competencymanage', CAP_ALLOW, $canmanagecomp, $sysctx->id);

View file

@ -80,6 +80,10 @@ class behat_tool_lp_data_generators extends behat_base {
'userevidencecompetencies' => array( 'userevidencecompetencies' => array(
'datagenerator' => 'user_evidence_competency', 'datagenerator' => 'user_evidence_competency',
'required' => array('userevidence', 'competency') 'required' => array('userevidence', 'competency')
),
'usercompetencies' => array(
'datagenerator' => 'user_competency',
'required' => array('user', 'competency')
) )
); );
@ -295,4 +299,28 @@ class behat_tool_lp_data_generators extends behat_base {
return $data; return $data;
} }
/**
* Adapt creating user_evidence from user username.
*
* @param array $data
* @return array
*/
protected function preprocess_user_competency($data) {
global $DB;
if (isset($data['user'])) {
$user = $DB->get_record('user', array('username' => $data['user']), '*', MUST_EXIST);
$data['userid'] = $user->id;
}
unset($data['user']);
if (isset($data['competency'])) {
$competency = $DB->get_record('tool_lp_competency', array('shortname' => $data['competency']), '*', MUST_EXIST);
$data['competencyid'] = $competency->id;
}
unset($data['competency']);
return $data;
}
} }

View file

@ -54,6 +54,10 @@ Feature: Manage competencies linked to evidence of prior learning
| userevidence | competency | | userevidence | competency |
| Test-Evidence | Test-Comp1 | | Test-Evidence | Test-Comp1 |
| Test-Evidence | Test-Comp2 | | Test-Evidence | Test-Comp2 |
Given the following lp "usercompetencies" exist:
| user | competency |
| admin | Test-Comp1 |
| admin | Test-Comp2 |
And I follow "Evidence of prior learning" And I follow "Evidence of prior learning"
And I should see "List of evidence" And I should see "List of evidence"
And I should see "Test-Evidence" And I should see "Test-Evidence"

View file

@ -107,7 +107,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
unassign_capability('tool/lp:competencygrade', $authrole->id); unassign_capability('tool/lp:competencygrade', $authrole->id);
unassign_capability('tool/lp:competencysuggestgrade', $authrole->id); unassign_capability('tool/lp:competencysuggestgrade', $authrole->id);
unassign_capability('tool/lp:competencymanage', $authrole->id); unassign_capability('tool/lp:competencymanage', $authrole->id);
unassign_capability('tool/lp:competencyread', $authrole->id); unassign_capability('tool/lp:competencyview', $authrole->id);
unassign_capability('tool/lp:planmanage', $authrole->id); unassign_capability('tool/lp:planmanage', $authrole->id);
unassign_capability('tool/lp:planmanagedraft', $authrole->id); unassign_capability('tool/lp:planmanagedraft', $authrole->id);
unassign_capability('tool/lp:planmanageown', $authrole->id); unassign_capability('tool/lp:planmanageown', $authrole->id);
@ -116,7 +116,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
unassign_capability('tool/lp:planviewown', $authrole->id); unassign_capability('tool/lp:planviewown', $authrole->id);
unassign_capability('tool/lp:planviewowndraft', $authrole->id); unassign_capability('tool/lp:planviewowndraft', $authrole->id);
unassign_capability('tool/lp:templatemanage', $authrole->id); unassign_capability('tool/lp:templatemanage', $authrole->id);
unassign_capability('tool/lp:templateread', $authrole->id); unassign_capability('tool/lp:templateview', $authrole->id);
unassign_capability('moodle/cohort:manage', $authrole->id); unassign_capability('moodle/cohort:manage', $authrole->id);
// Creating specific roles. // Creating specific roles.
@ -124,7 +124,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$this->userrole = create_role('User role', 'userrole', 'learning plan user role description'); $this->userrole = create_role('User role', 'userrole', 'learning plan user role description');
assign_capability('tool/lp:competencymanage', CAP_ALLOW, $this->creatorrole, $syscontext->id); assign_capability('tool/lp:competencymanage', CAP_ALLOW, $this->creatorrole, $syscontext->id);
assign_capability('tool/lp:competencyread', CAP_ALLOW, $this->userrole, $syscontext->id); assign_capability('tool/lp:competencyview', CAP_ALLOW, $this->userrole, $syscontext->id);
assign_capability('tool/lp:planmanage', CAP_ALLOW, $this->creatorrole, $syscontext->id); assign_capability('tool/lp:planmanage', CAP_ALLOW, $this->creatorrole, $syscontext->id);
assign_capability('tool/lp:planmanagedraft', CAP_ALLOW, $this->creatorrole, $syscontext->id); assign_capability('tool/lp:planmanagedraft', CAP_ALLOW, $this->creatorrole, $syscontext->id);
assign_capability('tool/lp:planmanageown', CAP_ALLOW, $this->creatorrole, $syscontext->id); assign_capability('tool/lp:planmanageown', CAP_ALLOW, $this->creatorrole, $syscontext->id);
@ -134,7 +134,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
assign_capability('tool/lp:competencygrade', CAP_ALLOW, $this->creatorrole, $syscontext->id); assign_capability('tool/lp:competencygrade', CAP_ALLOW, $this->creatorrole, $syscontext->id);
assign_capability('tool/lp:competencysuggestgrade', CAP_ALLOW, $this->creatorrole, $syscontext->id); assign_capability('tool/lp:competencysuggestgrade', CAP_ALLOW, $this->creatorrole, $syscontext->id);
assign_capability('moodle/cohort:manage', CAP_ALLOW, $this->creatorrole, $syscontext->id); assign_capability('moodle/cohort:manage', CAP_ALLOW, $this->creatorrole, $syscontext->id);
assign_capability('tool/lp:templateread', CAP_ALLOW, $this->userrole, $syscontext->id); assign_capability('tool/lp:templateview', CAP_ALLOW, $this->userrole, $syscontext->id);
assign_capability('tool/lp:competencysuggestgrade', CAP_ALLOW, $this->userrole, $syscontext->id); assign_capability('tool/lp:competencysuggestgrade', CAP_ALLOW, $this->userrole, $syscontext->id);
assign_capability('tool/lp:planviewown', CAP_ALLOW, $this->userrole, $syscontext->id); assign_capability('tool/lp:planviewown', CAP_ALLOW, $this->userrole, $syscontext->id);
assign_capability('tool/lp:planviewowndraft', CAP_ALLOW, $this->userrole, $syscontext->id); assign_capability('tool/lp:planviewowndraft', CAP_ALLOW, $this->userrole, $syscontext->id);
@ -1848,10 +1848,10 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$cattemplate = $this->create_template(2, false); $cattemplate = $this->create_template(2, false);
// User without permissions to read in system. // User without permissions to read in system.
assign_capability('tool/lp:templateread', CAP_PROHIBIT, $this->userrole, $syscontextid, true); assign_capability('tool/lp:templateview', CAP_PROHIBIT, $this->userrole, $syscontextid, true);
accesslib_clear_all_caches_for_unit_testing(); accesslib_clear_all_caches_for_unit_testing();
$this->setUser($this->user); $this->setUser($this->user);
$this->assertFalse(has_capability('tool/lp:templateread', context_system::instance())); $this->assertFalse(has_capability('tool/lp:templateview', context_system::instance()));
try { try {
external::read_template($systemplate->id); external::read_template($systemplate->id);
$this->fail('Invalid permissions'); $this->fail('Invalid permissions');
@ -1866,11 +1866,11 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
} }
// User with permissions to read in a category. // User with permissions to read in a category.
assign_capability('tool/lp:templateread', CAP_PREVENT, $this->userrole, $syscontextid, true); assign_capability('tool/lp:templateview', CAP_PREVENT, $this->userrole, $syscontextid, true);
assign_capability('tool/lp:templateread', CAP_ALLOW, $this->userrole, $catcontextid, true); assign_capability('tool/lp:templateview', CAP_ALLOW, $this->userrole, $catcontextid, true);
accesslib_clear_all_caches_for_unit_testing(); accesslib_clear_all_caches_for_unit_testing();
$this->assertFalse(has_capability('tool/lp:templateread', context_system::instance())); $this->assertFalse(has_capability('tool/lp:templateview', context_system::instance()));
$this->assertTrue(has_capability('tool/lp:templateread', context_coursecat::instance($this->category->id))); $this->assertTrue(has_capability('tool/lp:templateview', context_coursecat::instance($this->category->id)));
try { try {
external::read_template($systemplate->id); external::read_template($systemplate->id);
$this->fail('Invalid permissions'); $this->fail('Invalid permissions');
@ -1889,9 +1889,9 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$this->assertEquals(userdate(0), $result['duedateformatted']); $this->assertEquals(userdate(0), $result['duedateformatted']);
// User with permissions to read in the system. // User with permissions to read in the system.
assign_capability('tool/lp:templateread', CAP_ALLOW, $this->userrole, $syscontextid, true); assign_capability('tool/lp:templateview', CAP_ALLOW, $this->userrole, $syscontextid, true);
accesslib_clear_all_caches_for_unit_testing(); accesslib_clear_all_caches_for_unit_testing();
$this->assertTrue(has_capability('tool/lp:templateread', context_system::instance())); $this->assertTrue(has_capability('tool/lp:templateview', context_system::instance()));
$result = external::read_template($systemplate->id); $result = external::read_template($systemplate->id);
$result = external_api::clean_returnvalue(external::read_template_returns(), $result); $result = external_api::clean_returnvalue(external::read_template_returns(), $result);
$this->assertEquals($systemplate->id, $result['id']); $this->assertEquals($systemplate->id, $result['id']);
@ -2068,7 +2068,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
// User without permission. // User without permission.
$this->setUser($this->user); $this->setUser($this->user);
assign_capability('tool/lp:templateread', CAP_PROHIBIT, $this->userrole, $syscontextid, true); assign_capability('tool/lp:templateview', CAP_PROHIBIT, $this->userrole, $syscontextid, true);
accesslib_clear_all_caches_for_unit_testing(); accesslib_clear_all_caches_for_unit_testing();
try { try {
external::list_templates('id', 'ASC', 0, 10, array('contextid' => $syscontextid), 'children', false); external::list_templates('id', 'ASC', 0, 10, array('contextid' => $syscontextid), 'children', false);
@ -2078,8 +2078,8 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
} }
// User with category permissions. // User with category permissions.
assign_capability('tool/lp:templateread', CAP_PREVENT, $this->userrole, $syscontextid, true); assign_capability('tool/lp:templateview', CAP_PREVENT, $this->userrole, $syscontextid, true);
assign_capability('tool/lp:templateread', CAP_ALLOW, $this->userrole, $catcontextid, true); assign_capability('tool/lp:templateview', CAP_ALLOW, $this->userrole, $catcontextid, true);
accesslib_clear_all_caches_for_unit_testing(); accesslib_clear_all_caches_for_unit_testing();
$result = external::list_templates('id', 'ASC', 0, 10, array('contextid' => $syscontextid), 'children', false); $result = external::list_templates('id', 'ASC', 0, 10, array('contextid' => $syscontextid), 'children', false);
$result = external_api::clean_returnvalue(external::list_templates_returns(), $result); $result = external_api::clean_returnvalue(external::list_templates_returns(), $result);
@ -2088,7 +2088,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$this->assertEquals($cat2->id, $result[1]['id']); $this->assertEquals($cat2->id, $result[1]['id']);
// User with system permissions. // User with system permissions.
assign_capability('tool/lp:templateread', CAP_ALLOW, $this->userrole, $syscontextid, true); assign_capability('tool/lp:templateview', CAP_ALLOW, $this->userrole, $syscontextid, true);
accesslib_clear_all_caches_for_unit_testing(); accesslib_clear_all_caches_for_unit_testing();
$result = external::list_templates('id', 'DESC', 0, 3, array('contextid' => $catcontextid), 'parents', false); $result = external::list_templates('id', 'DESC', 0, 3, array('contextid' => $catcontextid), 'parents', false);
$result = external_api::clean_returnvalue(external::list_templates_returns(), $result); $result = external_api::clean_returnvalue(external::list_templates_returns(), $result);
@ -2159,7 +2159,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
// User without permission. // User without permission.
$this->setUser($this->user); $this->setUser($this->user);
assign_capability('tool/lp:templateread', CAP_PROHIBIT, $this->userrole, $syscontextid, true); assign_capability('tool/lp:templateview', CAP_PROHIBIT, $this->userrole, $syscontextid, true);
accesslib_clear_all_caches_for_unit_testing(); accesslib_clear_all_caches_for_unit_testing();
try { try {
external::count_templates(array('contextid' => $syscontextid), 'children'); external::count_templates(array('contextid' => $syscontextid), 'children');
@ -2169,15 +2169,15 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
} }
// User with category permissions. // User with category permissions.
assign_capability('tool/lp:templateread', CAP_PREVENT, $this->userrole, $syscontextid, true); assign_capability('tool/lp:templateview', CAP_PREVENT, $this->userrole, $syscontextid, true);
assign_capability('tool/lp:templateread', CAP_ALLOW, $this->userrole, $catcontextid, true); assign_capability('tool/lp:templateview', CAP_ALLOW, $this->userrole, $catcontextid, true);
accesslib_clear_all_caches_for_unit_testing(); accesslib_clear_all_caches_for_unit_testing();
$result = external::count_templates(array('contextid' => $syscontextid), 'children'); $result = external::count_templates(array('contextid' => $syscontextid), 'children');
$result = external_api::clean_returnvalue(external::count_templates_returns(), $result); $result = external_api::clean_returnvalue(external::count_templates_returns(), $result);
$this->assertEquals(3, $result); $this->assertEquals(3, $result);
// User with system permissions. // User with system permissions.
assign_capability('tool/lp:templateread', CAP_ALLOW, $this->userrole, $syscontextid, true); assign_capability('tool/lp:templateview', CAP_ALLOW, $this->userrole, $syscontextid, true);
accesslib_clear_all_caches_for_unit_testing(); accesslib_clear_all_caches_for_unit_testing();
$result = external::count_templates(array('contextid' => $catcontextid), 'parents'); $result = external::count_templates(array('contextid' => $catcontextid), 'parents');
$result = external_api::clean_returnvalue(external::count_templates_returns(), $result); $result = external_api::clean_returnvalue(external::count_templates_returns(), $result);

View file

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016020919; // The current plugin version (Date: YYYYMMDDXX). $plugin->version = 2016020920; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2014110400; // Requires this Moodle version. $plugin->requires = 2014110400; // Requires this Moodle version.
$plugin->component = 'tool_lp'; // Full name of the plugin (used for diagnostics). $plugin->component = 'tool_lp'; // Full name of the plugin (used for diagnostics).

View file

@ -36,7 +36,7 @@ $functions = array(
'classpath' => '', 'classpath' => '',
'description' => 'Load the data for the competency report in a course.', 'description' => 'Load the data for the competency report in a course.',
'type' => 'read', 'type' => 'read',
'capabilities' => 'tool/lp:coursecompetencyread', 'capabilities' => 'tool/lp:coursecompetencyview',
'ajax' => true, 'ajax' => true,
) )
); );

View file

@ -34,7 +34,7 @@ defined('MOODLE_INTERNAL') || die;
* @param stdClass $context The context of the course * @param stdClass $context The context of the course
*/ */
function report_competency_extend_navigation_course($navigation, $course, $context) { function report_competency_extend_navigation_course($navigation, $course, $context) {
if (has_capability('tool/lp:coursecompetencyread', $context)) { if (has_capability('tool/lp:coursecompetencyview', $context)) {
$url = new moodle_url('/report/competency/index.php', array('id' => $course->id)); $url = new moodle_url('/report/competency/index.php', array('id' => $course->id));
$name = get_string('pluginname', 'report_competency'); $name = get_string('pluginname', 'report_competency');
$navigation->add($name, $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', '')); $navigation->add($name, $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));