qswiki/permissions.h

78 γραμμές
2.3 KiB
C++

#ifndef PERMISSIONS_H
#define PERMISSIONS_H
#define PERM_CAN_READ 1 << 0
#define PERM_CAN_EDIT 1 << 1
#define PERM_CAN_PAGE_HISTORY 1 << 2
#define PERM_CAN_GLOBAL_HISTORY 1 << 3
#define PERM_CAN_DELETE 1 << 4
#define PERM_CAN_SEE_PAGE_LIST 1 << 5
#define PERM_CAN_CREATE 1 << 6
#define PERM_CAN_SEE_CATEGORY_LIST 1 << 7
#define PERM_CAN_SEE_LINKS_HERE 1 << 8
#define PERM_CAN_SEARCH 1 << 9
#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() { this->permissions = 0; }
Permissions(int permissions);
Permissions(const std::string &str);
Permissions (Permissions &&o)
{
this->permissions = o.permissions;
}
Permissions (const Permissions &o)
{
this->permissions = o.permissions;
}
Permissions &operator=(const Permissions &o)
{
this->permissions = o.permissions;
return *this;
}
Permissions &operator=(Permissions &&o)
{
this->permissions = o.permissions;
return *this;
}
int getPermissions() const { return this->permissions; }
bool canRead() const { return this->permissions & PERM_CAN_READ; }
bool canEdit() const { return this->permissions & PERM_CAN_EDIT; }
bool canSeePageHistory() const { return this->permissions & PERM_CAN_PAGE_HISTORY; }
bool canSeeGlobalHistory() const { return this->permissions & PERM_CAN_GLOBAL_HISTORY; }
bool canCreate() const { return this->permissions & PERM_CAN_CREATE; }
bool canSeeCategoryList() const { return this->permissions & PERM_CAN_SEE_CATEGORY_LIST; }
bool canSeeLinksHere() const { return this->permissions & PERM_CAN_SEE_LINKS_HERE; }
bool canSearch() const { return this->permissions & PERM_CAN_SEARCH; }
bool canDelete() const { return this->permissions & PERM_CAN_DELETE; }
bool canSeePageList() const { return this->permissions & PERM_CAN_SEE_PAGE_LIST; }
};
#endif // PERMISSIONS_H