diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index 73d05e2e40e..ee3404e24cc 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -1846,6 +1846,11 @@ function mod_workshop_core_calendar_provide_event_action(calendar_event $event, $cm = get_fast_modinfo($event->courseid)->instances['workshop'][$event->instance]; + if (!$cm->uservisible) { + // The module is not visible to the user for any reason. + return null; + } + return $factory->create_instance( get_string('viewworkshopsummary', 'workshop'), new \moodle_url('/mod/workshop/view.php', array('id' => $cm->id)), diff --git a/mod/workshop/tests/lib_test.php b/mod/workshop/tests/lib_test.php index b52404d84b8..f2cd1b9f67c 100644 --- a/mod/workshop/tests/lib_test.php +++ b/mod/workshop/tests/lib_test.php @@ -56,6 +56,32 @@ class mod_workshop_lib_testcase extends advanced_testcase { $this->assertTrue($actionevent->is_actionable()); } + /** + * Test calendar event provide action open for a non user. + */ + public function test_workshop_core_calendar_provide_event_action_open_for_non_user() { + global $CFG; + + $this->resetAfterTest(); + $this->setAdminUser(); + + $now = time(); + $course = $this->getDataGenerator()->create_course(); + $workshop = $this->getDataGenerator()->create_module('workshop', ['course' => $course->id, + 'submissionstart' => $now - DAYSECS, 'submissionend' => $now + DAYSECS]); + $event = $this->create_action_event($course->id, $workshop->id, WORKSHOP_EVENT_TYPE_SUBMISSION_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(); + + $factory = new \core_calendar\action_factory(); + $actionevent = mod_workshop_core_calendar_provide_event_action($event, $factory); + + // Confirm the event is not shown at all. + $this->assertNull($actionevent); + } + /** * Test calendar event provide action closed. */ @@ -78,10 +104,33 @@ class mod_workshop_lib_testcase extends advanced_testcase { $this->assertTrue($actionevent->is_actionable()); } + /** + * Test calendar event provide action closed for a non user. + */ + public function test_workshop_core_calendar_provide_event_action_closed_for_non_user() { + global $CFG; + + $this->resetAfterTest(); + $this->setAdminUser(); + + $course = $this->getDataGenerator()->create_course(); + $workshop = $this->getDataGenerator()->create_module('workshop', array('course' => $course->id, + 'submissionend' => time() - DAYSECS)); + $event = $this->create_action_event($course->id, $workshop->id, WORKSHOP_EVENT_TYPE_SUBMISSION_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(); + + $factory = new \core_calendar\action_factory(); + $actionevent = mod_workshop_core_calendar_provide_event_action($event, $factory); + + // Confirm the event is not shown at all. + $this->assertNull($actionevent); + } + /** * Test calendar event action open in future. - * - * @throws coding_exception */ public function test_workshop_core_calendar_provide_event_action_open_in_future() { $this->resetAfterTest(); @@ -102,10 +151,33 @@ class mod_workshop_lib_testcase extends advanced_testcase { $this->assertTrue($actionevent->is_actionable()); } + /** + * Test calendar event action open in future for a non user. + */ + public function test_workshop_core_calendar_provide_event_action_open_in_future_for_non_user() { + global $CFG; + + $this->resetAfterTest(); + $this->setAdminUser(); + + $course = $this->getDataGenerator()->create_course(); + $workshop = $this->getDataGenerator()->create_module('workshop', ['course' => $course->id, + 'submissionstart' => time() + DAYSECS]); + $event = $this->create_action_event($course->id, $workshop->id, WORKSHOP_EVENT_TYPE_SUBMISSION_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(); + + $factory = new \core_calendar\action_factory(); + $actionevent = mod_workshop_core_calendar_provide_event_action($event, $factory); + + // Confirm the event is not shown at all. + $this->assertNull($actionevent); + } + /** * Test calendar event with no time specified. - * - * @throws coding_exception */ public function test_workshop_core_calendar_provide_event_action_no_time_specified() { $this->resetAfterTest(); @@ -125,6 +197,30 @@ class mod_workshop_lib_testcase extends advanced_testcase { $this->assertTrue($actionevent->is_actionable()); } + /** + * Test calendar event with no time specified for a non user. + */ + public function test_workshop_core_calendar_provide_event_action_no_time_specified_for_non_user() { + global $CFG; + + $this->resetAfterTest(); + $this->setAdminUser(); + + $course = $this->getDataGenerator()->create_course(); + $workshop = $this->getDataGenerator()->create_module('workshop', ['course' => $course->id]); + $event = $this->create_action_event($course->id, $workshop->id, WORKSHOP_EVENT_TYPE_SUBMISSION_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(); + + $factory = new \core_calendar\action_factory(); + $actionevent = mod_workshop_core_calendar_provide_event_action($event, $factory); + + // Confirm the event is not shown at all. + $this->assertNull($actionevent); + } + /** * Creates an action event. *