From 047c2e0d371376b870ea8a067c3d9d9639a1d0d3 Mon Sep 17 00:00:00 2001 From: cuihaikuo Date: Mon, 11 Jun 2018 14:45:01 +0800 Subject: [PATCH] Add parameter 'in_structure' to control whether checking ancestor groups or not in check_group_staff() --- net/common/rpc-service.c | 7 ++++--- net/common/rpc-service.h | 2 +- net/server/group-mgr.c | 20 ++++++++++++++------ net/server/group-mgr.h | 3 ++- python/ccnet/rpc.py | 4 ++-- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/net/common/rpc-service.c b/net/common/rpc-service.c index 160d006..53290e3 100644 --- a/net/common/rpc-service.c +++ b/net/common/rpc-service.c @@ -271,7 +271,7 @@ ccnet_start_rpc(CcnetSession *session) searpc_server_register_function ("ccnet-threaded-rpcserver", ccnet_rpc_check_group_staff, "check_group_staff", - searpc_signature_int__int_string()); + searpc_signature_int__int_string_int()); searpc_server_register_function ("ccnet-threaded-rpcserver", ccnet_rpc_remove_group_user, "remove_group_user", @@ -1251,7 +1251,7 @@ ccnet_rpc_get_members_with_prefix(int group_id, const char *prefix, GError **err } int -ccnet_rpc_check_group_staff (int group_id, const char *user_name, +ccnet_rpc_check_group_staff (int group_id, const char *user_name, int in_structure, GError **error) { CcnetGroupManager *group_mgr = @@ -1264,7 +1264,8 @@ ccnet_rpc_check_group_staff (int group_id, const char *user_name, } return ccnet_group_manager_check_group_staff (group_mgr, - group_id, user_name); + group_id, user_name, + in_structure ? TRUE : FALSE); } int diff --git a/net/common/rpc-service.h b/net/common/rpc-service.h index d50027a..6608df9 100644 --- a/net/common/rpc-service.h +++ b/net/common/rpc-service.h @@ -240,7 +240,7 @@ GList * ccnet_rpc_get_members_with_prefix(int group_id, const char *prefix, GError **error); int -ccnet_rpc_check_group_staff (int group_id, const char *user_name, +ccnet_rpc_check_group_staff (int group_id, const char *user_name, int in_structure, GError **error); int diff --git a/net/server/group-mgr.c b/net/server/group-mgr.c index 5faa003..a314294 100644 --- a/net/server/group-mgr.c +++ b/net/server/group-mgr.c @@ -402,8 +402,15 @@ int ccnet_group_manager_create_org_group (CcnetGroupManager *mgr, } static gboolean -check_group_staff (CcnetDB *db, int group_id, const char *user_name) +check_group_staff (CcnetDB *db, int group_id, const char *user_name, gboolean in_structure) { + if (!in_structure) { + return ccnet_db_statement_exists (db, "SELECT group_id FROM GroupUser WHERE " + "group_id = ? AND user_name = ? AND " + "is_staff = 1", + 2, "int", group_id, "string", user_name); + } + gboolean exists; GString *sql = g_string_new(""); g_string_printf (sql, "SELECT path FROM GroupStructure WHERE group_id=?"); @@ -499,7 +506,7 @@ int ccnet_group_manager_add_member (CcnetGroupManager *mgr, CcnetDB *db = mgr->priv->db; /* check whether user is the staff of the group */ - if (!check_group_staff (db, group_id, user_name)) { + if (!check_group_staff (db, group_id, user_name, TRUE)) { g_set_error (error, CCNET_DOMAIN, 0, "Permission error: only group staff can add member"); return -1; @@ -543,7 +550,7 @@ int ccnet_group_manager_remove_member (CcnetGroupManager *mgr, char *sql; /* check whether user is the staff of the group */ - if (!check_group_staff (db, group_id, user_name)) { + if (!check_group_staff (db, group_id, user_name, TRUE)) { g_set_error (error, CCNET_DOMAIN, 0, "Only group staff can remove member"); return -1; @@ -628,7 +635,7 @@ int ccnet_group_manager_quit_group (CcnetGroupManager *mgr, CcnetDB *db = mgr->priv->db; /* check where user is the staff of the group */ - if (check_group_staff (db, group_id, user_name)) { + if (check_group_staff (db, group_id, user_name, FALSE)) { g_set_error (error, CCNET_DOMAIN, 0, "Group staff can not quit group"); return -1; @@ -1044,9 +1051,10 @@ ccnet_group_manager_get_members_with_prefix (CcnetGroupManager *mgr, int ccnet_group_manager_check_group_staff (CcnetGroupManager *mgr, int group_id, - const char *user_name) + const char *user_name, + gboolean in_structure) { - return check_group_staff (mgr->priv->db, group_id, user_name); + return check_group_staff (mgr->priv->db, group_id, user_name, in_structure); } int diff --git a/net/server/group-mgr.h b/net/server/group-mgr.h index d6ad45e..c857ac1 100644 --- a/net/server/group-mgr.h +++ b/net/server/group-mgr.h @@ -97,7 +97,8 @@ ccnet_group_manager_get_members_with_prefix (CcnetGroupManager *mgr, int ccnet_group_manager_check_group_staff (CcnetGroupManager *mgr, int group_id, - const char *user_name); + const char *user_name, + int in_structure); int ccnet_group_manager_remove_group_user (CcnetGroupManager *mgr, diff --git a/python/ccnet/rpc.py b/python/ccnet/rpc.py index 778507f..fedf29e 100644 --- a/python/ccnet/rpc.py +++ b/python/ccnet/rpc.py @@ -331,8 +331,8 @@ class CcnetThreadedRpcClient(RpcClientBase): def get_members_with_prefix(self, group_id, prefix): pass - @searpc_func("int", ["int", "string"]) - def check_group_staff(self, group_id, username): + @searpc_func("int", ["int", "string", "int"]) + def check_group_staff(self, group_id, username, in_structure): pass @searpc_func("int", ["string"])