Skip to content

Commit

Permalink
MDL-53700 competency: Migrate capabilities to core
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Apr 18, 2016
1 parent 1f76995 commit b90e220
Show file tree
Hide file tree
Showing 42 changed files with 791 additions and 821 deletions.
396 changes: 198 additions & 198 deletions admin/tool/lp/classes/api.php

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions admin/tool/lp/classes/competency_framework.php
Expand Up @@ -488,7 +488,7 @@ public function can_manage() {
* @return bool
*/
public static function can_manage_context($context) {
return has_capability('tool/lp:competencymanage', $context);
return has_capability('moodle/competency:competencymanage', $context);
}

/**
Expand All @@ -507,7 +507,7 @@ public function can_read() {
* @return bool
*/
public static function can_read_context($context) {
return has_capability('tool/lp:competencyview', $context) || self::can_manage_context($context);
return has_capability('moodle/competency:competencyview', $context) || self::can_manage_context($context);
}

}
4 changes: 2 additions & 2 deletions admin/tool/lp/classes/course_competency_settings.php
Expand Up @@ -88,7 +88,7 @@ public static function get_by_courseid($courseid) {
public static function can_read($courseid) {
$context = context_course::instance($courseid);

$capabilities = array('tool/lp:coursecompetencyview');
$capabilities = array('moodle/competency:coursecompetencyview');

return has_any_capability($capabilities, $context);
}
Expand All @@ -102,7 +102,7 @@ public static function can_read($courseid) {
public static function can_manage_course($courseid) {
$context = context_course::instance($courseid);

$capabilities = array('tool/lp:coursecompetencyconfigure');
$capabilities = array('moodle/competency:coursecompetencyconfigure');

return has_any_capability($capabilities, $context);
}
Expand Down
Expand Up @@ -54,7 +54,7 @@ protected function get_other_values(renderer_base $output) {
$filters = array('competencyframeworkid' => $this->persistent->get_id());
$context = $this->persistent->get_context();
return array(
'canmanage' => has_capability('tool/lp:competencymanage', $context),
'canmanage' => has_capability('moodle/competency:competencymanage', $context),
'competenciescount' => api::count_competencies($filters),
'contextname' => $context->get_context_name(),
'contextnamenoprefix' => $context->get_context_name(false)
Expand Down
Expand Up @@ -96,8 +96,8 @@ protected function get_other_values(renderer_base $output) {
'proficientcompetencypercentageformatted' => $proficientcompetencypercentageformatted,
'leastproficient' => $competencies,
'leastproficientcount' => count($competencies),
'canbegradedincourse' => has_capability('tool/lp:coursecompetencygradable', $this->related['context']),
'canmanagecoursecompetencies' => has_capability('tool/lp:coursecompetencymanage', $this->related['context'])
'canbegradedincourse' => has_capability('moodle/competency:coursecompetencygradable', $this->related['context']),
'canmanagecoursecompetencies' => has_capability('moodle/competency:coursecompetencymanage', $this->related['context'])
);
}
}
2 changes: 1 addition & 1 deletion admin/tool/lp/classes/form/framework_autocomplete.php
Expand Up @@ -106,7 +106,7 @@ public function setValue($value) {
list($insql, $inparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'param');
$frameworks = competency_framework::get_records_select("id $insql", $inparams, 'shortname');
foreach ($frameworks as $framework) {
if (!has_any_capability(array('tool/lp:competencyview', 'tool/lp:competencymanage'), $framework->get_context())) {
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'), $framework->get_context())) {
continue;
} else if ($this->onlyvisible && !$framework->get_visible()) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/lp/classes/form/plan.php
Expand Up @@ -75,7 +75,7 @@ public function definition() {
// There is only one status to select from.
$mform->addElement('static', 'staticstatus', get_string('status', 'tool_lp'), current($status));
} else {
throw new required_capability_exception($context, 'tool/lp:planmanage', 'nopermissions', '');
throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
}

// Disable short forms.
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/lp/classes/form/template_plans.php
Expand Up @@ -44,7 +44,7 @@ public function definition() {
$options = array(
'ajax' => 'tool_lp/form-user-selector',
'multiple' => true,
'data-capability' => 'tool/lp:planmanage'
'data-capability' => 'moodle/competency:planmanage'
);
$mform->addElement('autocomplete', 'users', get_string('selectuserstocreateplansfor', 'tool_lp'), array(), $options);
$mform->addElement('submit', 'submit', get_string('createplans', 'tool_lp'));
Expand Down
8 changes: 4 additions & 4 deletions admin/tool/lp/classes/output/course_competencies_page.php
Expand Up @@ -78,8 +78,8 @@ public function __construct($courseid) {
$this->context = context_course::instance($courseid);
$this->courseid = $courseid;
$this->coursecompetencylist = api::list_course_competencies($courseid);
$this->canmanagecoursecompetencies = has_capability('tool/lp:coursecompetencymanage', $this->context);
$this->canconfigurecoursecompetencies = has_capability('tool/lp:coursecompetencyconfigure', $this->context);
$this->canmanagecoursecompetencies = has_capability('moodle/competency:coursecompetencymanage', $this->context);
$this->canconfigurecoursecompetencies = has_capability('moodle/competency:coursecompetencyconfigure', $this->context);
$this->coursecompetencysettings = api::read_course_competency_settings($courseid);
$this->coursecompetencystatistics = new course_competency_statistics($courseid);

Expand All @@ -88,7 +88,7 @@ public function __construct($courseid) {
$this->canmanagecompetencyframeworks = false;
$contexts = array_reverse($this->context->get_parent_contexts(true));
foreach ($contexts as $context) {
$canmanage = has_capability('tool/lp:competencymanage', $context);
$canmanage = has_capability('moodle/competency:competencymanage', $context);
if ($canmanage) {
$this->manageurl = new moodle_url('/admin/tool/lp/competencyframeworks.php',
array('pagecontextid' => $context->id));
Expand All @@ -113,7 +113,7 @@ public function export_for_template(renderer_base $output) {
$data->competencies = array();
$contextcache = array();

$gradable = is_enrolled($this->context, $USER, 'tool/lp:coursecompetencygradable');
$gradable = is_enrolled($this->context, $USER, 'moodle/competency:coursecompetencygradable');
if ($gradable) {
$usercompetencycourses = api::list_user_competencies_in_course($this->courseid, $USER->id);
$data->gradableuserid = $USER->id;
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/lp/classes/output/manage_competencies_page.php
Expand Up @@ -79,7 +79,7 @@ public function __construct($framework, $search, $pagecontext) {
);
$this->navigation[] = $addpage;

$this->canmanage = has_capability('tool/lp:competencymanage', $framework->get_context());
$this->canmanage = has_capability('moodle/competency:competencymanage', $framework->get_context());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/lp/classes/output/template_cohorts_table.php
Expand Up @@ -61,7 +61,7 @@ public function __construct($uniqueid, \tool_lp\template $template) {

// This object should not be used without the right permissions.
if (!$template->can_read()) {
throw new \required_capability_exception($template->get_context(), 'tool/lp:templateview', 'nopermissions', '');
throw new \required_capability_exception($template->get_context(), 'moodle/competency:templateview', 'nopermissions', '');
}

// Set protected properties.
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/lp/classes/output/template_competencies_page.php
Expand Up @@ -78,8 +78,8 @@ public function __construct(template $template, context $pagecontext) {
$this->template = $template;
$this->templatestatistics = new template_statistics($template->get_id());
$this->competencies = api::list_competencies_in_template($template);
$this->canmanagecompetencyframeworks = has_capability('tool/lp:competencymanage', $this->pagecontext);
$this->canmanagetemplatecompetencies = has_capability('tool/lp:templatemanage', $this->pagecontext);
$this->canmanagecompetencyframeworks = has_capability('moodle/competency:competencymanage', $this->pagecontext);
$this->canmanagetemplatecompetencies = has_capability('moodle/competency:templatemanage', $this->pagecontext);
$this->manageurl = new moodle_url('/admin/tool/lp/competencyframeworks.php',
array('pagecontextid' => $this->pagecontext->id));
}
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/lp/classes/output/template_plans_table.php
Expand Up @@ -61,7 +61,7 @@ public function __construct($uniqueid, \tool_lp\template $template) {

// This object should not be used without the right permissions.
if (!$template->can_read()) {
throw new \required_capability_exception($template->get_context(), 'tool/lp:templateview', 'nopermissions', '');
throw new \required_capability_exception($template->get_context(), 'moodle/competency:templateview', 'nopermissions', '');
}

// Set protected properties.
Expand Down
Expand Up @@ -85,7 +85,7 @@ public function export_for_template(renderer_base $output) {
$data->baseurl = $this->baseurl;
$data->groupselector = '';

if (has_capability('tool/lp:coursecompetencymanage', $context)) {
if (has_capability('moodle/competency:coursecompetencymanage', $context)) {
$course = $DB->get_record('course', array('id' => $this->courseid));
$currentgroup = groups_get_course_group($course, true);
if ($currentgroup !== false) {
Expand All @@ -97,7 +97,7 @@ public function export_for_template(renderer_base $output) {
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
$showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);

$users = get_enrolled_users($context, 'tool/lp:coursecompetencygradable', $currentgroup,
$users = get_enrolled_users($context, 'moodle/competency:coursecompetencygradable', $currentgroup,
'u.*', null, 0, 0, $showonlyactiveenrol);

$data->users = array();
Expand Down
26 changes: 13 additions & 13 deletions admin/tool/lp/classes/plan.php
Expand Up @@ -364,9 +364,9 @@ protected function validate_userid($value) {
public static function can_comment_user($planuserid) {
global $USER;

$capabilities = array('tool/lp:plancomment');
$capabilities = array('moodle/competency:plancomment');
if ($USER->id == $planuserid) {
$capabilities[] = 'tool/lp:plancommentown';
$capabilities[] = 'moodle/competency:plancommentown';
}

return has_any_capability($capabilities, context_user::instance($planuserid));
Expand All @@ -382,9 +382,9 @@ public static function can_manage_user($planuserid) {
global $USER;
$context = context_user::instance($planuserid);

$capabilities = array('tool/lp:planmanage');
$capabilities = array('moodle/competency:planmanage');
if ($context->instanceid == $USER->id) {
$capabilities[] = 'tool/lp:planmanageown';
$capabilities[] = 'moodle/competency:planmanageown';
}

return has_any_capability($capabilities, $context);
Expand All @@ -400,9 +400,9 @@ public static function can_manage_user_draft($planuserid) {
global $USER;
$context = context_user::instance($planuserid);

$capabilities = array('tool/lp:planmanagedraft');
$capabilities = array('moodle/competency:planmanagedraft');
if ($context->instanceid == $USER->id) {
$capabilities[] = 'tool/lp:planmanageowndraft';
$capabilities[] = 'moodle/competency:planmanageowndraft';
}

return has_any_capability($capabilities, $context);
Expand All @@ -429,9 +429,9 @@ public static function can_read_user($planuserid) {
global $USER;
$context = context_user::instance($planuserid);

$capabilities = array('tool/lp:planview');
$capabilities = array('moodle/competency:planview');
if ($context->instanceid == $USER->id) {
$capabilities[] = 'tool/lp:planviewown';
$capabilities[] = 'moodle/competency:planviewown';
}

return has_any_capability($capabilities, $context)
Expand All @@ -448,9 +448,9 @@ public static function can_read_user_draft($planuserid) {
global $USER;
$context = context_user::instance($planuserid);

$capabilities = array('tool/lp:planviewdraft');
$capabilities = array('moodle/competency:planviewdraft');
if ($context->instanceid == $USER->id) {
$capabilities[] = 'tool/lp:planviewowndraft';
$capabilities[] = 'moodle/competency:planviewowndraft';
}

return has_any_capability($capabilities, $context)
Expand All @@ -466,9 +466,9 @@ public static function can_read_user_draft($planuserid) {
public static function can_request_review_user($planuserid) {
global $USER;

$capabilities = array('tool/lp:planrequestreview');
$capabilities = array('moodle/competency:planrequestreview');
if ($USER->id == $planuserid) {
$capabilities[] = 'tool/lp:planrequestreviewown';
$capabilities[] = 'moodle/competency:planrequestreviewown';
}

return has_any_capability($capabilities, context_user::instance($planuserid));
Expand All @@ -483,7 +483,7 @@ public static function can_request_review_user($planuserid) {
* @return bool
*/
public static function can_review_user($planuserid) {
return has_capability('tool/lp:planreview', context_user::instance($planuserid))
return has_capability('moodle/competency:planreview', context_user::instance($planuserid))
|| self::can_manage_user($planuserid);
}

Expand Down
4 changes: 2 additions & 2 deletions admin/tool/lp/classes/template.php
Expand Up @@ -114,7 +114,7 @@ public function can_manage() {
* @return bool
*/
public static function can_manage_context($context) {
return has_capability('tool/lp:templatemanage', $context);
return has_capability('moodle/competency:templatemanage', $context);
}

/**
Expand All @@ -133,7 +133,7 @@ public function can_read() {
* @return bool
*/
public static function can_read_context($context) {
return has_capability('tool/lp:templateview', $context) || self::can_manage_context($context);
return has_capability('moodle/competency:templateview', $context) || self::can_manage_context($context);
}

/**
Expand Down
18 changes: 9 additions & 9 deletions admin/tool/lp/classes/user_competency.php
Expand Up @@ -335,9 +335,9 @@ protected function validate_grade($value) {
public static function can_comment_user($userid) {
global $USER;

$capabilities = array('tool/lp:usercompetencycomment');
$capabilities = array('moodle/competency:usercompetencycomment');
if ($USER->id == $userid) {
$capabilities[] = 'tool/lp:usercompetencycommentown';
$capabilities[] = 'moodle/competency:usercompetencycommentown';
}

if (has_any_capability($capabilities, context_user::instance($userid))) {
Expand All @@ -354,7 +354,7 @@ public static function can_comment_user($userid) {
* @return bool
*/
public static function can_grade_user($userid) {
$ratecap = 'tool/lp:competencygrade';
$ratecap = 'moodle/competency:competencygrade';
return has_capability($ratecap, context_user::instance($userid));
}

Expand All @@ -366,7 +366,7 @@ public static function can_grade_user($userid) {
* @return bool
*/
public static function can_grade_user_in_course($userid, $courseid) {
$ratecap = 'tool/lp:competencygrade';
$ratecap = 'moodle/competency:competencygrade';
return has_capability($ratecap, context_course::instance($courseid))
|| static::can_grade_user($userid);
}
Expand All @@ -390,7 +390,7 @@ public static function can_read_comments_user($userid) {
* @return bool
*/
public static function can_read_user_in_course($userid, $courseid) {
$capability = 'tool/lp:usercompetencyview';
$capability = 'moodle/competency:usercompetencyview';
return has_capability($capability, context_course::instance($courseid))
|| static::can_read_user($userid);
}
Expand All @@ -402,7 +402,7 @@ public static function can_read_user_in_course($userid, $courseid) {
* @return bool
*/
public static function can_read_user($userid) {
$capability = 'tool/lp:usercompetencyview';
$capability = 'moodle/competency:usercompetencyview';
return has_capability($capability, context_user::instance($userid))
|| plan::can_read_user($userid);
}
Expand All @@ -420,9 +420,9 @@ public static function can_read_user($userid) {
public static function can_request_review_user($userid) {
global $USER;

$capabilities = array('tool/lp:usercompetencyrequestreview');
$capabilities = array('moodle/competency:usercompetencyrequestreview');
if ($USER->id == $userid) {
$capabilities[] = 'tool/lp:usercompetencyrequestreviewown';
$capabilities[] = 'moodle/competency:usercompetencyrequestreviewown';
}

if (has_any_capability($capabilities, context_user::instance($userid))) {
Expand All @@ -439,7 +439,7 @@ public static function can_request_review_user($userid) {
* @return bool
*/
public static function can_review_user($userid) {
$capability = 'tool/lp:usercompetencyreview';
$capability = 'moodle/competency:usercompetencyreview';
return has_capability($capability, context_user::instance($userid));
}

Expand Down
6 changes: 3 additions & 3 deletions admin/tool/lp/classes/user_evidence.php
Expand Up @@ -170,9 +170,9 @@ public static function can_manage_user($evidenceuserid) {
global $USER;
$context = context_user::instance($evidenceuserid);

$capabilities = array('tool/lp:userevidencemanage');
$capabilities = array('moodle/competency:userevidencemanage');
if ($context->instanceid == $USER->id) {
$capabilities[] = 'tool/lp:userevidencemanageown';
$capabilities[] = 'moodle/competency:userevidencemanageown';
}

return has_any_capability($capabilities, $context);
Expand All @@ -187,7 +187,7 @@ public static function can_manage_user($evidenceuserid) {
public static function can_read_user($evidenceuserid) {
$context = context_user::instance($evidenceuserid);

$capabilities = array('tool/lp:userevidenceview');
$capabilities = array('moodle/competency:userevidenceview');

return has_any_capability($capabilities, $context) || self::can_manage_user($evidenceuserid);
}
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/lp/competencies.php
Expand Up @@ -37,7 +37,7 @@
$context = $framework->get_context();

if (!\tool_lp\competency_framework::can_read_context($context)) {
throw new required_capability_exception($context, 'tool/lp:competencyview', 'nopermissions', '');
throw new required_capability_exception($context, 'moodle/competency:competencyview', 'nopermissions', '');
}

$title = get_string('competencies', 'tool_lp');
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/lp/competencyframeworks.php
Expand Up @@ -35,7 +35,7 @@
\tool_lp\api::require_enabled();

if (!\tool_lp\competency_framework::can_read_context($context)) {
throw new required_capability_exception($context, 'tool/lp:competencyview', 'nopermissions', '');
throw new required_capability_exception($context, 'moodle/competency:competencyview', 'nopermissions', '');
}

$title = get_string('competencies', 'tool_lp');
Expand Down

0 comments on commit b90e220

Please sign in to comment.