tree: visible => listed
This commit is contained in:
rodzic
18f4ad9d51
commit
03c6816528
@ -102,23 +102,27 @@ std::vector<Page> 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);
|
||||
};
|
||||
}
|
||||
|
@ -57,10 +57,12 @@ std::optional<Page> 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<Page> 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<Page> 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);
|
||||
};
|
||||
|
@ -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
|
||||
|
@ -52,7 +52,7 @@ std::vector<Revision> 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<Revision> 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<Revision> 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<Revision> 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<Revision> 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<Revision> 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);
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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<std::pair<std::string, time_t>> pageList;
|
||||
for(const Page &member : members)
|
||||
|
@ -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"));
|
||||
|
@ -9,7 +9,7 @@ std::vector<HandlerFeedGenerator::EntryRevisionPair> HandlerFeedGenerator::fetch
|
||||
|
||||
std::vector<EntryRevisionPair> 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::EntryRevisionPair> 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(),
|
||||
|
@ -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;
|
||||
|
1
page.h
1
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;
|
||||
};
|
||||
|
Ładowanie…
Reference in New Issue
Block a user