mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-40737 tool_uploadcourse: Prevent update of frontpage
This commit is contained in:
parent
a31e811563
commit
0e8f56103c
@ -399,7 +399,7 @@ class tool_uploadcourse_course {
|
||||
* @return bool false is any error occured.
|
||||
*/
|
||||
public function prepare() {
|
||||
global $DB;
|
||||
global $DB, $SITE;
|
||||
$this->prepared = true;
|
||||
|
||||
// Validate the shortname.
|
||||
@ -432,6 +432,12 @@ class tool_uploadcourse_course {
|
||||
$this->error('courseexistsanduploadnotallowed',
|
||||
new lang_string('courseexistsanduploadnotallowed', 'tool_uploadcourse'));
|
||||
return false;
|
||||
} else if ($this->can_update()) {
|
||||
// We can never allow for any front page changes!
|
||||
if ($this->shortname == $SITE->shortname) {
|
||||
$this->error('cannotupdatefrontpage', new lang_string('cannotupdatefrontpage', 'tool_uploadcourse'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!$this->can_create()) {
|
||||
@ -608,6 +614,13 @@ class tool_uploadcourse_course {
|
||||
if ($exists) {
|
||||
$missingonly = ($updatemode === tool_uploadcourse_processor::UPDATE_MISSING_WITH_DATA_OR_DEFAUTLS);
|
||||
$coursedata = $this->get_final_update_data($coursedata, $usedefaults, $missingonly);
|
||||
|
||||
// Make sure we are not trying to mess with the front page, though we should never get here!
|
||||
if ($coursedata['id'] == $SITE->id) {
|
||||
$this->error('cannotupdatefrontpage', new lang_string('cannotupdatefrontpage', 'tool_uploadcourse'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->do = self::DO_UPDATE;
|
||||
} else {
|
||||
$coursedata = $this->get_final_create_data($coursedata);
|
||||
|
@ -32,6 +32,7 @@ $string['cannotreadbackupfile'] = 'Cannot read the backup file';
|
||||
$string['cannotrenamecoursenotexist'] = 'Cannot rename a course that does not exist';
|
||||
$string['cannotrenameidnumberconflict'] = 'Cannot rename the course, the ID number conflicts with an existing course';
|
||||
$string['cannotrenameshortnamealreadyinuse'] = 'Cannot rename the course, the shortname is already used';
|
||||
$string['cannotupdatefrontpage'] = 'It is forbidden to modify the front page';
|
||||
$string['canonlyrenameinupdatemode'] = 'Can only rename a course when update is allowed';
|
||||
$string['canonlyresetcourseinupdatemode'] = 'Can only reset a course in update mode';
|
||||
$string['couldnotresolvecatgorybyid'] = 'Could not resolve category by ID';
|
||||
|
@ -920,4 +920,47 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
|
||||
$this->assertArrayHasKey('courseshortnameincremented', $co->get_statuses());
|
||||
}
|
||||
|
||||
public function test_mess_with_frontpage() {
|
||||
global $SITE;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Updating the front page.
|
||||
$mode = tool_uploadcourse_processor::MODE_UPDATE_ONLY;
|
||||
$updatemode = tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY;
|
||||
$data = array('shortname' => $SITE->shortname, 'idnumber' => 'NewIDN');
|
||||
$importoptions = array();
|
||||
$co = new tool_uploadcourse_course($mode, $updatemode, $data, array(), $importoptions);
|
||||
$this->assertFalse($co->prepare());
|
||||
$this->assertArrayHasKey('cannotupdatefrontpage', $co->get_errors());
|
||||
|
||||
// Updating the front page.
|
||||
$mode = tool_uploadcourse_processor::MODE_CREATE_OR_UPDATE;
|
||||
$updatemode = tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY;
|
||||
$data = array('shortname' => $SITE->shortname, 'idnumber' => 'NewIDN');
|
||||
$importoptions = array();
|
||||
$co = new tool_uploadcourse_course($mode, $updatemode, $data, array(), $importoptions);
|
||||
$this->assertFalse($co->prepare());
|
||||
$this->assertArrayHasKey('cannotupdatefrontpage', $co->get_errors());
|
||||
|
||||
// Generating a shortname should not be allowed in update mode, and so we cannot update the front page.
|
||||
$mode = tool_uploadcourse_processor::MODE_CREATE_OR_UPDATE;
|
||||
$updatemode = tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY;
|
||||
$data = array('idnumber' => 'NewIDN', 'fullname' => 'FN', 'category' => 1);
|
||||
$importoptions = array('shortnametemplate' => $SITE->shortname);
|
||||
$co = new tool_uploadcourse_course($mode, $updatemode, $data, array(), $importoptions);
|
||||
$this->assertFalse($co->prepare());
|
||||
$this->assertArrayHasKey('cannotgenerateshortnameupdatemode', $co->get_errors());
|
||||
|
||||
// Renaming to the front page should not be allowed.
|
||||
$c1 = $this->getDataGenerator()->create_course();
|
||||
$mode = tool_uploadcourse_processor::MODE_CREATE_OR_UPDATE;
|
||||
$updatemode = tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY;
|
||||
$data = array('shortname' => $c1->shortname, 'fullname' => 'FN', 'idnumber' => 'NewIDN', 'rename' => $SITE->shortname);
|
||||
$importoptions = array('canrename' => true);
|
||||
$co = new tool_uploadcourse_course($mode, $updatemode, $data, array(), $importoptions);
|
||||
$this->assertFalse($co->prepare());
|
||||
$this->assertArrayHasKey('cannotrenameshortnamealreadyinuse', $co->get_errors());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user