This commit is contained in:
Sara Arjona 2022-11-14 16:04:06 +01:00
commit 5fd5650838
2 changed files with 38 additions and 0 deletions

View File

@ -357,6 +357,9 @@ class manager {
// But excluding all reviewattempts users converting a capabilities join into left join.
$reviewersjoin = get_with_capability_join($context, 'mod/h5pactivity:reviewattempts', 'u.id');
if ($reviewersjoin->cannotmatchanyrows) {
return $capjoin;
}
$capjoin = new sql_join(
$capjoin->joins . "\n LEFT " . str_replace('ra', 'reviewer', $reviewersjoin->joins),

View File

@ -737,6 +737,41 @@ class manager_test extends \advanced_testcase {
$this->assertEqualsCanonicalizing([$teacher->username, $userone->username], $users);
}
/**
* Test getting active users join where there are no roles with 'mod/h5pactivity:reviewattempts' capability
*/
public function test_get_active_users_join_no_reviewers(): void {
global $DB;
$this->resetAfterTest();
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
$activity = $this->getDataGenerator()->create_module('h5pactivity', ['course' => $course]);
$user = $this->getDataGenerator()->create_and_enrol($course, 'student');
$manager = manager::create_from_instance($activity);
// By default manager and editingteacher can review attempts, prohibit both.
$rolemanager = $DB->get_field('role', 'id', ['shortname' => 'manager']);
role_change_permission($rolemanager, $manager->get_context(), 'mod/h5pactivity:reviewattempts', CAP_PROHIBIT);
$roleeditingteacher = $DB->get_field('role', 'id', ['shortname' => 'editingteacher']);
role_change_permission($roleeditingteacher, $manager->get_context(), 'mod/h5pactivity:reviewattempts', CAP_PROHIBIT);
// Generate users join SQL to find matching users.
$usersjoin = $manager->get_active_users_join(true);
$usernames = $DB->get_fieldset_sql(
"SELECT u.username
FROM {user} u
{$usersjoin->joins}
WHERE {$usersjoin->wheres}",
$usersjoin->params
);
$this->assertEquals([$user->username], $usernames);
}
/**
* Test static count_attempts.
*/