qswiki/permissions.h

131 рядки
2.4 KiB
C

2018-11-03 17:12:20 +01:00
#ifndef PERMISSIONS_H
#define PERMISSIONS_H
2023-07-28 15:04:58 +02:00
#define PERM_CAN_NOTHING 0
2018-11-03 17:12:20 +01:00
#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
2023-07-28 15:04:58 +02:00
#define PERM_CAN_SET_PAGE_PERMS 1 << 10
#define PERM_IS_ADMIN (1L<<31)-1
2018-11-03 17:12:20 +01:00
#include <string>
#include <map>
2018-11-03 17:12:20 +01:00
class Permissions
2018-11-03 17:12:20 +01:00
{
private:
int permissions = 0;
2018-11-03 17:12:20 +01:00
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;
}
2023-07-28 15:04:58 +02:00
bool canNothing() const
{
return this->permissions == PERM_CAN_NOTHING;
}
2018-11-03 17:12:20 +01:00
bool canRead() const
{
return this->permissions & PERM_CAN_READ;
}
2023-07-28 15:04:58 +02:00
2018-11-03 17:12:20 +01:00
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;
}
2023-07-28 15:04:58 +02:00
bool canSetPagePerms() const
{
return this->permissions & PERM_CAN_SET_PAGE_PERMS;
}
bool isAdmin() const
{
return this->permissions == PERM_IS_ADMIN;
}
std::string toString() const
{
return Permissions::toString(this->permissions);
}
static std::string toString(int perms);
2023-07-28 15:04:58 +02:00
bool operator==(const Permissions &o) const
{
return this->permissions == o.permissions;
}
2018-11-03 17:12:20 +01:00
};
#endif // PERMISSIONS_H