Skip to content

Commit

Permalink
MDL-53070 tool_lp: Fix missing capabilities
Browse files Browse the repository at this point in the history
* Non-editing teacher is missing view usercompetency capability.
* Teacher is missing the suggest grade capability.
  • Loading branch information
taboubi authored and Frederic Massart committed Apr 18, 2016
1 parent e375c65 commit 1fa1336
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions admin/tool/lp/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE, // And CONTEXT_USER.
'archetypes' => array(
'teacher' => CAP_ALLOW
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW
),
),
'tool/lp:competencygrade' => array(
Expand Down Expand Up @@ -182,7 +183,8 @@
'captype' => 'read',
'contextlevel' => CONTEXT_USER, // And CONTEXT_COURSE.
'archetypes' => array(
'editingteacher' => CAP_ALLOW
'editingteacher' => CAP_ALLOW,
'teacher' => CAP_ALLOW
)
),
'tool/lp:usercompetencyrequestreview' => array(
Expand Down
11 changes: 11 additions & 0 deletions admin/tool/lp/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3575,6 +3575,7 @@ public function test_grade_competency_in_course_permissions() {
$c2ctx = context_course::instance($c2->id);

$teacher1 = $dg->create_user();
$noneditingteacher = $dg->create_user();
$student1 = $dg->create_user();
$student2 = $dg->create_user();
$notstudent1 = $dg->create_user();
Expand Down Expand Up @@ -3671,6 +3672,16 @@ public function test_grade_competency_in_course_permissions() {
// Try to grade a user that is not enrolled, even though they are 'gradable'.
$this->assertExceptionWithGradeCompetencyInCourse('coding_exception', 'The competency may not be rated at this time.',
$c1->id, $notstudent1->id, $comp1->get_id());

// Non-Editing teacher can suggest grade in user competency.
$dg->role_assign($canviewucrole, $noneditingteacher->id, $c1ctx->id);
$this->setUser($noneditingteacher);
accesslib_clear_all_caches_for_unit_testing();
$this->assertExceptionWithGradeCompetencyInCourse('required_capability_exception', 'Set competency grade',
$c1->id, $student1->id, $comp1->get_id());
// Give permission for non-editing teacher to suggest.
$dg->role_assign($cansuggestrole, $noneditingteacher->id, $c1ctx->id);
$this->assertSuccessWithGradeCompetencyInCourse($c1->id, $student1->id, $comp1->get_id(), 1, false);
}

protected function assertSuccessWithGradeCompetencyInCourse($courseid, $userid, $compid, $grade = 1, $override = true) {
Expand Down

0 comments on commit 1fa1336

Please sign in to comment.