CLI #25
@ -20,6 +20,17 @@ SOFTWARE.
|
||||
*/
|
||||
#include "permissions.h"
|
||||
|
||||
static const std::map<std::string, int> permmap = {{"can_read", PERM_CAN_READ},
|
||||
{"can_edit", PERM_CAN_EDIT},
|
||||
{"can_page_history", PERM_CAN_PAGE_HISTORY},
|
||||
{"can_global_history", PERM_CAN_GLOBAL_HISTORY},
|
||||
{"can_delete", PERM_CAN_DELETE},
|
||||
{"can_see_page_list", PERM_CAN_SEE_PAGE_LIST},
|
||||
{"can_create", PERM_CAN_CREATE},
|
||||
{"can_see_category_list", PERM_CAN_SEE_CATEGORY_LIST},
|
||||
{"can_see_links_here", PERM_CAN_SEE_LINKS_HERE},
|
||||
{"can_search", PERM_CAN_SEARCH}};
|
||||
|
||||
Permissions::Permissions(int permissions)
|
||||
{
|
||||
this->permissions = permissions;
|
||||
@ -36,3 +47,20 @@ Permissions::Permissions(const std::string &str)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string Permissions::toString(int perms)
|
||||
{
|
||||
std::string result;
|
||||
for(auto pair : permmap)
|
||||
{
|
||||
if(pair.second & perms)
|
||||
{
|
||||
result += pair.first + ",";
|
||||
}
|
||||
}
|
||||
if(result.size() > 0)
|
||||
{
|
||||
result.pop_back();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -14,20 +14,12 @@
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
class Permissions
|
||||
|
||||
{
|
||||
private:
|
||||
int permissions = 0;
|
||||
const std::map<std::string, int> permmap = {{"can_read", PERM_CAN_READ},
|
||||
{"can_edit", PERM_CAN_EDIT},
|
||||
{"can_page_history", PERM_CAN_PAGE_HISTORY},
|
||||
{"can_global_history", PERM_CAN_GLOBAL_HISTORY},
|
||||
{"can_delete", PERM_CAN_DELETE},
|
||||
{"can_see_page_list", PERM_CAN_SEE_PAGE_LIST},
|
||||
{"can_create", PERM_CAN_CREATE},
|
||||
{"can_see_category_list", PERM_CAN_SEE_CATEGORY_LIST},
|
||||
{"can_see_links_here", PERM_CAN_SEE_LINKS_HERE},
|
||||
{"can_search", PERM_CAN_SEARCH}};
|
||||
|
||||
public:
|
||||
Permissions()
|
||||
@ -102,6 +94,13 @@ class Permissions
|
||||
{
|
||||
return this->permissions & PERM_CAN_SEE_PAGE_LIST;
|
||||
}
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
return Permissions::toString(this->permissions);
|
||||
}
|
||||
|
||||
static std::string toString(int perms);
|
||||
};
|
||||
|
||||
#endif // PERMISSIONS_H
|
||||
|
Loading…
Reference in New Issue
Block a user