Loading editor/src/webedit_api.cpp +10 −4 Original line number Diff line number Diff line Loading @@ -971,14 +971,19 @@ void webedit::Api::handleSaveDocument(libhttppp::HttpRequest &curreq, std::string body = getRequestBody(curreq); json_object *req = json_tokener_parse(body.c_str()); json_object *nameObj = nullptr; if (req) json_object_object_get_ex(req, "name", &nameObj); json_object *nameObj = nullptr, *groupObj = nullptr; if (req) { json_object_object_get_ex(req, "name", &nameObj); json_object_object_get_ex(req, "group", &groupObj); } auto &doc = getDocState(sessionid); std::lock_guard<std::mutex> lk(doc.mtx); if (nameObj) doc.currentDocName = json_object_get_string(nameObj); if (groupObj) doc.currentDocGroup = json_object_get_string(groupObj); std::string xml = exportTreeXml(doc); std::string docId; Loading @@ -990,16 +995,17 @@ void webedit::Api::handleSaveDocument(libhttppp::HttpRequest &curreq, _session.getData(sessionid, "domain", domain); if (doc.currentDocId.empty()) { docId = _db.saveDocument(uid, domain, doc.currentDocName, xml, author); docId = _db.saveDocument(uid, domain, doc.currentDocName, xml, author, doc.currentDocGroup); doc.currentDocId = docId; } else { docId = _db.updateDocument(uid, doc.currentDocId, doc.currentDocName, xml, author); docId = _db.updateDocument(uid, doc.currentDocId, doc.currentDocName, xml, author, doc.currentDocGroup); } json_object *resp = json_object_new_object(); json_object_object_add(resp, "status", json_object_new_string("ok")); json_object_object_add(resp, "id", json_object_new_string(docId.c_str())); json_object_object_add(resp, "name", json_object_new_string(doc.currentDocName.c_str())); json_object_object_add(resp, "group", json_object_new_string(doc.currentDocGroup.c_str())); sendJson(curreq, resp); json_object_put(resp); if (req) json_object_put(req); Loading editor/src/webedit_api.h +1 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,7 @@ namespace webedit { blogi::webedit::EditPlugin *root = nullptr; std::string currentDocId; std::string currentDocName; std::string currentDocGroup; std::vector<std::unique_ptr<blogi::webedit::EditPlugin, blogi::webedit::EditPluginDeleter>> ownedElements; std::mutex mtx; Loading editor/src/webedit_db.cpp +25 −9 Original line number Diff line number Diff line Loading @@ -81,6 +81,7 @@ void webedit::Database::initTables() { << "id " << _db->getUUIDType(sql) << "," << "owner_uid text NOT NULL," << "domain text NOT NULL DEFAULT ''," << "group_name varchar(255) NOT NULL DEFAULT ''," << "name varchar(255) NOT NULL," << "xml text NOT NULL," << "created timestamp DEFAULT CURRENT_TIMESTAMP," Loading @@ -90,6 +91,16 @@ void webedit::Database::initTables() { _db->exec(sql, res); // Migration: add group_name column if missing sql.clear(); res.clear(); try { sql << "ALTER TABLE documents ADD COLUMN group_name varchar(255) NOT NULL DEFAULT '';"; _db->exec(sql, res); } catch (...) {} sql.clear(); res.clear(); _db->exec(sql, res); sql.clear(); res.clear(); Loading Loading @@ -207,18 +218,20 @@ void webedit::Database::setOption(const std::string &key, const std::string &val std::string webedit::Database::saveDocument(const std::string &ownerUid, const std::string &domain, const std::string &name, const std::string &xml, const std::string &author) { const std::string &author, const std::string &group) { uuid::uuid docId; docId.generate(); dbpp::SQL sql; dbpp::DBResult res; std::vector<char> escapedName, escapedXml, escapedUid, escapedDomain; std::vector<char> escapedName, escapedXml, escapedUid, escapedDomain, escapedGroup; sql << "INSERT INTO documents (id, owner_uid, domain, name, xml) VALUES ('" sql << "INSERT INTO documents (id, owner_uid, domain, group_name, name, xml) VALUES ('" << docId.c_str() << "','" << dbpp::SQL::escaped(escapedUid, ownerUid.c_str()) << "','" << dbpp::SQL::escaped(escapedDomain, domain.c_str()) << "','" << dbpp::SQL::escaped(escapedGroup, group.c_str()) << "','" << dbpp::SQL::escaped(escapedName, name.c_str()) << "','" << dbpp::SQL::escaped(escapedXml, xml.c_str()) << "');"; Loading Loading @@ -249,18 +262,20 @@ std::string webedit::Database::updateDocument(const std::string &ownerUid, const std::string &id, const std::string &name, const std::string &xml, const std::string &author) { const std::string &author, const std::string &group) { dbpp::SQL sql; dbpp::DBResult res; std::vector<char> escapedName, escapedXml, escapedId, escapedUid; std::vector<char> escapedName, escapedXml, escapedId, escapedUid, escapedGroup; sql << "UPDATE documents SET name='" sql << "UPDATE documents SET group_name='" << dbpp::SQL::escaped(escapedGroup, group.c_str()) << "', name='" << dbpp::SQL::escaped(escapedName, name.c_str()) << "', xml='" << dbpp::SQL::escaped(escapedXml, xml.c_str()) << "', modified=CURRENT_TIMESTAMP WHERE id='" << dbpp::SQL::escaped(escapedId, id.c_str()) << "' AND owner_uid='" << dbpp::SQL::escaped(escapedUid, ownerUid.c_str()) << "';"; << dbpp::SQL::escaped(escapedUid, ownerUid.c_str()) << "';" _db->exec(sql, res); Loading Loading @@ -366,9 +381,9 @@ std::string webedit::Database::listDocuments(const std::string &domain) { dbpp::DBResult res; std::vector<char> escapedDomain; sql << "SELECT id, name, created, modified FROM documents WHERE domain='" sql << "SELECT id, name, created, modified, group_name FROM documents WHERE domain='" << dbpp::SQL::escaped(escapedDomain, domain.c_str()) << "' ORDER BY modified DESC;"; << "' ORDER BY group_name, name, modified DESC;" int rows = _db->exec(sql, res); Loading @@ -380,6 +395,7 @@ std::string webedit::Database::listDocuments(const std::string &domain) { json_object_object_add(obj, "name", json_object_new_string(res[i][1])); json_object_object_add(obj, "created", json_object_new_string(res[i][2])); json_object_object_add(obj, "modified", json_object_new_string(res[i][3])); json_object_object_add(obj, "group", json_object_new_string(res[i][4])); json_object_array_add(arr, obj); } Loading editor/src/webedit_db.h +4 −2 Original line number Diff line number Diff line Loading @@ -43,10 +43,12 @@ namespace webedit { // Document CRUD (per-user + per-domain) std::string saveDocument(const std::string &ownerUid, const std::string &domain, const std::string &name, const std::string &xml, const std::string &author = ""); const std::string &author = "", const std::string &group = ""); std::string updateDocument(const std::string &ownerUid, const std::string &id, const std::string &name, const std::string &xml, const std::string &author = ""); const std::string &author = "", const std::string &group = ""); bool loadDocument(const std::string &ownerUid, const std::string &id, std::string &name, std::string &xml); bool deleteDocument(const std::string &ownerUid, const std::string &id); Loading Loading
editor/src/webedit_api.cpp +10 −4 Original line number Diff line number Diff line Loading @@ -971,14 +971,19 @@ void webedit::Api::handleSaveDocument(libhttppp::HttpRequest &curreq, std::string body = getRequestBody(curreq); json_object *req = json_tokener_parse(body.c_str()); json_object *nameObj = nullptr; if (req) json_object_object_get_ex(req, "name", &nameObj); json_object *nameObj = nullptr, *groupObj = nullptr; if (req) { json_object_object_get_ex(req, "name", &nameObj); json_object_object_get_ex(req, "group", &groupObj); } auto &doc = getDocState(sessionid); std::lock_guard<std::mutex> lk(doc.mtx); if (nameObj) doc.currentDocName = json_object_get_string(nameObj); if (groupObj) doc.currentDocGroup = json_object_get_string(groupObj); std::string xml = exportTreeXml(doc); std::string docId; Loading @@ -990,16 +995,17 @@ void webedit::Api::handleSaveDocument(libhttppp::HttpRequest &curreq, _session.getData(sessionid, "domain", domain); if (doc.currentDocId.empty()) { docId = _db.saveDocument(uid, domain, doc.currentDocName, xml, author); docId = _db.saveDocument(uid, domain, doc.currentDocName, xml, author, doc.currentDocGroup); doc.currentDocId = docId; } else { docId = _db.updateDocument(uid, doc.currentDocId, doc.currentDocName, xml, author); docId = _db.updateDocument(uid, doc.currentDocId, doc.currentDocName, xml, author, doc.currentDocGroup); } json_object *resp = json_object_new_object(); json_object_object_add(resp, "status", json_object_new_string("ok")); json_object_object_add(resp, "id", json_object_new_string(docId.c_str())); json_object_object_add(resp, "name", json_object_new_string(doc.currentDocName.c_str())); json_object_object_add(resp, "group", json_object_new_string(doc.currentDocGroup.c_str())); sendJson(curreq, resp); json_object_put(resp); if (req) json_object_put(req); Loading
editor/src/webedit_api.h +1 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,7 @@ namespace webedit { blogi::webedit::EditPlugin *root = nullptr; std::string currentDocId; std::string currentDocName; std::string currentDocGroup; std::vector<std::unique_ptr<blogi::webedit::EditPlugin, blogi::webedit::EditPluginDeleter>> ownedElements; std::mutex mtx; Loading
editor/src/webedit_db.cpp +25 −9 Original line number Diff line number Diff line Loading @@ -81,6 +81,7 @@ void webedit::Database::initTables() { << "id " << _db->getUUIDType(sql) << "," << "owner_uid text NOT NULL," << "domain text NOT NULL DEFAULT ''," << "group_name varchar(255) NOT NULL DEFAULT ''," << "name varchar(255) NOT NULL," << "xml text NOT NULL," << "created timestamp DEFAULT CURRENT_TIMESTAMP," Loading @@ -90,6 +91,16 @@ void webedit::Database::initTables() { _db->exec(sql, res); // Migration: add group_name column if missing sql.clear(); res.clear(); try { sql << "ALTER TABLE documents ADD COLUMN group_name varchar(255) NOT NULL DEFAULT '';"; _db->exec(sql, res); } catch (...) {} sql.clear(); res.clear(); _db->exec(sql, res); sql.clear(); res.clear(); Loading Loading @@ -207,18 +218,20 @@ void webedit::Database::setOption(const std::string &key, const std::string &val std::string webedit::Database::saveDocument(const std::string &ownerUid, const std::string &domain, const std::string &name, const std::string &xml, const std::string &author) { const std::string &author, const std::string &group) { uuid::uuid docId; docId.generate(); dbpp::SQL sql; dbpp::DBResult res; std::vector<char> escapedName, escapedXml, escapedUid, escapedDomain; std::vector<char> escapedName, escapedXml, escapedUid, escapedDomain, escapedGroup; sql << "INSERT INTO documents (id, owner_uid, domain, name, xml) VALUES ('" sql << "INSERT INTO documents (id, owner_uid, domain, group_name, name, xml) VALUES ('" << docId.c_str() << "','" << dbpp::SQL::escaped(escapedUid, ownerUid.c_str()) << "','" << dbpp::SQL::escaped(escapedDomain, domain.c_str()) << "','" << dbpp::SQL::escaped(escapedGroup, group.c_str()) << "','" << dbpp::SQL::escaped(escapedName, name.c_str()) << "','" << dbpp::SQL::escaped(escapedXml, xml.c_str()) << "');"; Loading Loading @@ -249,18 +262,20 @@ std::string webedit::Database::updateDocument(const std::string &ownerUid, const std::string &id, const std::string &name, const std::string &xml, const std::string &author) { const std::string &author, const std::string &group) { dbpp::SQL sql; dbpp::DBResult res; std::vector<char> escapedName, escapedXml, escapedId, escapedUid; std::vector<char> escapedName, escapedXml, escapedId, escapedUid, escapedGroup; sql << "UPDATE documents SET name='" sql << "UPDATE documents SET group_name='" << dbpp::SQL::escaped(escapedGroup, group.c_str()) << "', name='" << dbpp::SQL::escaped(escapedName, name.c_str()) << "', xml='" << dbpp::SQL::escaped(escapedXml, xml.c_str()) << "', modified=CURRENT_TIMESTAMP WHERE id='" << dbpp::SQL::escaped(escapedId, id.c_str()) << "' AND owner_uid='" << dbpp::SQL::escaped(escapedUid, ownerUid.c_str()) << "';"; << dbpp::SQL::escaped(escapedUid, ownerUid.c_str()) << "';" _db->exec(sql, res); Loading Loading @@ -366,9 +381,9 @@ std::string webedit::Database::listDocuments(const std::string &domain) { dbpp::DBResult res; std::vector<char> escapedDomain; sql << "SELECT id, name, created, modified FROM documents WHERE domain='" sql << "SELECT id, name, created, modified, group_name FROM documents WHERE domain='" << dbpp::SQL::escaped(escapedDomain, domain.c_str()) << "' ORDER BY modified DESC;"; << "' ORDER BY group_name, name, modified DESC;" int rows = _db->exec(sql, res); Loading @@ -380,6 +395,7 @@ std::string webedit::Database::listDocuments(const std::string &domain) { json_object_object_add(obj, "name", json_object_new_string(res[i][1])); json_object_object_add(obj, "created", json_object_new_string(res[i][2])); json_object_object_add(obj, "modified", json_object_new_string(res[i][3])); json_object_object_add(obj, "group", json_object_new_string(res[i][4])); json_object_array_add(arr, obj); } Loading
editor/src/webedit_db.h +4 −2 Original line number Diff line number Diff line Loading @@ -43,10 +43,12 @@ namespace webedit { // Document CRUD (per-user + per-domain) std::string saveDocument(const std::string &ownerUid, const std::string &domain, const std::string &name, const std::string &xml, const std::string &author = ""); const std::string &author = "", const std::string &group = ""); std::string updateDocument(const std::string &ownerUid, const std::string &id, const std::string &name, const std::string &xml, const std::string &author = ""); const std::string &author = "", const std::string &group = ""); bool loadDocument(const std::string &ownerUid, const std::string &id, std::string &name, std::string &xml); bool deleteDocument(const std::string &ownerUid, const std::string &id); Loading