1
0
mirror of https://github.com/moodle/moodle.git synced 2025-05-07 16:56:15 +02:00

MDL-82177 file upload: default to path '/'when things go wrong

This 'fix' is basically a work-around, but one that is already used in
some places. Now it is used in all similar places.

Exactly what causes the current file path in a file manager to become
unset is still unclear to me, but it seems to be an obscure race
condition that is very hard to reproduce.

However, when it happens, currently we are effectively defaulting to
path '/undefined/'. Using '/' is never worse, and is infinitely better
in the case where the filepicker does not allow folders to be used
(which includes important cases like essay questions in a quiz, which
some people use for exams!). In that case, falling back to non-top-level
path leads to dataloss.

Also, this is all historic JavaScript which will get replaced in the
grand de-YUI-fication, so I think a pragmatic fix is justified here.
This commit is contained in:
Tim Hunt 2024-07-29 21:54:11 +01:00
parent 1a33da6637
commit 3e88ef17bf
3 changed files with 11 additions and 4 deletions

@ -1084,8 +1084,10 @@ M.form_dndupload.init = function(Y, options) {
if (this.options.author) {
formdata.append('author', this.options.author);
}
if (this.options.filemanager) { // Filepickers do not have folders
if (this.options.filemanager && this.options.filemanager.currentpath) { // Filepickers do not have folders
formdata.append('savepath', this.options.filemanager.currentpath);
} else {
formdata.append('savepath', '/');
}
formdata.append('title', filename);
if (overwrite) {

@ -159,7 +159,7 @@ M.form_filemanager.init = function(Y, options) {
}
params['sesskey'] = M.cfg.sesskey;
params['client_id'] = this.client_id;
params['filepath'] = this.currentpath;
params['filepath'] = this.currentpath || '/';
params['itemid'] = this.options.itemid?this.options.itemid:0;
if (args['params']) {
for (i in args['params']) {

@ -1281,7 +1281,12 @@ M.core_filepicker.init = function(Y, options) {
var title = selectnode.one('.fp-saveas input').get('value');
var filesource = selectnode.one('form #filesource-'+client_id).get('value');
var filesourcekey = selectnode.one('form #filesourcekey-'+client_id).get('value');
var params = {'title':title, 'source':filesource, 'savepath': this.options.savepath, sourcekey: filesourcekey};
var params = {
'title': title,
'source': filesource,
'savepath': this.options.savepath || '/',
'sourcekey': filesourcekey,
};
var license = selectnode.one('.fp-setlicense select');
if (license) {
params['license'] = license.get('value');
@ -1886,7 +1891,7 @@ M.core_filepicker.init = function(Y, options) {
scope: scope,
action:'upload',
client_id: client_id,
params: {'savepath':scope.options.savepath},
params: {'savepath': scope.options.savepath || '/'},
repository_id: scope.active_repo.id,
form: {id: id, upload:true},
onerror: function(id, o, args) {