Vertaa committeja
No commits in common. "b59e81a41dc9a2f80afbc6b096f6757b74b7fe49" and "c4072a7e952dd66dcd1fa14e4fdbfa0754986dee" have entirely different histories.
b59e81a41d
...
c4072a7e95
25
cli.cpp
25
cli.cpp
@ -138,31 +138,6 @@ std::pair<bool, std::string> CLIHandler::user_show(const std::vector<std::string
|
||||
return {false, "User not found"};
|
||||
}
|
||||
|
||||
std::pair<bool, std::string> CLIHandler::page_list(const std::vector<std::string> &args)
|
||||
{
|
||||
auto pageDao = this->db->createPageDao();
|
||||
QueryOption o;
|
||||
auto result = pageDao->getPageList(o);
|
||||
std::stringstream stream;
|
||||
for(std::string pagename : result)
|
||||
{
|
||||
Page p = pageDao->find(pagename).value();
|
||||
stream << p.name << " " << p.pageid << " " << std::string(p.listed ? "listed" : "unlisted") << std::endl;
|
||||
}
|
||||
return {true, stream.str()};
|
||||
}
|
||||
|
||||
std::pair<bool, std::string> CLIHandler::pageperms_set_permissions(const std::vector<std::string> &args)
|
||||
{
|
||||
std::string page = args.at(0);
|
||||
std::string username = args.at(1);
|
||||
std::string perms = args.at(2);
|
||||
|
||||
auto permissionsDao = this->db->createPermissionsDao();
|
||||
permissionsDao->save(page, username, Permissions{perms});
|
||||
return {true, ""};
|
||||
}
|
||||
|
||||
std::pair<bool, std::string> CLIHandler::attach(const std::vector<std::string> &args)
|
||||
{
|
||||
/* TODO: consider authentication */
|
||||
|
16
cli.h
16
cli.h
@ -30,8 +30,6 @@ class CLIHandler
|
||||
std::pair<bool, std::string> user_set_perms(const std::vector<std::string> &args);
|
||||
std::pair<bool, std::string> user_list(const std::vector<std::string> &args);
|
||||
std::pair<bool, std::string> user_show(const std::vector<std::string> &args);
|
||||
std::pair<bool, std::string> page_list(const std::vector<std::string> &args);
|
||||
std::pair<bool, std::string> pageperms_set_permissions(const std::vector<std::string> &args);
|
||||
std::pair<bool, std::string> version(const std::vector<std::string> &args);
|
||||
|
||||
std::vector<struct cmd> cmds{
|
||||
@ -45,20 +43,6 @@ class CLIHandler
|
||||
{"list", "- lists users", 0, {}, &CLIHandler::user_list},
|
||||
{"show", "[user] - show detailed information about user", 1, {}, &CLIHandler::user_show}}},
|
||||
&CLIHandler::cli_help},
|
||||
{"page",
|
||||
"operation on pages",
|
||||
1,
|
||||
{{{"list", "- lists existing pages", 0, {}, &CLIHandler::page_list}}},
|
||||
&CLIHandler::cli_help},
|
||||
{"pageperms",
|
||||
"set permissions on pages",
|
||||
1,
|
||||
{{{"set",
|
||||
"- [page] [username] [permissions] set permisisons on page",
|
||||
3,
|
||||
{},
|
||||
&CLIHandler::pageperms_set_permissions}}},
|
||||
&CLIHandler::cli_help},
|
||||
{"exit",
|
||||
"exit cli",
|
||||
0,
|
||||
|
@ -7,7 +7,6 @@ class PermissionsDao
|
||||
public:
|
||||
PermissionsDao();
|
||||
virtual std::optional<Permissions> find(std::string pagename, std::string username) = 0;
|
||||
virtual void save(std::string pagename, std::string username, Permissions perms) = 0;
|
||||
};
|
||||
|
||||
#endif // PERMISSIONSDAO_H
|
||||
|
@ -41,21 +41,3 @@ std::optional<Permissions> PermissionsDaoSqlite::find(std::string pagename, std:
|
||||
|
||||
return Permissions{permissions};
|
||||
}
|
||||
|
||||
void PermissionsDaoSqlite::save(std::string pagename, std::string username, Permissions perms)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto query =
|
||||
*db
|
||||
<< "INSERT OR REPLACE INTO permissions (id, permissions, userid, page) VALUES((SELECT id FROM permissions "
|
||||
"WHERE page = (SELECT id FROM page WHERE name = ?) AND userid = (SELECT id FROM user WHERE username = "
|
||||
"?)), ?, (SELECT id FROM user WHERE username = ?), (SELECT id FROM page WHERE name = ?))";
|
||||
query << pagename << username << perms.getPermissions() << username << pagename;
|
||||
query.execute();
|
||||
}
|
||||
catch(const sqlite::errors::no_rows &e)
|
||||
{
|
||||
throwFrom(e);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ class PermissionsDaoSqlite : public PermissionsDao, protected SqliteDao
|
||||
PermissionsDaoSqlite();
|
||||
|
||||
std::optional<Permissions> find(std::string pagename, std::string username) override;
|
||||
virtual void save(std::string pagename, std::string username, Permissions perms) override;
|
||||
using SqliteDao::SqliteDao;
|
||||
};
|
||||
|
||||
|
Ladataan…
Viittaa uudesa ongelmassa
Block a user