Commit 1cd6b7bf authored by Astor Bizard's avatar Astor Bizard
Browse files

Temporary token now sent to execution server. Added prompt to load newer...

Temporary token now sent to execution server. Added prompt to load newer submission after execution.
parent 936db5de
This diff is collapsed.
......@@ -1737,6 +1737,44 @@ define(
}
});
var reloadFilesAfterExecution = function() {
$.ajax({
type: "POST",
url: options.loadajaxurl + 'getlastversion',
'data': JSON.stringify(options),
contentType: "application/json; charset=utf-8",
dataType: "json"
}).done(function(outcome) {
if (outcome.success && fileManager.getVersion() < outcome.response.version) {
// A more recent version exists, prompt user to load it.
showMessage(str('morerecentversionloadprompt'), {
title: str('morerecentversionsaved'),
yes: function() {
VPLUtil.requestAction('load', 'loading', options, options.loadajaxurl)
.done(function(response) {
var files = response.files;
for (var i = 0; i < files.length; i++) {
fileManager.addFile(files[i], true, VPLUtil.doNothing, showErrorMessage);
}
fileManager.fileListVisibleIfNeeded();
fileManager.resetModified();
fileManager.setVersion(response.version);
fileManager.fileListVisible(files.length > 5);
tabs.tabs('option', 'active', 0);
VPLUtil.afterAll('AfterLoadFiles', function() {
fileManager.resetModified();
updateMenu();
autoResizeTab();
adjustTabsTitles(false);
});
})
.fail(showErrorMessage);
}
});
}
});
};
var executionActions = {
'getConsole': function() {
return lastConsole;
......@@ -1747,19 +1785,20 @@ define(
if (lastConsole && lastConsole.isOpen()) {
lastConsole.close();
}
var afterExecution = function() {
if (ws.readyState != ws.OPEN) {
reloadFilesAfterExecution();
}
ws.close();
focusCurrentFile();
};
if (type == 'terminal') {
lastConsole = terminal;
terminal.connect(coninfo.executionURL, function() {
ws.close();
focusCurrentFile();
});
terminal.connect(coninfo.executionURL, afterExecution);
} else {
lastConsole = VNCClient;
VNCClient.connect(coninfo.secure, coninfo.server, coninfo.portToUse, coninfo.VNCpassword,
coninfo.executionPath, function() {
ws.close();
focusCurrentFile();
});
coninfo.executionPath, afterExecution);
}
},
'lastAction': false,
......
......@@ -121,6 +121,8 @@ class vpl_editor_util {
'interfacetheme',
'keyboard',
'maxfilesexceeded',
'morerecentversionloadprompt',
'morerecentversionsaved',
'new',
'next',
'load',
......
......@@ -118,6 +118,9 @@ try {
case 'getjails' :
$outcome->response->servers = vpl_jailserver_manager::get_https_server_list( $vpl->get_instance()->jailservers );
break;
case 'getlastversion' :
$outcome->response->version = $vpl->last_user_submission( $userid )->id;
break;
default :
throw new Exception( 'ajax action error: ' + $action );
}
......
......@@ -203,6 +203,8 @@ $string ['minsimlevel'] = 'Minimum similarity level to show';
$string ['moduleconfigtitle'] = 'VPL Module Config';
$string ['modulename'] = 'Virtual programming lab';
$string ['modulenameplural'] = 'Virtual programming labs';
$string ['morerecentversionloadprompt'] = 'A more recent version has been saved. Do you want to load it?';
$string ['morerecentversionsaved'] = 'More recent version saved';
$string ['multidelete'] = 'Multiple delete';
$string ['nevaluations'] = '{$a} automatic evaluations done';
$string ['new'] = 'New';
......
......@@ -181,6 +181,8 @@ $string ['minsimlevel'] = 'Niveau minimal de similarité à montrer';
$string ['moduleconfigtitle'] = 'Config. du module VPL';
$string ['modulename'] = 'Laboratoire virtuel de programmation (VPL)';
$string ['modulenameplural'] = 'Laboratoires virtuels de programmation';
$string ['morerecentversionloadprompt'] = 'Une version plus récente a été sauvegardée. Voulez-vous la charger ?';
$string ['morerecentversionsaved'] = 'Version plus récente sauvegardée';
$string ['multidelete'] = 'Suppression multiple';
$string ['new'] = 'Nouveau';
$string ['new_file_name'] = 'Nom du nouveau fichier';
......
......@@ -918,6 +918,7 @@ function vpl_get_webservice_available() {
}
function vpl_get_webservice_token($vpl) {
global $DB, $USER, $CFG;
require_once($CFG->dirroot . '/webservice/lib.php');
$now = time();
if ($USER->id <= 2) {
return '';
......@@ -962,6 +963,42 @@ function vpl_get_webservice_urlbase($vpl) {
. '&wstoken=' . $token . '&id=' . $vpl->get_course_module()->id . '&wsfunction=';
}
/**
* Retrieve or generate a temporary embedded webservice token for the given vpl and user.
* @param mod_vpl $vpl The VPL to get the token for.
* @param int $userid The id of the user to get the token for.
* @return string The token, or an empty string if service is unavailable.
*/
function vpl_get_temporary_webservice_token($vpl, $userid) {
global $CFG, $DB;
require_once($CFG->libdir . '/externallib.php');
if (! $CFG->enablewebservices) {
return '';
}
$service = $DB->get_record( 'external_services', array (
'shortname' => 'mod_vpl_edit',
'enabled' => 1
) );
if (empty( $service )) {
return '';
}
// If such a token already exists and is still valid, use it.
$tokens = $DB->get_records( 'external_tokens', array(
'tokentype' => EXTERNAL_TOKEN_EMBEDDED,
'userid' => $userid,
'externalserviceid' => $service->id,
'sid' => session_id(),
'contextid' => $vpl->get_context()->id
) );
foreach ($tokens as $token) {
if ($token->validuntil == 0 || $token->validuntil > time()) {
return $token->token;
}
}
// No such valid token found, generate a new one.
return external_generate_token(EXTERNAL_TOKEN_EMBEDDED, $service, $userid, $vpl->get_context()->id, time() + DAYSECS);
}
function vpl_timestamp_to_midday($timestamp) {
return $timestamp - ($timestamp + date('Z')) % 86400 + 43200;
}
......
......@@ -25,6 +25,7 @@
defined('MOODLE_INTERNAL') || die();
require_once(dirname(__FILE__).'/../../lib/gradelib.php');
require_once(dirname(__FILE__).'/locallib.php');
require_once(dirname(__FILE__).'/vpl_submission.class.php');
require_once(dirname(__FILE__).'/jail/jailserver_manager.class.php');
require_once(dirname(__FILE__).'/jail/running_processes.class.php');
......@@ -289,6 +290,7 @@ class mod_vpl_submission_CE extends mod_vpl_submission {
$info .= vpl_bash_export( 'MOODLE_USER_NAME', $user->username );
}
$info .= vpl_bash_export( 'MOODLE_USER_ID', $subinstance->userid );
$info .= vpl_bash_export( 'MOODLE_USER_TOKEN', vpl_get_temporary_webservice_token($vpl, $subinstance->userid) );
if ($type == 2) { // If evaluation add information.
$info .= vpl_bash_export( 'VPL_MAXTIME', $data->maxtime );
$info .= vpl_bash_export( 'VPL_MAXMEMORY', $data->maxmemory );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment