mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-80689 filepicker: better reporting of incorrect file type
Before this change, file type errors were reported like system errors. Now, they are reported in a plain dialoue, which is more like how it works for drag-drop upload. Also, before this, after an upload errors, you were left with a blank filepicker dialogue. Now, the upload form is redisplayed.
This commit is contained in:
parent
2e8b980985
commit
0cd7aaebcd
@ -688,13 +688,30 @@ M.core_filepicker.init = function(Y, options) {
|
||||
}
|
||||
// error checking
|
||||
if (data && data.error) {
|
||||
Y.use('moodle-core-notification-ajaxexception', function () {
|
||||
return new M.core.ajaxException(data);
|
||||
});
|
||||
this.fpnode.one('.fp-content').setContent('');
|
||||
if (data.errorcode === 'invalidfiletype') {
|
||||
// File type errors are not really errors, so report them less scarily.
|
||||
Y.use('moodle-core-notification-alert', function() {
|
||||
return new M.core.alert({
|
||||
title: M.util.get_string('error', 'moodle'),
|
||||
message: data.error,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
Y.use('moodle-core-notification-ajaxexception', function() {
|
||||
return new M.core.ajaxException(data);
|
||||
});
|
||||
}
|
||||
if (args.onerror) {
|
||||
args.onerror(id, data, p);
|
||||
} else {
|
||||
// Don't know what to do, so blank the dialogue to ensure it is not left in an inconsistent state.
|
||||
// This is not great. The user needs to re-click 'Upload file' to reset the display.
|
||||
this.fpnode.one('.fp-content').setContent('');
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if (data.msg) {
|
||||
// As far as I can tell, msg will never be set by any PHP code. -- Tim Oct 2024.
|
||||
scope.print_msg(data.msg, 'info');
|
||||
}
|
||||
// cache result if applicable
|
||||
|
17
repository/tests/behat/upload_file_type.feature
Normal file
17
repository/tests/behat/upload_file_type.feature
Normal file
@ -0,0 +1,17 @@
|
||||
@core @core_filepicker @_file_upload
|
||||
Feature: File type can be validated on upload
|
||||
While uploading files
|
||||
As a user
|
||||
I want the file type to be validated to save me from errors
|
||||
|
||||
@javascript
|
||||
Scenario: File-picker does not break if you upload the wrong file type
|
||||
Given I am on the "filemanager_hideif_disabledif_form" "core_form > Fixture" page logged in as "admin"
|
||||
When I click on "Add..." "link"
|
||||
And I select "Upload a file" repository in file picker
|
||||
And I set the field "Attachment" to "#dirroot#/lib/form/tests/fixtures/filemanager_hideif_disabledif_form.php"
|
||||
And I click on "Upload this file" "button" in the "File picker" "dialogue"
|
||||
Then I should see "Text file filetype cannot be accepted." in the "Error" "dialogue"
|
||||
And I click on "OK" "button" in the "Error" "dialogue"
|
||||
And I should see "Attachment" in the "File picker" "dialogue"
|
||||
And "Upload this file" "button" in the "File picker" "dialogue" should be visible
|
Loading…
x
Reference in New Issue
Block a user