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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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().
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user