MDL-63136 mod_data: Check if the module is visible to the user
This commit is contained in:
@@ -4471,6 +4471,12 @@ function mod_data_core_calendar_provide_event_action(calendar_event $event,
|
||||
}
|
||||
|
||||
$cm = get_fast_modinfo($event->courseid, $userid)->instances['data'][$event->instance];
|
||||
|
||||
if (!$cm->uservisible) {
|
||||
// The module is not visible to the user for any reason.
|
||||
return null;
|
||||
}
|
||||
|
||||
$now = time();
|
||||
|
||||
if (!empty($cm->customdata['timeavailableto']) && $cm->customdata['timeavailableto'] < $now) {
|
||||
|
||||
@@ -1314,6 +1314,74 @@ class mod_data_lib_testcase extends advanced_testcase {
|
||||
$this->assertEquals([$datarecor1did, $datarecor2did], $updates->entries->itemids, '', 0, 10, true);
|
||||
}
|
||||
|
||||
public function test_data_core_calendar_provide_event_action_in_hidden_section() {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create a course.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
|
||||
// Create a student.
|
||||
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
||||
|
||||
// Create a database activity.
|
||||
$data = $this->getDataGenerator()->create_module('data', array('course' => $course->id,
|
||||
'timeavailablefrom' => time() - DAYSECS, 'timeavailableto' => time() + DAYSECS));
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $data->id, DATA_EVENT_TYPE_OPEN);
|
||||
|
||||
// Set sections 0 as hidden.
|
||||
set_section_visible($course->id, 0, 0);
|
||||
|
||||
// Now, log out.
|
||||
$CFG->forcelogin = true; // We don't want to be logged in as guest, as guest users might still have some capabilities.
|
||||
$this->setUser();
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event for the student.
|
||||
$actionevent = mod_data_core_calendar_provide_event_action($event, $factory, $student->id);
|
||||
|
||||
// Confirm the event is not shown at all.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
public function test_data_core_calendar_provide_event_action_for_non_user() {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create a course.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
|
||||
// Create a database activity.
|
||||
$data = $this->getDataGenerator()->create_module('data', array('course' => $course->id,
|
||||
'timeavailablefrom' => time() - DAYSECS, 'timeavailableto' => time() + DAYSECS));
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $data->id, DATA_EVENT_TYPE_OPEN);
|
||||
|
||||
// Now, log out.
|
||||
$CFG->forcelogin = true; // We don't want to be logged in as guest, as guest users might still have some capabilities.
|
||||
$this->setUser();
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event.
|
||||
$actionevent = mod_data_core_calendar_provide_event_action($event, $factory);
|
||||
|
||||
// Confirm the event is not shown at all.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
public function test_data_core_calendar_provide_event_action_open() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user