diff --git a/lib/rpc_table.py b/lib/rpc_table.py index 599e7d8..1d3752d 100644 --- a/lib/rpc_table.py +++ b/lib/rpc_table.py @@ -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"] ], diff --git a/net/common/rpc-service.c b/net/common/rpc-service.c index 92f6473..a30132a 100644 --- a/net/common/rpc-service.c +++ b/net/common/rpc-service.c @@ -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) diff --git a/net/common/rpc-service.h b/net/common/rpc-service.h index 9c2ba24..e18fbc1 100644 --- a/net/common/rpc-service.h +++ b/net/common/rpc-service.h @@ -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); diff --git a/net/server/group-mgr.c b/net/server/group-mgr.c index e2f4692..81fbd13 100644 --- a/net/server/group-mgr.c +++ b/net/server/group-mgr.c @@ -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, diff --git a/net/server/group-mgr.h b/net/server/group-mgr.h index 45c7997..c47cbef 100644 --- a/net/server/group-mgr.h +++ b/net/server/group-mgr.h @@ -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); diff --git a/python/ccnet/rpc.py b/python/ccnet/rpc.py index 8a7a33f..601de87 100644 --- a/python/ccnet/rpc.py +++ b/python/ccnet/rpc.py @@ -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