mirror of
https://github.com/haiwen/ccnet-server.git
synced 2025-08-01 04:57:13 +00:00
Support listing child groups and users.
This commit is contained in:
parent
c095959cce
commit
d8937ae5ad
@ -49,6 +49,7 @@ func_table = [
|
||||
[ "objlist", ["int"] ],
|
||||
[ "objlist", ["int", "int"] ],
|
||||
[ "objlist", ["int", "int", "int"] ],
|
||||
[ "objlist", ["int", "string"] ],
|
||||
[ "objlist", ["string"] ],
|
||||
[ "objlist", ["string", "int"] ],
|
||||
[ "objlist", ["string", "int", "int"] ],
|
||||
|
@ -264,6 +264,10 @@ ccnet_start_rpc(CcnetSession *session)
|
||||
ccnet_rpc_get_group_members,
|
||||
"get_group_members",
|
||||
searpc_signature_objlist__int());
|
||||
searpc_server_register_function ("ccnet-threaded-rpcserver",
|
||||
ccnet_rpc_get_members_with_prefix,
|
||||
"get_members_with_prefix",
|
||||
searpc_signature_objlist__int_string());
|
||||
searpc_server_register_function ("ccnet-threaded-rpcserver",
|
||||
ccnet_rpc_check_group_staff,
|
||||
"check_group_staff",
|
||||
@ -292,6 +296,10 @@ ccnet_start_rpc(CcnetSession *session)
|
||||
ccnet_rpc_get_child_groups,
|
||||
"get_child_groups",
|
||||
searpc_signature_objlist__int());
|
||||
searpc_server_register_function ("ccnet-threaded-rpcserver",
|
||||
ccnet_rpc_get_descendants_groups,
|
||||
"get_descendants_groups",
|
||||
searpc_signature_objlist__int());
|
||||
|
||||
searpc_server_register_function ("ccnet-threaded-rpcserver",
|
||||
ccnet_rpc_create_org,
|
||||
@ -847,6 +855,18 @@ ccnet_rpc_get_child_groups (int group_id, GError **error)
|
||||
return groups;
|
||||
}
|
||||
|
||||
GList*
|
||||
ccnet_rpc_get_descendants_groups(int group_id, GError **error)
|
||||
{
|
||||
CcnetGroupManager *group_mgr =
|
||||
((CcnetServerSession *)session)->group_mgr;
|
||||
GList *groups = NULL;
|
||||
|
||||
groups = ccnet_group_manager_get_descendants_groups (group_mgr, group_id, error);
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
GList*
|
||||
ccnet_rpc_search_ldapusers (const char *keyword,
|
||||
int start, int limit,
|
||||
@ -1218,6 +1238,18 @@ ccnet_rpc_get_group_members (int group_id, GError **error)
|
||||
return g_list_reverse (ret);
|
||||
}
|
||||
|
||||
GList *
|
||||
ccnet_rpc_get_members_with_prefix(int group_id, const char *prefix, GError **error)
|
||||
{
|
||||
CcnetGroupManager *group_mgr =
|
||||
((CcnetServerSession *)session)->group_mgr;
|
||||
GList *ret = NULL;
|
||||
|
||||
ret = ccnet_group_manager_get_members_with_prefix (group_mgr, group_id, prefix, error);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
ccnet_rpc_check_group_staff (int group_id, const char *user_name,
|
||||
GError **error)
|
||||
|
@ -227,12 +227,18 @@ ccnet_rpc_get_top_groups (GError **error);
|
||||
GList *
|
||||
ccnet_rpc_get_child_groups (int group_id, GError **error);
|
||||
|
||||
GList *
|
||||
ccnet_rpc_get_descendants_groups(int group_id, GError **error);
|
||||
|
||||
GObject *
|
||||
ccnet_rpc_get_group (int group_id, GError **error);
|
||||
|
||||
GList *
|
||||
ccnet_rpc_get_group_members (int group_id, GError **error);
|
||||
|
||||
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,
|
||||
GError **error);
|
||||
|
@ -864,6 +864,33 @@ ccnet_group_manager_get_child_groups (CcnetGroupManager *mgr, int group_id,
|
||||
return ret;
|
||||
}
|
||||
|
||||
GList *
|
||||
ccnet_group_manager_get_descendants_groups(CcnetGroupManager *mgr, int group_id,
|
||||
GError **error)
|
||||
{
|
||||
GList *ret = NULL;
|
||||
CcnetDB *db = mgr->priv->db;
|
||||
const char *table_name = mgr->priv->table_name;
|
||||
|
||||
GString *sql = g_string_new("");
|
||||
g_string_printf (sql, "SELECT g.group_id, group_name, creator_name, timestamp, "
|
||||
"parent_group_id FROM `%s` g, GroupStructure s "
|
||||
"WHERE g.group_id=s.group_id "
|
||||
"AND (s.path LIKE '%d, %%' OR s.path LIKE '%%, %d, %%' "
|
||||
"OR g.group_id=?)",
|
||||
table_name, group_id, group_id);
|
||||
|
||||
if (ccnet_db_statement_foreach_row (db, sql->str,
|
||||
get_user_groups_cb, &ret,
|
||||
1, "int", group_id) < 0) {
|
||||
g_string_free (sql, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
g_string_free (sql, TRUE);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CcnetGroup *
|
||||
ccnet_group_manager_get_group (CcnetGroupManager *mgr, int group_id,
|
||||
GError **error)
|
||||
@ -933,6 +960,47 @@ ccnet_group_manager_get_group_members (CcnetGroupManager *mgr, int group_id,
|
||||
return g_list_reverse (group_users);
|
||||
}
|
||||
|
||||
GList *
|
||||
ccnet_group_manager_get_members_with_prefix (CcnetGroupManager *mgr,
|
||||
int group_id,
|
||||
const char *prefix,
|
||||
GError **error)
|
||||
{
|
||||
CcnetDB *db = mgr->priv->db;
|
||||
GList *group_users = NULL;
|
||||
GList *ptr;
|
||||
CcnetGroup *group;
|
||||
GString *sql = g_string_new ("");
|
||||
int id;
|
||||
|
||||
g_string_printf(sql, "SELECT group_id, user_name, is_staff FROM GroupUser "
|
||||
"WHERE group_id IN (");
|
||||
GList *groups = ccnet_group_manager_get_descendants_groups(mgr, group_id, NULL);
|
||||
if (!groups)
|
||||
g_string_append_printf(sql, "%d", group_id);
|
||||
|
||||
for (ptr = groups; ptr; ptr = ptr->next) {
|
||||
group = ptr->data;
|
||||
g_object_get(group, "id", &id, NULL);
|
||||
g_string_append_printf(sql, "%d", id);
|
||||
if (ptr->next)
|
||||
g_string_append_printf(sql, ", ");
|
||||
}
|
||||
g_string_append_printf(sql, ")");
|
||||
if (prefix)
|
||||
g_string_append_printf(sql, " AND user_name LIKE '%s%%'", prefix);
|
||||
g_list_free_full (groups, g_object_unref);
|
||||
|
||||
if (ccnet_db_statement_foreach_row (db, sql->str,
|
||||
get_ccnet_groupuser_cb, &group_users, 0) < 0) {
|
||||
g_string_free(sql, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
g_string_free(sql, TRUE);
|
||||
|
||||
return group_users;
|
||||
}
|
||||
|
||||
int
|
||||
ccnet_group_manager_check_group_staff (CcnetGroupManager *mgr,
|
||||
int group_id,
|
||||
|
@ -88,6 +88,12 @@ GList *
|
||||
ccnet_group_manager_get_group_members (CcnetGroupManager *mgr, int group_id,
|
||||
GError **error);
|
||||
|
||||
GList *
|
||||
ccnet_group_manager_get_members_with_prefix (CcnetGroupManager *mgr,
|
||||
int group_id,
|
||||
const char *prefix,
|
||||
GError **error);
|
||||
|
||||
int
|
||||
ccnet_group_manager_check_group_staff (CcnetGroupManager *mgr,
|
||||
int group_id,
|
||||
@ -123,6 +129,10 @@ GList *
|
||||
ccnet_group_manager_get_child_groups (CcnetGroupManager *mgr, int group_id,
|
||||
GError **error);
|
||||
|
||||
GList *
|
||||
ccnet_group_manager_get_descendants_groups (CcnetGroupManager *mgr, int group_id,
|
||||
GError **error);
|
||||
|
||||
GList *
|
||||
ccnet_group_manager_get_ancestor_groups (CcnetGroupManager *mgr, int group_id);
|
||||
|
||||
|
@ -315,6 +315,10 @@ class CcnetThreadedRpcClient(RpcClientBase):
|
||||
def get_child_groups(self, group_id):
|
||||
pass
|
||||
|
||||
@searpc_func("objlist", ["int"])
|
||||
def get_descendants_groups(self, group_id):
|
||||
pass
|
||||
|
||||
@searpc_func("object", ["int"])
|
||||
def get_group(self, group_id):
|
||||
pass
|
||||
@ -323,6 +327,10 @@ class CcnetThreadedRpcClient(RpcClientBase):
|
||||
def get_group_members(self, group_id):
|
||||
pass
|
||||
|
||||
@searpc_func("objlist", ["int", "string"])
|
||||
def get_members_with_prefix(self, group_id, prefix):
|
||||
pass
|
||||
|
||||
@searpc_func("int", ["int", "string"])
|
||||
def check_group_staff(self, group_id, username):
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user