diff --git a/database/categorydaosqlite.cpp b/database/categorydaosqlite.cpp index b5848af..c062c2a 100644 --- a/database/categorydaosqlite.cpp +++ b/database/categorydaosqlite.cpp @@ -102,23 +102,27 @@ std::vector CategoryDaoSqlite::fetchMembers(std::string name, QueryOption SqliteQueryOption queryOption{o}; std::string queryoptions = - queryOption.setOrderByColumn("name").setVisibleColumnName("page.visible").setPrependWhere(false).build(); + queryOption.setOrderByColumn("name").setListedColumnName("page.listed").setPrependWhere(false).build(); try { - auto query = *db << "SELECT page.id, page.name AS name, page.title, page.lastrevision, page.visible FROM " - "categorymember INNER JOIN page ON page.id = " - "categorymember.page WHERE category = (SELECT id FROM category WHERE name = ? ) AND " + - queryoptions - << name; - query >> [&](unsigned int id, std::string name, std::string title, unsigned int lastrevision, bool visible) + auto query = + *db + << "SELECT page.id, page.name AS name, page.title, page.lastrevision, page.listed, page.feedlisted FROM " + "categorymember INNER JOIN page ON page.id = " + "categorymember.page WHERE category = (SELECT id FROM category WHERE name = ? ) AND " + + queryoptions + << name; + query >> [&](unsigned int id, std::string name, std::string title, unsigned int lastrevision, bool listed, + bool feedlisted) { Page p; p.name = name; p.pageid = id; p.title = title; p.current_revision = lastrevision; - p.listed = visible; + p.listed = listed; + p.feedlisted = feedlisted; result.push_back(p); }; } diff --git a/database/pagedaosqlite.cpp b/database/pagedaosqlite.cpp index f0676c0..056d943 100644 --- a/database/pagedaosqlite.cpp +++ b/database/pagedaosqlite.cpp @@ -57,10 +57,12 @@ std::optional PageDaoSqlite::findByTitle(std::string title) Page result; try { - auto ps = *db << "SELECT id, name, title, lastrevision, visible, (SELECT name FROM page WHERE id = parent) " - "FROM page WHERE title = ?"; + auto ps = + *db + << "SELECT id, name, title, lastrevision, listed, feedlisted, (SELECT name FROM page WHERE id = parent) " + "FROM page WHERE title = ?"; ps << title >> std::tie(result.pageid, result.name, result.title, result.current_revision, result.listed, - result.parentpage); + result.feedlisted, result.parentpage); } catch(const sqlite::errors::no_rows &e) { @@ -80,10 +82,13 @@ std::optional PageDaoSqlite::find(unsigned int id) result.pageid = id; try { - auto ps = *db << "SELECT name, title, lastrevision, visible, (SELECT name FROM page WHERE id = parent) FROM " - "page WHERE id = ?"; + auto ps = + *db + << "SELECT name, title, lastrevision, listed, feedlisted, (SELECT name FROM page WHERE id = parent) FROM " + "page WHERE id = ?"; - ps << id >> std::tie(result.name, result.title, result.current_revision, result.listed, result.parentpage); + ps << id >> std::tie(result.name, result.title, result.current_revision, result.listed, result.feedlisted, + result.parentpage); } catch(const sqlite::errors::no_rows &e) { @@ -121,12 +126,10 @@ void PageDaoSqlite::save(const Page &page) { try { - *db << "INSERT OR REPLACE INTO page (id, name, title, lastrevision, visible, parent) VALUES((SELECT id FROM " - "page WHERE " - "name = " - "? OR id = ?), ?, ?, ?, ?, (SELECT id FROM page WHERE name = ?))" + *db << "INSERT OR REPLACE INTO page (id, name, title, lastrevision, listed, feedlisted, parent) VALUES((SELECT " + "id FROM page WHERE name = ? OR id = ?), ?, ?, ?, ?, ?, (SELECT id FROM page WHERE name = ?))" << page.name << page.pageid << page.name << page.title << page.current_revision << page.listed - << page.parentpage; + << page.feedlisted << page.parentpage; } catch(sqlite::sqlite_exception &e) { @@ -142,21 +145,22 @@ std::vector PageDaoSqlite::getPageList(QueryOption option) { std::string queryOption = SqliteQueryOption(option) .setOrderByColumn("lower(name)") - .setVisibleColumnName("visible") + .setListedColumnName("listed") .setPrependWhere(true) .build(); - std::string query = - "SELECT id, name, title, lastrevision, visible, (SELECT name FROM page WHERE id = parent) FROM page " + - queryOption; + std::string query = "SELECT id, name, title, lastrevision, listed, feedlisted, (SELECT name FROM page WHERE " + "id = parent) FROM page " + + queryOption; *db << query >> [&](unsigned int pageid, std::string name, std::string title, unsigned int current_revision, - bool visible, std::string parent) + bool listed, bool feedlisted, std::string parent) { Page tmp; tmp.pageid = pageid; tmp.name = name; tmp.title = title; tmp.current_revision = current_revision; - tmp.listed = visible; + tmp.listed = listed; + tmp.feedlisted = feedlisted; tmp.parentpage = parent; result.push_back(tmp); }; diff --git a/database/queryoption.h b/database/queryoption.h index 12160ba..d1c0f07 100644 --- a/database/queryoption.h +++ b/database/queryoption.h @@ -13,7 +13,7 @@ class QueryOption unsigned int offset = 0; unsigned int limit = 0; SORT_ORDER order = ASCENDING; - bool includeInvisible = true; + bool includeUnlisted = true; }; #endif // QUERYOPTION_H diff --git a/database/revisiondaosqlite.cpp b/database/revisiondaosqlite.cpp index 7c9e0f1..3526b01 100644 --- a/database/revisiondaosqlite.cpp +++ b/database/revisiondaosqlite.cpp @@ -52,7 +52,7 @@ std::vector RevisionDaoSqlite::getAllRevisions(QueryOption &options) { SqliteQueryOption queryOption{options}; std::string queryOptionSql = queryOption.setPrependWhere(true) - .setVisibleColumnName("page.visible") + .setListedColumnName("page.listed") .setOrderByColumn("creationtime") .build(); auto query = @@ -61,7 +61,8 @@ std::vector RevisionDaoSqlite::getAllRevisions(QueryOption &options) "page.name, revisionid FROM revision INNER JOIN page ON revision.page = page.id " + queryOptionSql; query >> [&](std::string author, std::string comment, std::string content, time_t creationtime, - std::string page, unsigned int revisionid) { + std::string page, unsigned int revisionid) + { Revision r; r.author = author; r.comment = comment; @@ -91,7 +92,7 @@ std::vector RevisionDaoSqlite::getAllRevisionsForPage(std::string page { SqliteQueryOption queryOption{option}; std::string queryOptionSql = queryOption.setPrependWhere(false) - .setVisibleColumnName("page.visible") + .setListedColumnName("page.listed") .setOrderByColumn("creationtime") .build(); auto query = *db << "SELECT (SELECT username FROM user WHERE id = author), comment, content, " @@ -101,7 +102,8 @@ std::vector RevisionDaoSqlite::getAllRevisionsForPage(std::string page << pagename; query >> [&](std::string author, std::string comment, std::string content, time_t creationtime, - std::string page, unsigned int revisionid) { + std::string page, unsigned int revisionid) + { Revision r; r.author = author; r.comment = comment; @@ -129,7 +131,8 @@ std::optional RevisionDaoSqlite::getCurrentForPage(std::string pagenam try { auto query = *db << "SELECT (SELECT username FROM user WHERE id = author), comment, content, " - "strftime('%s',creationtime), page.name, revisionid FROM revision INNER JOIN page ON revision.page = page.id WHERE page.name = ? AND page.lastrevision = revision.revisionid"; + "strftime('%s',creationtime), page.name, revisionid FROM revision INNER JOIN page ON " + "revision.page = page.id WHERE page.name = ? AND page.lastrevision = revision.revisionid"; query << pagename; query >> std::tie(result.author, result.comment, result.content, result.timestamp, result.page, result.revision); @@ -154,7 +157,8 @@ std::optional RevisionDaoSqlite::getRevisionForPage(std::string pagena auto query = *db << "SELECT (SELECT username FROM user WHERE id = author), comment, content, strftime('%s',creationtime), " - "page.name, revisionid FROM revision INNER JOIN page ON revision.page = page.id WHERE page.name = ? AND revisionid = ? "; + "page.name, revisionid FROM revision INNER JOIN page ON revision.page = page.id WHERE page.name = ? AND " + "revisionid = ? "; query << pagename << revision; query >> std::tie(result.author, result.comment, result.content, result.timestamp, result.page, result.revision); diff --git a/database/sqlitequeryoption.cpp b/database/sqlitequeryoption.cpp index ea9742c..5a9b418 100644 --- a/database/sqlitequeryoption.cpp +++ b/database/sqlitequeryoption.cpp @@ -31,9 +31,9 @@ SqliteQueryOption &SqliteQueryOption::setOrderByColumn(std::string name) return *this; } -SqliteQueryOption &SqliteQueryOption::setVisibleColumnName(std::string name) +SqliteQueryOption &SqliteQueryOption::setListedColumnName(std::string name) { - this->visibleColumnName = name; + this->listedColumnName = name; return *this; } @@ -50,9 +50,9 @@ std::string SqliteQueryOption::build() { result += "WHERE "; } - if(!o.includeInvisible && !this->visibleColumnName.empty()) + if(!o.includeUnlisted && !this->listedColumnName.empty()) { - result += this->visibleColumnName + " = 1"; + result += this->listedColumnName + " = 1"; } else { diff --git a/database/sqlitequeryoption.h b/database/sqlitequeryoption.h index 13d4184..59a16f6 100644 --- a/database/sqlitequeryoption.h +++ b/database/sqlitequeryoption.h @@ -7,7 +7,7 @@ class SqliteQueryOption { private: QueryOption o; - std::string visibleColumnName; + std::string listedColumnName; std::string orderByColumnName; bool prependWhere; @@ -17,7 +17,7 @@ class SqliteQueryOption SqliteQueryOption &setOrderByColumn(std::string name); - SqliteQueryOption &setVisibleColumnName(std::string name); + SqliteQueryOption &setListedColumnName(std::string name); SqliteQueryOption &setPrependWhere(bool b); diff --git a/dynamic/dynamiccontentpostlist.cpp b/dynamic/dynamiccontentpostlist.cpp index 2af0bc8..1b26fee 100644 --- a/dynamic/dynamiccontentpostlist.cpp +++ b/dynamic/dynamiccontentpostlist.cpp @@ -9,7 +9,7 @@ std::string DynamicContentPostList::render() auto permissionDao = this->database->createPermissionsDao(); QueryOption option; - option.includeInvisible = false; + option.includeUnlisted = false; auto members = categoryDao->fetchMembers(this->argument, option); std::vector> pageList; for(const Page &member : members) diff --git a/handlers/handler.cpp b/handlers/handler.cpp index 4113950..051d3e4 100644 --- a/handlers/handler.cpp +++ b/handlers/handler.cpp @@ -53,7 +53,7 @@ std::string Handler::createPageTitle(std::string title) QueryOption Handler::queryOption(const Request &r, SORT_ORDER defaultSort) const { QueryOption result; - result.includeInvisible = false; + result.includeUnlisted = false; try { result.limit = utils::toUInt(r.get("limit")); diff --git a/handlers/handlerfeedgenerator.cpp b/handlers/handlerfeedgenerator.cpp index 874fee8..dd8f858 100644 --- a/handlers/handlerfeedgenerator.cpp +++ b/handlers/handlerfeedgenerator.cpp @@ -9,7 +9,7 @@ std::vector HandlerFeedGenerator::fetch std::vector result; QueryOption option; - option.includeInvisible = false; + option.includeUnlisted = true; // option.limit = 20; auto comppage = [](const Page &a, const Page &b) { return a.name < b.name; }; @@ -34,12 +34,15 @@ std::vector HandlerFeedGenerator::fetch } for(const Page &member : members) { - Permissions perms = permissionDao->find(member.name, this->userSession->user.login) - .value_or(this->userSession->user.permissions); - if(perms.canRead()) + if(member.feedlisted) { - auto revision = revisionDao->getRevisionForPage(member.name, 1).value(); - result.push_back({member, revision}); + Permissions perms = permissionDao->find(member.name, this->userSession->user.login) + .value_or(this->userSession->user.permissions); + if(perms.canRead()) + { + auto revision = revisionDao->getRevisionForPage(member.name, 1).value(); + result.push_back({member, revision}); + } } } std::sort(result.begin(), result.end(), diff --git a/handlers/handlerpageedit.cpp b/handlers/handlerpageedit.cpp index b0e3a5c..dcc4774 100644 --- a/handlers/handlerpageedit.cpp +++ b/handlers/handlerpageedit.cpp @@ -76,7 +76,16 @@ Response HandlerPageEdit::handleRequest(PageDao &pageDao, std::string pagename, try { this->database->beginTransaction(); + std::string visiblecmd = parser.extractCommand("visible", newContent); + std::string listedcmd = parser.extractCommand("listed", newContent); + /* Backwarts compatibility */ + if(listedcmd.empty()) + { + listedcmd = visiblecmd; + } + std::string feedlistedcmd = parser.extractCommand("feedlisted", newContent); + std::string rename = parser.extractCommand("rename", newContent); std::string customtitle = parser.extractCommand("pagetitle", newContent); std::string parentpage = parser.extractCommand("parentpage", newContent); @@ -139,7 +148,8 @@ Response HandlerPageEdit::handleRequest(PageDao &pageDao, std::string pagename, } page.current_revision = current_revision; - page.listed = !(visiblecmd == "0"); + page.listed = !(listedcmd == "0"); + page.feedlisted = !(feedlistedcmd == "0"); page.name = pagename; page.title = customtitle; page.parentpage = parentpage; diff --git a/page.h b/page.h index 78bda17..d637ec0 100644 --- a/page.h +++ b/page.h @@ -10,6 +10,7 @@ class Page std::string title; std::string parentpage; bool listed; + bool feedlisted; unsigned int current_revision; unsigned int pageid; };