Skip to content

Commit

Permalink
Merge branch 'MDL-59994-32' of git://github.com/lameze/moodle into MO…
Browse files Browse the repository at this point in the history
…ODLE_32_STABLE
  • Loading branch information
junpataleta committed Sep 18, 2017
2 parents cc60733 + 437a07a commit d19291f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion competency/classes/api.php
Expand Up @@ -1349,7 +1349,8 @@ public static function list_user_competencies_to_review($skip = 0, $limit = 50,
JOIN {user} u
ON u.id = uc.userid
WHERE (uc.status = :waitingforreview
OR (uc.status = :inreview AND uc.reviewerid = :reviewerid))";
OR (uc.status = :inreview AND uc.reviewerid = :reviewerid))
AND u.deleted = 0";
$ordersql = " ORDER BY c.shortname ASC";
$params = array(
'inreview' => user_competency::STATUS_IN_REVIEW,
Expand Down
15 changes: 14 additions & 1 deletion competency/tests/api_test.php
Expand Up @@ -4564,6 +4564,9 @@ public function test_list_plans_to_review() {
}

public function test_list_user_competencies_to_review() {
global $CFG;
require_once($CFG->dirroot . '/user/lib.php');

$dg = $this->getDataGenerator();
$this->resetAfterTest();
$ccg = $dg->get_plugin_generator('core_competency');
Expand All @@ -4580,6 +4583,7 @@ public function test_list_user_competencies_to_review() {

$u1 = $dg->create_user();
$u2 = $dg->create_user();
$u3 = $dg->create_user();
$f1 = $ccg->create_framework();
$c1 = $ccg->create_competency(['competencyframeworkid' => $f1->get_id()]);
$c2 = $ccg->create_competency(['competencyframeworkid' => $f1->get_id()]);
Expand All @@ -4596,14 +4600,23 @@ public function test_list_user_competencies_to_review() {
'status' => user_competency::STATUS_IDLE]);
$uc2c = $ccg->create_user_competency(['userid' => $u2->id, 'competencyid' => $c3->get_id(),
'status' => user_competency::STATUS_IN_REVIEW]);
$uc3a = $ccg->create_user_competency(['userid' => $u3->id, 'competencyid' => $c3->get_id(),
'status' => user_competency::STATUS_WAITING_FOR_REVIEW]);

// The reviewer can review all plans waiting for review, or in review where they are the reviewer.
$this->setUser($reviewer);
$result = api::list_user_competencies_to_review();
$this->assertEquals(3, $result['count']);
$this->assertEquals(4, $result['count']);
$this->assertEquals($uc2a->get_id(), $result['competencies'][0]->usercompetency->get_id());
$this->assertEquals($uc1b->get_id(), $result['competencies'][1]->usercompetency->get_id());
$this->assertEquals($uc1c->get_id(), $result['competencies'][2]->usercompetency->get_id());
$this->assertEquals($uc3a->get_id(), $result['competencies'][3]->usercompetency->get_id());

// Now, let's delete user 3.
// It should not be listed on user competencies to review any more.
user_delete_user($u3);
$result = api::list_user_competencies_to_review();
$this->assertEquals(3, $result['count']);

// The reviewer cannot view the plans when they do not have the permission in the user's context.
role_assign($roleprohibit, $reviewer->id, context_user::instance($u2->id)->id);
Expand Down

0 comments on commit d19291f

Please sign in to comment.