CLI: Begin 'page' and 'pageperms' commands

Этот коммит содержится в:
Albert S. 2021-10-05 21:57:20 +02:00
родитель f002969cc1
Коммит b59e81a41d
2 изменённых файлов: 41 добавлений и 0 удалений

25
cli.cpp
Просмотреть файл

@ -138,6 +138,31 @@ 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
Просмотреть файл

@ -30,6 +30,8 @@ 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{
@ -43,6 +45,20 @@ 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,