1
0
mirror of https://github.com/haiwen/ccnet-server.git synced 2025-08-19 21:07:06 +00:00

Merge pull request #26 from haiwen/is_group_staff

Add parameter 'in_structure' to control whether checking ancestor gro…
This commit is contained in:
Jiaqiang Xu 2018-06-21 11:12:48 +08:00 committed by GitHub
commit 020389e066
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 13 deletions

View File

@ -271,7 +271,7 @@ ccnet_start_rpc(CcnetSession *session)
searpc_server_register_function ("ccnet-threaded-rpcserver", searpc_server_register_function ("ccnet-threaded-rpcserver",
ccnet_rpc_check_group_staff, ccnet_rpc_check_group_staff,
"check_group_staff", "check_group_staff",
searpc_signature_int__int_string()); searpc_signature_int__int_string_int());
searpc_server_register_function ("ccnet-threaded-rpcserver", searpc_server_register_function ("ccnet-threaded-rpcserver",
ccnet_rpc_remove_group_user, ccnet_rpc_remove_group_user,
"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 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) GError **error)
{ {
CcnetGroupManager *group_mgr = 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, return ccnet_group_manager_check_group_staff (group_mgr,
group_id, user_name); group_id, user_name,
in_structure ? TRUE : FALSE);
} }
int int

View File

@ -240,7 +240,7 @@ GList *
ccnet_rpc_get_members_with_prefix(int group_id, const char *prefix, GError **error); ccnet_rpc_get_members_with_prefix(int group_id, const char *prefix, GError **error);
int 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); GError **error);
int int

View File

@ -402,8 +402,15 @@ int ccnet_group_manager_create_org_group (CcnetGroupManager *mgr,
} }
static gboolean 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; gboolean exists;
GString *sql = g_string_new(""); GString *sql = g_string_new("");
g_string_printf (sql, "SELECT path FROM GroupStructure WHERE group_id=?"); 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; CcnetDB *db = mgr->priv->db;
/* check whether user is the staff of the group */ /* 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, g_set_error (error, CCNET_DOMAIN, 0,
"Permission error: only group staff can add member"); "Permission error: only group staff can add member");
return -1; return -1;
@ -543,7 +550,7 @@ int ccnet_group_manager_remove_member (CcnetGroupManager *mgr,
char *sql; char *sql;
/* check whether user is the staff of the group */ /* 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, g_set_error (error, CCNET_DOMAIN, 0,
"Only group staff can remove member"); "Only group staff can remove member");
return -1; return -1;
@ -628,7 +635,7 @@ int ccnet_group_manager_quit_group (CcnetGroupManager *mgr,
CcnetDB *db = mgr->priv->db; CcnetDB *db = mgr->priv->db;
/* check where user is the staff of the group */ /* 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, g_set_error (error, CCNET_DOMAIN, 0,
"Group staff can not quit group"); "Group staff can not quit group");
return -1; return -1;
@ -1044,9 +1051,10 @@ ccnet_group_manager_get_members_with_prefix (CcnetGroupManager *mgr,
int int
ccnet_group_manager_check_group_staff (CcnetGroupManager *mgr, ccnet_group_manager_check_group_staff (CcnetGroupManager *mgr,
int group_id, 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 int

View File

@ -97,7 +97,8 @@ ccnet_group_manager_get_members_with_prefix (CcnetGroupManager *mgr,
int int
ccnet_group_manager_check_group_staff (CcnetGroupManager *mgr, ccnet_group_manager_check_group_staff (CcnetGroupManager *mgr,
int group_id, int group_id,
const char *user_name); const char *user_name,
int in_structure);
int int
ccnet_group_manager_remove_group_user (CcnetGroupManager *mgr, ccnet_group_manager_remove_group_user (CcnetGroupManager *mgr,

View File

@ -331,8 +331,8 @@ class CcnetThreadedRpcClient(RpcClientBase):
def get_members_with_prefix(self, group_id, prefix): def get_members_with_prefix(self, group_id, prefix):
pass pass
@searpc_func("int", ["int", "string"]) @searpc_func("int", ["int", "string", "int"])
def check_group_staff(self, group_id, username): def check_group_staff(self, group_id, username, in_structure):
pass pass
@searpc_func("int", ["string"]) @searpc_func("int", ["string"])