MDL-59544 workshop: Drop the custom validation of allowed file types
Now that the validation is provided directly by the filemanager, we do not need to do the same here. Note that existing Behat tests are left untouched to make sure there is no regression.
This commit is contained in:
@@ -120,41 +120,4 @@ class workshop_assessment_form extends moodleform {
|
||||
public function is_editable() {
|
||||
return !$this->_form->isFrozen();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate assessment form data.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $files
|
||||
* @return array
|
||||
*/
|
||||
public function validation($data, $files) {
|
||||
|
||||
$errors = parent::validation($data, $files);
|
||||
|
||||
if (isset($data['feedbackauthorattachment_filemanager']) and isset($this->workshop->overallfeedbackfiletypes)) {
|
||||
$filetypesutil = new \core_form\filetypes_util();
|
||||
$whitelist = $filetypesutil->normalize_file_types($this->workshop->overallfeedbackfiletypes);
|
||||
if ($whitelist) {
|
||||
$draftfiles = file_get_drafarea_files($data['feedbackauthorattachment_filemanager']);
|
||||
if ($draftfiles) {
|
||||
$wrongfiles = array();
|
||||
foreach ($draftfiles->list as $file) {
|
||||
if (!$filetypesutil->is_allowed_file_type($file->filename, $whitelist)) {
|
||||
$wrongfiles[] = $file->filename;
|
||||
}
|
||||
}
|
||||
if ($wrongfiles) {
|
||||
$a = array(
|
||||
'whitelist' => implode(', ', $whitelist),
|
||||
'wrongfiles' => implode(', ', $wrongfiles),
|
||||
);
|
||||
$errors['feedbackauthorattachment_filemanager'] = get_string('err_wrongfileextension', 'mod_workshop', $a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
err_unknownfileextension,mod_workshop
|
||||
err_wrongfileextension,mod_workshop
|
||||
yourassessment,mod_workshop
|
||||
|
||||
@@ -107,7 +107,6 @@ $string['editingsubmission'] = 'Editing submission';
|
||||
$string['editsubmission'] = 'Edit submission';
|
||||
$string['err_multiplesubmissions'] = 'While editing this form, another version of the submission has been saved. Multiple submissions per user are not allowed.';
|
||||
$string['err_removegrademappings'] = 'Unable to remove the unused grade mappings';
|
||||
$string['err_wrongfileextension'] = 'Some files ({$a->wrongfiles}) cannot be uploaded. Only file types {$a->whitelist} are allowed.';
|
||||
$string['evaluategradeswait'] = 'Please wait until the assessments are evaluated and the grades are calculated';
|
||||
$string['evaluation'] = 'Grading evaluation';
|
||||
$string['evaluationmethod'] = 'Grading evaluation method';
|
||||
@@ -373,3 +372,4 @@ $string['yourassessment'] = 'Your assessment';
|
||||
|
||||
// Deprecated since Moodle 3.4.
|
||||
$string['err_unknownfileextension'] = 'Unknown file extension: {$a}';
|
||||
$string['err_wrongfileextension'] = 'Some files ({$a->wrongfiles}) cannot be uploaded. Only file types {$a->whitelist} are allowed.';
|
||||
|
||||
@@ -94,29 +94,6 @@ class workshop_submission_form extends moodleform {
|
||||
$errors['attachment_filemanager'] = get_string('submissionrequiredfile', 'mod_workshop');
|
||||
}
|
||||
|
||||
if (isset($data['attachment_filemanager']) and isset($this->_customdata['workshop']->submissionfiletypes)) {
|
||||
$filetypesutil = new \core_form\filetypes_util();
|
||||
$whitelist = $filetypesutil->normalize_file_types($this->_customdata['workshop']->submissionfiletypes);
|
||||
if ($whitelist) {
|
||||
$draftfiles = file_get_drafarea_files($data['attachment_filemanager']);
|
||||
if ($draftfiles) {
|
||||
$wrongfiles = array();
|
||||
foreach ($draftfiles->list as $file) {
|
||||
if (!$filetypesutil->is_allowed_file_type($file->filename, $whitelist)) {
|
||||
$wrongfiles[] = $file->filename;
|
||||
}
|
||||
}
|
||||
if ($wrongfiles) {
|
||||
$a = array(
|
||||
'whitelist' => implode(', ', $whitelist),
|
||||
'wrongfiles' => implode(', ', $wrongfiles),
|
||||
);
|
||||
$errors['attachment_filemanager'] = get_string('err_wrongfileextension', 'mod_workshop', $a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user