Merge pull request #6893 from Atlante45/fix/new-assignment

Fix DS new assignment feature
This commit is contained in:
Stephen Birarda 2016-01-22 16:44:35 -08:00
commit 3c2923f50a

View file

@ -1148,13 +1148,22 @@ QJsonObject DomainServer::jsonObjectForNode(const SharedNodePointer& node) {
return nodeJson; return nodeJson;
} }
const char ASSIGNMENT_SCRIPT_HOST_LOCATION[] = "resources/web/assignment"; QDir pathForAssignmentScriptsDirectory() {
static const QString SCRIPTS_DIRECTORY_NAME = "/scripts/";
QDir directory(ServerPathUtils::getDataDirectory() + SCRIPTS_DIRECTORY_NAME);
if (!directory.exists()) {
directory.mkpath(".");
qInfo() << "Created path to " << directory.path();
}
return directory;
}
QString pathForAssignmentScript(const QUuid& assignmentUUID) { QString pathForAssignmentScript(const QUuid& assignmentUUID) {
QString newPath { ServerPathUtils::getDataDirectory() + "/" + QString(ASSIGNMENT_SCRIPT_HOST_LOCATION) }; QDir directory = pathForAssignmentScriptsDirectory();
newPath += "/scripts/";
// append the UUID for this script as the new filename, remove the curly braces // append the UUID for this script as the new filename, remove the curly braces
newPath += uuidStringWithoutCurlyBraces(assignmentUUID); return directory.absoluteFilePath(uuidStringWithoutCurlyBraces(assignmentUUID));
return newPath;
} }
const QString URI_OAUTH = "/oauth"; const QString URI_OAUTH = "/oauth";
@ -1162,7 +1171,6 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
const QString JSON_MIME_TYPE = "application/json"; const QString JSON_MIME_TYPE = "application/json";
const QString URI_ASSIGNMENT = "/assignment"; const QString URI_ASSIGNMENT = "/assignment";
const QString URI_ASSIGNMENT_SCRIPTS = URI_ASSIGNMENT + "/scripts";
const QString URI_NODES = "/nodes"; const QString URI_NODES = "/nodes";
const QString URI_SETTINGS = "/settings"; const QString URI_SETTINGS = "/settings";
@ -1203,13 +1211,14 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
if (matchingAssignment && matchingAssignment->getType() == Assignment::AgentType) { if (matchingAssignment && matchingAssignment->getType() == Assignment::AgentType) {
// we have a matching assignment and it is for the right type, have the HTTP manager handle it // we have a matching assignment and it is for the right type, have the HTTP manager handle it
// via correct URL for the script so the client can download // via correct URL for the script so the client can download
QFile scriptFile(pathForAssignmentScript(matchingAssignment->getUUID()));
QUrl scriptURL = url;
scriptURL.setPath(URI_ASSIGNMENT + "/scripts/" if (scriptFile.exists() && scriptFile.open(QIODevice::ReadOnly)) {
+ uuidStringWithoutCurlyBraces(matchingAssignment->getUUID())); connection->respond(HTTPConnection::StatusCode200, scriptFile.readAll(), "application/javascript");
} else {
// have the HTTPManager serve the appropriate script file connection->respond(HTTPConnection::StatusCode404, "Resource not found.");
return _httpManager.handleHTTPRequest(connection, scriptURL, true); }
return true;
} }
// request not handled // request not handled