2021-10-31 21:45:12 +01:00
|
|
|
#include "rbac_rank.h"
|
|
|
|
|
2021-11-10 19:35:02 +01:00
|
|
|
#include "core/http/request.h"
|
|
|
|
|
|
|
|
bool RBACRank::has_permission(Request *request, const int permission) {
|
|
|
|
//todo try to find a match from the permissions array
|
|
|
|
|
|
|
|
return (base_permissions & permission) != 0;
|
|
|
|
}
|
|
|
|
|
2021-11-10 20:08:42 +01:00
|
|
|
bool RBACRank::has_rank_permission(const int permission) {
|
|
|
|
return (rank_permissions & permission) != 0;
|
|
|
|
}
|
|
|
|
|
2021-11-02 12:26:26 +01:00
|
|
|
void RBACRank::sort_permissions() {
|
|
|
|
for (int i = 0; i < permissions.size(); ++i) {
|
|
|
|
for (int j = i + 1; j < permissions.size(); ++j) {
|
|
|
|
if (permissions[j]->is_smaller(permissions[i])) {
|
|
|
|
permissions.swap(i, j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-31 21:45:12 +01:00
|
|
|
RBACRank::RBACRank() :
|
|
|
|
Resource() {
|
|
|
|
|
|
|
|
id = 0;
|
2021-11-09 19:58:56 +01:00
|
|
|
base_permissions = 0;
|
2021-11-01 15:12:09 +01:00
|
|
|
rank_permissions = 0;
|
2021-10-31 21:45:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
RBACRank::~RBACRank() {
|
2021-11-01 15:12:09 +01:00
|
|
|
permissions.clear();
|
2021-10-31 21:45:12 +01:00
|
|
|
}
|