remove old upload implementation
add viewer of file submissions
This commit is contained in:
@@ -683,6 +683,18 @@ namespace Database {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Executes the prepared statement SELECT_FREELANCER_FILE_SUBMISSION_BASE_DATA
|
||||||
|
* Takes an open pqxx::connection and the freelancer email
|
||||||
|
* returns a list of file submissions with the columns filename, filesizemb, uploaddate
|
||||||
|
*/
|
||||||
|
pqxx::result executePreparedStatement_SELECT_FREELANCER_FILE_SUBMISSION_BASE_DATA(pqxx::connection &connection, const std::string& freelancerEmail) {
|
||||||
|
pqxx::work work(connection);
|
||||||
|
pqxx::result result = work.exec_prepared(PREPARED_STATEMENT_SELECT_FREELANCER_FILE_SUBMISSION_BASE_DATA, freelancerEmail);
|
||||||
|
work.commit();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Executes the prepared statement SELECT_FREELANCER_FILE_SUBMISSION_PATH
|
* Executes the prepared statement SELECT_FREELANCER_FILE_SUBMISSION_PATH
|
||||||
* Takes an open pqxx::connection the file name and the freelancer email
|
* Takes an open pqxx::connection the file name and the freelancer email
|
||||||
|
@@ -240,7 +240,7 @@ namespace DatabaseStatementConstCollection {
|
|||||||
* Name and Statement for prepared statement to select file submission data for submission selection interface
|
* Name and Statement for prepared statement to select file submission data for submission selection interface
|
||||||
*/
|
*/
|
||||||
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_FILE_SUBMISSION_BASE_DATA = "selectFreelancerFileSubmissionBaseData";
|
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_FILE_SUBMISSION_BASE_DATA = "selectFreelancerFileSubmissionBaseData";
|
||||||
const static std::string SQL_STATEMENT_SELECT_FREELANCER_FILE_SUBMISSION_BASE_DATA = "select filename, round(filesize / 1024.0 / 1024.0, 4) as filesizemb, uploaddate from freelancersubmissions where freelancerid = (select freelancers.id from freelancers where emailaddress = $1)";
|
const static std::string SQL_STATEMENT_SELECT_FREELANCER_FILE_SUBMISSION_BASE_DATA = "select filename, round(coalesce(filesize, 0) / 1024.0 / 1024.0, 4) as filesizemb, uploaddate from freelancersubmissions where freelancerid = (select freelancers.id from freelancers where emailaddress = $1)";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Name and Statement for prepared statement to select MB of used freelancer storage
|
* Name and Statement for prepared statement to select MB of used freelancer storage
|
||||||
|
77
src/main.cpp
77
src/main.cpp
@@ -1160,82 +1160,6 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
CROW_ROUTE(app, "/freelancer/submissionManagement/add/fulfillment").methods(crow::HTTPMethod::Post)
|
|
||||||
([&, configuration](const crow::request& postRequest) {
|
|
||||||
auto& cookieCtx = app.get_context<crow::CookieParser>(postRequest);
|
|
||||||
if (Utilities::checkCookieLoginState(configuration, cookieCtx)) {
|
|
||||||
pqxx::connection databaseConnection(configuration.databaseConnectionString);
|
|
||||||
Database::prepareStatements(databaseConnection, {
|
|
||||||
ID_SELECT_FREELANCER_ID,
|
|
||||||
ID_SELECT_FREELANCER_NAME
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
string freelancerName, freelancerID;
|
|
||||||
pqxx::result freelancerNameResult = Database::executePreparedStatement_SELECT_FREELANCER_NAME(databaseConnection, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL));
|
|
||||||
freelancerName = freelancerNameResult.at(0).at(0).c_str();
|
|
||||||
pqxx::result freelancerIDResult = Database::executePreparedStatement_SELECT_FREELANCER_ID(databaseConnection, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL));
|
|
||||||
freelancerID = freelancerIDResult.at(0).at(0).c_str();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
crow::multipart::message multipartMessage(postRequest);
|
|
||||||
return crow::response(400);
|
|
||||||
for (const auto& part : multipartMessage.part_map)
|
|
||||||
{
|
|
||||||
const auto& mustacheSubmissionNameValue = part.first;
|
|
||||||
const auto& fileSubmission = part.second;
|
|
||||||
if (MUSTACHE_FREELANCER_SUBMISSION_NAME == mustacheSubmissionNameValue)
|
|
||||||
{
|
|
||||||
auto contentDispositionIt = fileSubmission.headers.find("Content-Disposition");
|
|
||||||
|
|
||||||
if (contentDispositionIt == fileSubmission.headers.end())
|
|
||||||
return crow::response(400, "Content-Disposition could not be found");
|
|
||||||
|
|
||||||
auto filenameIt = contentDispositionIt->second.params.find("filename");
|
|
||||||
if (filenameIt == contentDispositionIt->second.params.end())
|
|
||||||
return crow::response(400, "File Submission does not have a filename");
|
|
||||||
|
|
||||||
if (!Utilities::checkFiletypeValidity(configuration, filenameIt->second))
|
|
||||||
return crow::response(400, "Submitted File does not have a valid filetype");
|
|
||||||
|
|
||||||
if (!Utilities::validateFileSize(configuration, fileSubmission.body))
|
|
||||||
return crow::response(400, "File Size is not valid");
|
|
||||||
|
|
||||||
const std::string outputFolderPath = Utilities::generateSubmissionFolderPath(configuration, freelancerName, freelancerID);
|
|
||||||
|
|
||||||
if(!Utilities::validateFolderPath(outputFolderPath))
|
|
||||||
return crow::response(400, "Unable to write to Freelancer folder");
|
|
||||||
|
|
||||||
const std::string outputFilename = filenameIt->second;
|
|
||||||
const std::string outputFilePath = Utilities::generateSubmissionFilePath(outputFolderPath, outputFilename);
|
|
||||||
cout << outputFolderPath << endl;
|
|
||||||
cout << outputFilePath << endl;
|
|
||||||
if(!Utilities::validateFilePath(outputFilePath))
|
|
||||||
return crow::response(400, "file already exists - hash collision");
|
|
||||||
|
|
||||||
std::ofstream outputFileStream(outputFilePath);
|
|
||||||
if (!outputFileStream)
|
|
||||||
return crow::response(500, "File could not be written to disk");
|
|
||||||
|
|
||||||
outputFileStream << fileSubmission.body;
|
|
||||||
outputFileStream.close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return crow::response(400, "Mustache Submission name could not be found in the request");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return crow::response(200);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//ERROR not logged in
|
|
||||||
return crow::response(403, "Not logged in");
|
|
||||||
}
|
|
||||||
});*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Page for freelancer to view existing submissions
|
* Page for freelancer to view existing submissions
|
||||||
*/
|
*/
|
||||||
@@ -1244,6 +1168,7 @@ int main(int argc, char *argv[]) {
|
|||||||
auto& cookieCtx = app.get_context<crow::CookieParser>(getRequest);
|
auto& cookieCtx = app.get_context<crow::CookieParser>(getRequest);
|
||||||
crow::mustache::context ctx;
|
crow::mustache::context ctx;
|
||||||
if (Utilities::checkCookieLoginState(configuration, cookieCtx)) {
|
if (Utilities::checkCookieLoginState(configuration, cookieCtx)) {
|
||||||
|
ctx = Utilities::getFreelancerSubmissions(configuration, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL));
|
||||||
|
|
||||||
|
|
||||||
ctx[MUSTACHE_COOKIE_LOGGED_IN] = true;
|
ctx[MUSTACHE_COOKIE_LOGGED_IN] = true;
|
||||||
|
@@ -687,6 +687,18 @@ namespace Utilities {
|
|||||||
return resultJsonFreelancerTemplate;
|
return resultJsonFreelancerTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Gets the freelancer submissions and converts them into a wvalue JSON under the name "submissions"
|
||||||
|
* takes config and freelancer email
|
||||||
|
*/
|
||||||
|
crow::json::wvalue getFreelancerSubmissions(const Utilities::config& configuration, const std::string& emailAddress) {
|
||||||
|
pqxx::connection databaseConnection(configuration.databaseConnectionString);
|
||||||
|
Database::prepareStatement(databaseConnection, ID_SELECT_FREELANCER_FILE_SUBMISSION_BASE_DATA);
|
||||||
|
pqxx::result resultJsonFreelancerSubmissions = Database::executePreparedStatement_SELECT_FREELANCER_FILE_SUBMISSION_BASE_DATA(databaseConnection, emailAddress);
|
||||||
|
crow::json::wvalue jsonFreelancerSubmissions = Database::convertResultToJSON(resultJsonFreelancerSubmissions, "submissions");
|
||||||
|
return jsonFreelancerSubmissions;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Gets the freelancer alias and converts them into a wvalue JSON under the name "alias"
|
* Gets the freelancer alias and converts them into a wvalue JSON under the name "alias"
|
||||||
* takes config and freelancer email
|
* takes config and freelancer email
|
||||||
|
@@ -8,12 +8,34 @@
|
|||||||
Please Log in.
|
Please Log in.
|
||||||
{{/COOKIE_LOGGED_IN}}
|
{{/COOKIE_LOGGED_IN}}
|
||||||
{{#COOKIE_LOGGED_IN}}
|
{{#COOKIE_LOGGED_IN}}
|
||||||
<form action="/freelancer/submissionManagement/view/delete" method="post">
|
<table>
|
||||||
<button type="submit" class="button">Delete Submission</button>
|
<tr>
|
||||||
</form>
|
<th>Name</th>
|
||||||
<form action="/freelancer/submissionManagement/view/generateLink" method="post">
|
<th>Size (MB)</th>
|
||||||
<button type="submit" class="button">Generate Link to submission</button>
|
<th>Upload date</th>
|
||||||
</form>
|
</tr>
|
||||||
|
{{#submissions}}
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
<form action="/freelancer/submissionManagement/view/{{filename}}" method="get">
|
||||||
|
<button type="submit" class="button">{{filename}}</button>
|
||||||
|
</form>
|
||||||
|
</th>
|
||||||
|
<th>{{filesizemb}} MB</th>
|
||||||
|
<th>{{uploaddate}}</th>
|
||||||
|
<th>
|
||||||
|
<form action="/freelancer/submissionManagement/view/delete" method="post">
|
||||||
|
<button type="submit" name="filename" value="{{filename}}" class="button">Delete</button>
|
||||||
|
</form>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<form action="/freelancer/submissionManagement/view/generateLink" method="post">
|
||||||
|
<button type="submit" name="filename" value="{{filename}}" class="button">Generate Link</button>
|
||||||
|
</form>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
{{/submissions}}
|
||||||
|
</table>
|
||||||
{{/COOKIE_LOGGED_IN}}
|
{{/COOKIE_LOGGED_IN}}
|
||||||
{{> templateIncludes/freelancerLoginSignupProfileLogoutInterface.html.html}}
|
{{> templateIncludes/freelancerLoginSignupProfileLogoutInterface.html.html}}
|
||||||
<br>
|
<br>
|
||||||
|
Reference in New Issue
Block a user