MDL-59393 calendar: stop user editing module events

This commit is contained in:
Ryan Wyllie 2017-08-18 05:29:07 +00:00
parent 5ca142dc5b
commit 909d08588d
5 changed files with 72 additions and 5 deletions

View file

@ -1332,8 +1332,8 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase {
}
/**
* Updating the event start day should change the date value but leave
* the time of day unchanged.
* A user should not be able to edit an event that they don't have
* capabilities for.
*/
public function test_update_event_start_day_no_permission() {
$generator = $this->getDataGenerator();
@ -1370,4 +1370,48 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase {
$result
);
}
/**
* A user should not be able to update a module event.
*/
public function test_update_event_start_day_module_event() {
$generator = $this->getDataGenerator();
$user = $generator->create_user();
$course = $generator->create_course();
$moduleinstance = $generator->get_plugin_generator('mod_assign')
->create_instance(['course' => $course->id]);
$roleid = $generator->create_role();
$context = \context_course::instance($course->id);
$originalStartTime = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
$newStartDate = new DateTimeImmutable('2018-02-2T10:00:00+08:00');
$expected = new DateTimeImmutable('2018-02-2T15:00:00+08:00');
$generator->role_assign($roleid, $user->id, $context->id);
$generator->enrol_user($user->id, $course->id);
$this->setUser($user);
$this->resetAfterTest(true);
$event = $this->create_calendar_event(
'Test event',
$user->id,
'user',
0,
null,
[
'modulename' => 'assign',
'instance' => $moduleinstance->id,
'courseid' => $course->id,
'timestart' => $originalStartTime->getTimestamp()
]
);
assign_capability('moodle/calendar:manageentries', CAP_ALLOW, $roleid, $context, true);
$this->expectException('moodle_exception');
$result = core_calendar_external::update_event_start_day($event->id, $newStartDate->getTimestamp());
$result = external_api::clean_returnvalue(
core_calendar_external::update_event_start_day_returns(),
$result
);
}
}