Skip to content

Commit

Permalink
MDL-34182 Repositories: Check for and warn on invalid output in the f…
Browse files Browse the repository at this point in the history
…ile picker
  • Loading branch information
andrewnicols committed Dec 13, 2013
1 parent 84008f4 commit f82f12e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
20 changes: 6 additions & 14 deletions repository/filepicker.js
Expand Up @@ -583,27 +583,19 @@ M.core_filepicker.init = function(Y, options) {
method: 'POST',
on: {
complete: function(id,o,p) {
if (!o) {
// TODO
alert('IO FATAL');
return;
}
var data = null;
try {
data = Y.JSON.parse(o.responseText);
} catch(e) {
scope.print_msg(M.str.repository.invalidjson, 'error');
scope.display_error(M.str.repository.invalidjson+'<pre>'+stripHTML(o.responseText)+'</pre>', 'invalidjson')
return;
if (o && o.status && o.status > 0) {
new M.core.exception(e);
return;
}
}
// error checking
if (data && data.error) {
scope.print_msg(data.error, 'error');
if (args.onerror) {
args.onerror(id,data,p);
} else {
this.fpnode.one('.fp-content').setContent('');
}
new M.core.ajaxException(data);
this.fpnode.one('.fp-content').setContent('');
return;
} else {
if (data.msg) {
Expand Down
14 changes: 14 additions & 0 deletions repository/repository_ajax.php
Expand Up @@ -74,6 +74,8 @@
'ajax' => true,
'mimetypes' => $accepted_types
);

ajax_capture_output();
$repo = repository::get_repository_by_id($repo_id, $contextid, $repooptions);

// Check permissions
Expand Down Expand Up @@ -127,6 +129,7 @@
if ($repo->check_login()) {
$listing = repository::prepare_listing($repo->get_listing($req_path, $page));
$listing['repo_id'] = $repo_id;
ajax_check_captured_output();
echo json_encode($listing);
break;
} else {
Expand All @@ -135,23 +138,27 @@
case 'login':
$listing = $repo->print_login();
$listing['repo_id'] = $repo_id;
ajax_check_captured_output();
echo json_encode($listing);
break;
case 'logout':
$logout = $repo->logout();
$logout['repo_id'] = $repo_id;
ajax_check_captured_output();
echo json_encode($logout);
break;
case 'searchform':
$search_form['repo_id'] = $repo_id;
$search_form['form'] = $repo->print_search();
$search_form['allowcaching'] = true;
ajax_check_captured_output();
echo json_encode($search_form);
break;
case 'search':
$search_result = repository::prepare_listing($repo->search($search_text, (int)$page));
$search_result['repo_id'] = $repo_id;
$search_result['issearchresult'] = true;
ajax_check_captured_output();
echo json_encode($search_result);
break;
case 'download':
Expand Down Expand Up @@ -190,6 +197,7 @@
$info['file'] = $saveas_filename;
$info['type'] = 'link';
$info['url'] = $link;
ajax_check_captured_output();
echo json_encode($info);
die;
} else {
Expand Down Expand Up @@ -281,6 +289,7 @@
// You can cache reository file in this callback
// or complete other tasks.
$repo->cache_file_by_reference($reference, $storedfile);
ajax_check_captured_output();
echo json_encode($event);
die;
} else if ($repo->has_moodle_files()) {
Expand All @@ -291,6 +300,7 @@
// {@link repository::copy_to_area()}.
$fileinfo = $repo->copy_to_area($reference, $record, $maxbytes, $areamaxbytes);

ajax_check_captured_output();
echo json_encode($fileinfo);
die;
} else {
Expand All @@ -316,12 +326,14 @@
$info['e'] = get_string('error', 'moodle');
}
}
ajax_check_captured_output();
echo json_encode($info);
die;
}
break;
case 'upload':
$result = $repo->upload($saveas_filename, $maxbytes);
ajax_check_captured_output();
echo json_encode($result);
break;

Expand All @@ -334,13 +346,15 @@
$newfilename = required_param('newfilename', PARAM_FILE);

$info = repository::overwrite_existing_draftfile($itemid, $filepath, $filename, $newfilepath, $newfilename);
ajax_check_captured_output();
echo json_encode($info);
break;

case 'deletetmpfile':
// delete tmp file
$newfilepath = required_param('newfilepath', PARAM_PATH);
$newfilename = required_param('newfilename', PARAM_FILE);
ajax_check_captured_output();
echo json_encode(repository::delete_tempfile_from_draft($itemid, $newfilepath, $newfilename));

break;
Expand Down

0 comments on commit f82f12e

Please sign in to comment.