1
0
mirror of https://github.com/haiwen/ccnet-server.git synced 2025-05-10 16:14:22 +00:00

Merge pull request from haiwen/list_child_groups_users

Support listing child groups and members.
This commit is contained in:
Jiaqiang Xu 2018-05-09 10:13:51 +08:00 committed by GitHub
commit 802dc5cfb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 139 additions and 1 deletions

View File

@ -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"] ],

View File

@ -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)

View File

@ -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);

View File

@ -130,7 +130,7 @@ static int check_db_table (CcnetGroupManager *manager, CcnetDB *db)
sql = "CREATE TABLE IF NOT EXISTS GroupStructure ( "
"id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, group_id INTEGER, "
"path VARCHAR(1024), UNIQUE INDEX(group_id))ENGINE=INNODB";
"path VARCHAR(1024), UNIQUE INDEX(group_id), UNIQUE INDEX(path))ENGINE=INNODB";
if (ccnet_db_query (db, sql) < 0)
return -1;
} else if (db_type == CCNET_DB_TYPE_SQLITE) {
@ -168,6 +168,12 @@ static int check_db_table (CcnetGroupManager *manager, CcnetDB *db)
"path VARCHAR(1024))";
if (ccnet_db_query (db, sql) < 0)
return -1;
sql = "CREATE UNIQUE INDEX IF NOT EXISTS path_indx on "
"`GroupStructure` (`path`)";
if (ccnet_db_query (db, sql) < 0)
return -1;
} else if (db_type == CCNET_DB_TYPE_PGSQL) {
g_string_printf (group_sql,
"CREATE TABLE IF NOT EXISTS \"%s\" (group_id SERIAL"
@ -200,6 +206,13 @@ static int check_db_table (CcnetGroupManager *manager, CcnetDB *db)
"path VARCHAR(1024))";
if (ccnet_db_query (db, sql) < 0)
return -1;
if (!pgsql_index_exists (db, "structure_path_idx")) {
sql = "CREATE UNIQUE structure_path_idx ON GroupStructure (path)";
if (ccnet_db_query (db, sql) < 0)
return -1;
}
}
g_string_free (group_sql, TRUE);
@ -864,6 +877,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 +973,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,

View File

@ -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,
@ -124,6 +130,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);

View File

@ -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