2021-10-31 21:45:12 +01:00
|
|
|
#ifndef RBAC_CONTROLLER_H
|
|
|
|
#define RBAC_CONTROLLER_H
|
|
|
|
|
2021-11-01 16:39:30 +01:00
|
|
|
#include <map>
|
|
|
|
|
2021-10-31 23:12:05 +01:00
|
|
|
#include "modules/admin_panel/admin_controller.h"
|
2021-10-31 21:45:12 +01:00
|
|
|
|
2021-11-01 16:39:30 +01:00
|
|
|
#include "core/containers/vector.h"
|
|
|
|
#include "core/string.h"
|
|
|
|
|
|
|
|
#include "rbac_permission.h"
|
|
|
|
#include "rbac_rank.h"
|
2021-10-31 21:45:12 +01:00
|
|
|
|
|
|
|
class Request;
|
|
|
|
class FormValidator;
|
|
|
|
|
2021-10-31 23:12:05 +01:00
|
|
|
class RBACController : public AdminController {
|
|
|
|
RCPP_OBJECT(RBACController, AdminController);
|
2021-11-01 23:48:25 +01:00
|
|
|
|
2021-10-31 21:45:12 +01:00
|
|
|
public:
|
|
|
|
void handle_request_main(Request *request);
|
|
|
|
void create_validators();
|
|
|
|
|
2021-11-01 15:12:09 +01:00
|
|
|
void admin_handle_request_main(Request *request);
|
2021-11-01 21:21:03 +01:00
|
|
|
String admin_get_section_name();
|
2021-11-01 01:39:55 +01:00
|
|
|
void admin_add_section_links(Vector<AdminSectionLinkInfo> *links);
|
|
|
|
|
2021-11-01 23:48:25 +01:00
|
|
|
struct RBACAdminRankViewData {
|
|
|
|
Ref<RBACRank> rank;
|
|
|
|
Vector<String> messages;
|
|
|
|
|
|
|
|
int id = 0;
|
|
|
|
String name = "";
|
|
|
|
String name_internal = "";
|
|
|
|
String settings = "";
|
|
|
|
int rank_permissions = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void admin_handle_new_rank(Request *request);
|
|
|
|
void admin_handle_edit_rank(Request *request);
|
|
|
|
void render_rank_view(Request *request, RBACAdminRankViewData *data);
|
|
|
|
|
2021-11-02 00:18:57 +01:00
|
|
|
struct RBACAdminEditPermissionView {
|
|
|
|
Ref<RBACRank> rank;
|
|
|
|
Ref<RBACPermission> permission;
|
|
|
|
Vector<String> messages;
|
|
|
|
|
|
|
|
int rank_id = 0;
|
|
|
|
int permission_id = 0;
|
|
|
|
};
|
|
|
|
|
2021-11-02 12:27:36 +01:00
|
|
|
void admin_permission_editor(Request *request);
|
|
|
|
void admin_render_permission_editor_main_view(Request *request, RBACAdminEditPermissionView* data);
|
|
|
|
void admin_render_permission_editor_entry_edit_create_view(Request *request, RBACAdminEditPermissionView* data);
|
|
|
|
bool admin_process_permission_editor_entry_edit_create_post(Request *request, RBACAdminEditPermissionView* data);
|
2021-11-02 00:18:57 +01:00
|
|
|
|
2021-11-01 21:21:03 +01:00
|
|
|
void admin_render_rank_list(Request *request);
|
|
|
|
void admin_render_rank_editor(Request *request);
|
|
|
|
|
2021-11-09 22:55:53 +01:00
|
|
|
void register_permission(const String& name, const int val);
|
|
|
|
void register_rank_permission(const String& name, const int val);
|
|
|
|
void clear_registered_permissions();
|
|
|
|
|
2021-11-01 16:39:30 +01:00
|
|
|
void initialize();
|
2021-11-09 22:55:53 +01:00
|
|
|
virtual void register_permissions();
|
2021-11-01 16:39:30 +01:00
|
|
|
|
2021-11-10 19:35:02 +01:00
|
|
|
Ref<RBACRank> get_rank(int rank_id);
|
2021-11-14 01:34:01 +01:00
|
|
|
|
|
|
|
int get_default_user_rank_id();
|
|
|
|
Ref<RBACRank> get_default_user_rank();
|
|
|
|
|
2021-11-10 19:35:02 +01:00
|
|
|
int get_default_rank_id();
|
|
|
|
Ref<RBACRank> get_default_rank();
|
|
|
|
|
2021-11-10 20:08:42 +01:00
|
|
|
String &get_redirect_url();
|
|
|
|
|
2021-11-10 19:35:02 +01:00
|
|
|
bool continue_on_missing_default_rank();
|
|
|
|
|
2021-10-31 21:45:12 +01:00
|
|
|
static RBACController *get_singleton();
|
|
|
|
|
|
|
|
RBACController();
|
|
|
|
~RBACController();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static RBACController *_self;
|
2021-11-01 16:39:30 +01:00
|
|
|
|
2021-11-10 19:53:56 +01:00
|
|
|
int _default_rank_id;
|
2021-11-14 01:34:01 +01:00
|
|
|
int _default_user_rank_id;
|
2021-11-09 22:55:53 +01:00
|
|
|
std::map<int, Ref<RBACRank> > _ranks;
|
2021-11-10 20:08:42 +01:00
|
|
|
String _redirect_url;
|
2021-11-09 22:55:53 +01:00
|
|
|
|
|
|
|
struct PermissionEntry {
|
|
|
|
String name;
|
|
|
|
int value;
|
|
|
|
|
|
|
|
PermissionEntry() {
|
|
|
|
}
|
|
|
|
|
|
|
|
PermissionEntry(const String& p_name, const int p_val) {
|
|
|
|
name = p_name;
|
|
|
|
value = p_val;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<PermissionEntry> _registered_permissions;
|
|
|
|
Vector<PermissionEntry> _registered_rank_permissions;
|
2021-10-31 21:45:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|