diff --git a/modules/rbac/rbac_controller.cpp b/modules/rbac/rbac_controller.cpp index a8fac91..52e9931 100644 --- a/modules/rbac/rbac_controller.cpp +++ b/modules/rbac/rbac_controller.cpp @@ -14,6 +14,10 @@ void RBACController::handle_request_main(Request *request) { void RBACController::create_validators() { } +void RBACController::admin_handle_request_main(Request *request) { + +} + void RBACController::admin_add_section_links(Vector *links) { links->push_back(AdminSectionLinkInfo("Test", "test")); } diff --git a/modules/rbac/rbac_controller.h b/modules/rbac/rbac_controller.h index d2387b5..b057de1 100644 --- a/modules/rbac/rbac_controller.h +++ b/modules/rbac/rbac_controller.h @@ -15,6 +15,7 @@ public: void handle_request_main(Request *request); void create_validators(); + void admin_handle_request_main(Request *request); void admin_add_section_links(Vector *links); static RBACController *get_singleton(); diff --git a/modules/rbac/rbac_model.cpp b/modules/rbac/rbac_model.cpp index da4f58c..dd1bf4b 100644 --- a/modules/rbac/rbac_model.cpp +++ b/modules/rbac/rbac_model.cpp @@ -6,29 +6,46 @@ #include "core/database/query_result.h" #include "core/database/table_builder.h" +#define RBAC_RANK_TABLE "rbac_ranks" +#define RBAC_PERMISSION_TABLE "rbac_permissions" + void RBACModel::create_table() { Ref tb = DatabaseManager::get_singleton()->ddb->get_table_builder(); - tb->create_table(_table_name); + tb->create_table(RBAC_RANK_TABLE); tb->integer("id")->auto_increment()->next_row(); - tb->varchar("username", 60)->not_null()->next_row(); - tb->varchar("email", 100)->not_null()->next_row(); - tb->integer("rank")->not_null()->next_row(); - tb->varchar("pre_salt", 100)->next_row(); - tb->varchar("post_salt", 100)->next_row(); - tb->varchar("password_hash", 100)->next_row(); - tb->integer("banned")->next_row(); - tb->varchar("password_reset_token", 100)->next_row(); - tb->integer("locked")->next_row(); + tb->varchar("name", 60)->not_null()->next_row(); + tb->varchar("name_internal", 100)->not_null()->next_row(); + tb->varchar("settings", 200)->not_null()->next_row(); + tb->integer("rank_permissions")->not_null()->next_row(); tb->primary_key("id"); tb->ccreate_table(); + //tb->run_query(); + //tb->print(); + + //tb->result = ""; + + tb->create_table(RBAC_PERMISSION_TABLE); + tb->integer("id")->auto_increment()->next_row(); + tb->integer("rank_id")->not_null()->next_row(); + tb->varchar("name", 60)->not_null()->next_row(); + tb->varchar("url", 100)->not_null()->next_row(); + + tb->integer("revoke")->not_null()->next_row(); + tb->integer("sort_order")->not_null()->next_row(); + tb->integer("permissions")->not_null()->next_row(); + + tb->primary_key("id"); + tb->foreign_key("rank_id")->references(RBAC_RANK_TABLE, "id"); + tb->ccreate_table(); tb->run_query(); //tb->print(); } void RBACModel::drop_table() { Ref tb = DatabaseManager::get_singleton()->ddb->get_table_builder(); - tb->drop_table_if_exists(_table_name)->run_query(); + tb->drop_table_if_exists(RBAC_PERMISSION_TABLE)->drop_table_if_exists(RBAC_RANK_TABLE)->run_query(); + //tb->print(); } void RBACModel::migrate() { drop_table(); diff --git a/modules/rbac/rbac_permission.cpp b/modules/rbac/rbac_permission.cpp index 7f335d3..7294041 100644 --- a/modules/rbac/rbac_permission.cpp +++ b/modules/rbac/rbac_permission.cpp @@ -5,7 +5,6 @@ RBACPermission::RBACPermission() : id = 0; rank_id = 0; - permission_id = 0; revoke = false; sort_order = 0; permissions = 0; diff --git a/modules/rbac/rbac_permission.h b/modules/rbac/rbac_permission.h index 39d222d..76378fa 100644 --- a/modules/rbac/rbac_permission.h +++ b/modules/rbac/rbac_permission.h @@ -11,7 +11,6 @@ class RBACPermission : public Resource { public: int id; int rank_id; - int permission_id; std::string name; std::string url; bool revoke; diff --git a/modules/rbac/rbac_rank.cpp b/modules/rbac/rbac_rank.cpp index 67ce5c9..bb60533 100644 --- a/modules/rbac/rbac_rank.cpp +++ b/modules/rbac/rbac_rank.cpp @@ -4,8 +4,9 @@ RBACRank::RBACRank() : Resource() { id = 0; + rank_permissions = 0; } RBACRank::~RBACRank() { - groups.clear(); + permissions.clear(); } diff --git a/modules/rbac/rbac_rank.h b/modules/rbac/rbac_rank.h index 75839c2..2123cf0 100644 --- a/modules/rbac/rbac_rank.h +++ b/modules/rbac/rbac_rank.h @@ -18,7 +18,9 @@ public: std::string name_internal; std::string settings; - std::vector > groups; + int rank_permissions; + + std::vector > permissions; RBACRank(); ~RBACRank();