mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
Initial rbac model setup.
This commit is contained in:
parent
32d370bfa3
commit
8e624d8b5a
@ -22,6 +22,10 @@ void RBACController::admin_add_section_links(Vector<AdminSectionLinkInfo> *links
|
||||
links->push_back(AdminSectionLinkInfo("Test", "test"));
|
||||
}
|
||||
|
||||
void RBACController::initialize() {
|
||||
_permissions = RBACModel::get_singleton()->load_permissions();
|
||||
}
|
||||
|
||||
RBACController *RBACController::get_singleton() {
|
||||
return _self;
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
#ifndef RBAC_CONTROLLER_H
|
||||
#define RBAC_CONTROLLER_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "modules/admin_panel/admin_controller.h"
|
||||
|
||||
#include <string>
|
||||
#include "core/containers/vector.h"
|
||||
#include "core/string.h"
|
||||
|
||||
#include "rbac_permission.h"
|
||||
#include "rbac_rank.h"
|
||||
|
||||
class Request;
|
||||
class FormValidator;
|
||||
@ -18,6 +24,8 @@ public:
|
||||
void admin_handle_request_main(Request *request);
|
||||
void admin_add_section_links(Vector<AdminSectionLinkInfo> *links);
|
||||
|
||||
void initialize();
|
||||
|
||||
static RBACController *get_singleton();
|
||||
|
||||
RBACController();
|
||||
@ -25,6 +33,8 @@ public:
|
||||
|
||||
protected:
|
||||
static RBACController *_self;
|
||||
|
||||
std::map<int, Ref<RBACRank> > _permissions;
|
||||
};
|
||||
|
||||
#endif
|
@ -9,6 +9,82 @@
|
||||
#define RBAC_RANK_TABLE "rbac_ranks"
|
||||
#define RBAC_PERMISSION_TABLE "rbac_permissions"
|
||||
|
||||
std::map<int, Ref<RBACRank> > RBACModel::load_permissions() {
|
||||
std::map<int, Ref<RBACRank> > ranks;
|
||||
|
||||
Ref<QueryBuilder> qb = DatabaseManager::get_singleton()->ddb->get_query_builder();
|
||||
|
||||
qb->select("id,name,name_internal,settings,rank_permissions")->from(RBAC_RANK_TABLE);
|
||||
Ref<QueryResult> res = qb->run();
|
||||
|
||||
while (res->next_row()) {
|
||||
Ref<RBACRank> r;
|
||||
r.instance();
|
||||
|
||||
r->id = res->get_cell_int(0);
|
||||
r->name = res->get_cell_str(1);
|
||||
r->name_internal = res->get_cell_str(2);
|
||||
r->settings = res->get_cell_str(3);
|
||||
r->rank_permissions = res->get_cell_int(4);
|
||||
|
||||
ranks[r->id] = r;
|
||||
}
|
||||
|
||||
/*
|
||||
qb->reset();
|
||||
qb->select("id,name,name_internal,settings,rank_permissions")->from(RBAC_PERMISSION_TABLE);
|
||||
res = qb->run();
|
||||
*/
|
||||
|
||||
return ranks;
|
||||
}
|
||||
|
||||
void RBACModel::save(const Ref<RBACRank> &rank) {
|
||||
save_rank(rank);
|
||||
|
||||
for (int i = 0; i < rank->permissions.size(); ++i) {
|
||||
Ref<RBACPermission> permission = rank->permissions[i];
|
||||
|
||||
if (permission->rank_id == 0) {
|
||||
permission->rank_id = rank->id;
|
||||
}
|
||||
|
||||
save_permission(permission);
|
||||
}
|
||||
}
|
||||
|
||||
void RBACModel::save_rank(const Ref<RBACRank> &rank) {
|
||||
Ref<QueryBuilder> qb = DatabaseManager::get_singleton()->ddb->get_query_builder();
|
||||
|
||||
if (rank->id == 0) {
|
||||
qb->insert(RBAC_RANK_TABLE, "name,name_internal,settings,rank_permissions")->values();
|
||||
qb->eval(rank->name)->eval(rank->name_internal)->eval(rank->settings)->val(rank->rank_permissions);
|
||||
qb->cvalues();
|
||||
qb->select_last_insert_id();
|
||||
Ref<QueryResult> res = qb->run();
|
||||
qb->print();
|
||||
|
||||
Ref<RBACRank> r = rank;
|
||||
|
||||
r->id = res->get_last_insert_rowid();
|
||||
} else {
|
||||
qb->udpate(RBAC_RANK_TABLE)->set();
|
||||
qb->esetp("name", rank->name);
|
||||
qb->esetp("name_internal", rank->name_internal);
|
||||
qb->esetp("settings", rank->settings);
|
||||
qb->setp("rank_permissions", rank->rank_permissions);
|
||||
qb->cset();
|
||||
qb->where()->wp("id", rank->id);
|
||||
qb->end_command();
|
||||
qb->run_query();
|
||||
qb->print();
|
||||
}
|
||||
}
|
||||
|
||||
void RBACModel::save_permission(const Ref<RBACPermission> &permission) {
|
||||
|
||||
}
|
||||
|
||||
void RBACModel::create_table() {
|
||||
Ref<TableBuilder> tb = DatabaseManager::get_singleton()->ddb->get_table_builder();
|
||||
|
||||
|
@ -3,13 +3,22 @@
|
||||
|
||||
#include "core/http/model.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "core/containers/vector.h"
|
||||
#include "core/string.h"
|
||||
|
||||
#include "rbac_permission.h"
|
||||
#include "rbac_rank.h"
|
||||
|
||||
class RBACModel : public Model {
|
||||
RCPP_OBJECT(RBACModel, Model);
|
||||
|
||||
public:
|
||||
virtual std::map<int, Ref<RBACRank> > load_permissions();
|
||||
|
||||
virtual void save(const Ref<RBACRank> &rank);
|
||||
virtual void save_rank(const Ref<RBACRank> &rank);
|
||||
virtual void save_permission(const Ref<RBACPermission> &permission);
|
||||
|
||||
void create_table();
|
||||
void drop_table();
|
||||
@ -22,8 +31,6 @@ public:
|
||||
|
||||
protected:
|
||||
static RBACModel *_self;
|
||||
|
||||
std::string _table_name;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user