1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-09-01 23:46:53 +00:00

Get all group repos by user.

This commit is contained in:
cuihaikuo
2017-12-29 11:46:25 +08:00
parent 2ebb4a097f
commit 8ef799679b
7 changed files with 136 additions and 0 deletions

View File

@@ -5233,4 +5233,28 @@ seafile_get_shared_repo_by_path (const char *repo_id,
return seaf_get_shared_repo_by_path (mgr, repo_id, path, shared_to, is_org ? TRUE:FALSE, error);
}
GList *
seafile_get_group_repos_by_user (const char *user, GError **error)
{
if (!user) {
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Arguments error");
return NULL;
}
SeafRepoManager *mgr = seaf->repo_mgr;
return seaf_get_group_repos_by_user (mgr, user, -1, error);
}
GList *
seafile_get_org_group_repos_by_user (const char *user, int org_id, GError **error)
{
if (!user) {
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Arguments error");
return NULL;
}
SeafRepoManager *mgr = seaf->repo_mgr;
return seaf_get_group_repos_by_user (mgr, user, org_id, error);
}
#endif /* SEAFILE_SERVER */

View File

@@ -1082,4 +1082,10 @@ seafile_get_shared_repo_by_path (const char *repo_id,
const char *shared_to,
int is_org,
GError **error);
GList *
seafile_get_group_repos_by_user (const char *user, GError **error);
GList *
seafile_get_org_group_repos_by_user (const char *user, int org_id, GError **error);
#endif

View File

@@ -609,6 +609,14 @@ class SeafServerThreadedRpcClient(ccnet.RpcClientBase):
def get_group_shared_repo_by_path(repo_id, path, group_id, is_org):
pass
@searpc_func("objlist", ["string"])
def get_group_repos_by_user (user):
pass
@searpc_func("objlist", ["string", "int"])
def get_org_group_repos_by_user (user, org_id):
pass
@searpc_func("objlist", ["string", "string", "string"])
def seafile_get_shared_users_for_subdir(repo_id, path, from_user):
pass

View File

@@ -446,6 +446,15 @@ class SeafileAPI(object):
"""
return seafserv_threaded_rpc.get_group_shared_repo_by_path(repo_id, path, group_id, 1 if is_org else 0)
def get_group_repos_by_user (self, user):
"""
Return all the repos in all groups that the @user belongs to.
"""
return seafserv_threaded_rpc.get_group_repos_by_user(user)
def get_org_group_repos_by_user (self, user, org_id):
return seafserv_threaded_rpc.get_org_group_repos_by_user(user, org_id)
def list_repo_shared_group_by_user(self, from_user, repo_id):
"""
Return: a list of SharedGroup objects (lib/repo.vala)

View File

@@ -3978,3 +3978,78 @@ seaf_get_group_shared_repo_by_path (SeafRepoManager *mgr,
return ret;
}
GList *
seaf_get_group_repos_by_user (SeafRepoManager *mgr,
const char *user,
int org_id,
GError **error)
{
CcnetGroup *group;
GList *groups = NULL, *p;
GList *repos = NULL;
SearpcClient *rpc_client;
GString *sql = NULL;
int group_id = 0;
rpc_client = ccnet_create_pooled_rpc_client (seaf->client_pool,
NULL,
"ccnet-threaded-rpcserver");
if (!rpc_client)
return NULL;
/* Get the groups this user belongs to. */
if (org_id < 0)
groups = ccnet_get_groups_by_user (rpc_client, user);
else
groups = ccnet_get_org_groups_by_user (rpc_client, user, org_id);
if (!groups) {
goto out;
}
sql = g_string_new ("");
g_string_printf (sql, "SELECT g.repo_id, v.repo_id, "
"group_id, %s, permission, commit_id, s.size, "
"v.origin_repo, v.path "
"FROM %s g LEFT JOIN VirtualRepo v ON "
"g.repo_id = v.repo_id "
"LEFT JOIN RepoSize s ON g.repo_id = s.repo_id, "
"Branch b WHERE g.repo_id = b.repo_id AND "
"b.name = 'master' AND group_id IN (",
org_id < 0 ? "user_name" : "owner",
org_id < 0 ? "RepoGroup" : "OrgGroupRepo");
for (p = groups; p != NULL; p = p->next) {
group = p->data;
g_object_get (group, "id", &group_id, NULL);
g_string_append_printf (sql, "%d", group_id);
if (p->next)
g_string_append_printf (sql, ",");
}
g_string_append_printf (sql, " ) ORDER BY group_id");
if (seaf_db_statement_foreach_row (mgr->seaf->db, sql->str, get_group_repos_cb,
&repos, 0) < 0) {
for (p = repos; p; p = p->next) {
g_object_unref (p->data);
}
g_list_free (repos);
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
"Failed to get user group repos from db.");
seaf_warning ("Failed to get user[%s] group repos from db.\n", user);
goto out;
}
seaf_fill_repo_obj_from_commit (&repos);
out:
if (sql)
g_string_free (sql, TRUE);
ccnet_rpc_client_free (rpc_client);
for (p = groups; p != NULL; p = p->next)
g_object_unref ((GObject *)p->data);
g_list_free (groups);
return g_list_reverse (repos);
}

View File

@@ -835,4 +835,10 @@ seaf_get_group_shared_repo_by_path (SeafRepoManager *mgr,
int group_id,
gboolean is_org,
GError **error);
GList *
seaf_get_group_repos_by_user (SeafRepoManager *mgr,
const char *user,
int org_id,
GError **error);
#endif

View File

@@ -462,6 +462,14 @@ static void start_rpc_service (CcnetClient *client, int cloud_mode)
seafile_get_group_shared_repo_by_path,
"get_group_shared_repo_by_path",
searpc_signature_object__string_string_int_int());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_group_repos_by_user,
"get_group_repos_by_user",
searpc_signature_objlist__string());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_org_group_repos_by_user,
"get_org_group_repos_by_user",
searpc_signature_objlist__string_int());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_repos_by_group,
"seafile_get_repos_by_group",