MDL-87657 cohort: fix permission check for viewing system cohorts.

The problem manifested itself in custom reports using the corresponding
cohort field filter, which didn't reload current form values due to
incorrect context tree comparison.
This commit is contained in:
Paul Holden
2026-02-12 17:01:22 +00:00
parent ac802ad804
commit 06df92cfa2
2 changed files with 16 additions and 1 deletions
+1 -1
View File
@@ -363,7 +363,7 @@ function cohort_can_view_cohort($cohortorid, $currentcontext) {
$cohort = $cohortorid;
}
if ($cohort && in_array($cohort->contextid, $currentcontext->get_parent_context_ids())) {
if ($cohort && in_array($cohort->contextid, $currentcontext->get_parent_context_ids(true))) {
if ($cohort->visible) {
return true;
}
+15
View File
@@ -943,6 +943,21 @@ final class lib_test extends \advanced_testcase {
}
}
/**
* Test whether user can view cohort
*
* @covers ::cohort_can_view_cohort
*/
public function test_cohort_can_view_cohort(): void {
$this->resetAfterTest();
$this->setAdminUser();
$context = \context_system::instance();
$cohort = $this->getDataGenerator()->create_cohort(['contextid' => $context->id]);
$this->assertTrue(cohort_can_view_cohort($cohort, $context));
}
/**
* Test the behaviour of cohort_get_cohort().
*