MDL-63152 mod_workshop: check if the module is visible to the user
This commit is contained in:
@@ -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)),
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user