1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-08-02 07:43:09 +00:00

Add rpc get_shared_repo_by_path().

This commit is contained in:
cuihaikuo 2017-10-31 11:02:52 +08:00
parent e195ab4178
commit 1ed203814e
8 changed files with 121 additions and 0 deletions

View File

@ -5242,4 +5242,20 @@ seafile_get_group_shared_repo_by_path (const char *repo_id,
return seaf_get_group_shared_repo_by_path (mgr, repo_id, path, group_id, is_org ? TRUE:FALSE, error);
}
GObject *
seafile_get_shared_repo_by_path (const char *repo_id,
const char *path,
const char *shared_to,
int is_org,
GError **error)
{
if (!repo_id || !shared_to) {
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Arguments error");
return NULL;
}
SeafRepoManager *mgr = seaf->repo_mgr;
return seaf_get_shared_repo_by_path (mgr, repo_id, path, shared_to, is_org ? TRUE:FALSE, error);
}
#endif /* SEAFILE_SERVER */

View File

@ -1076,4 +1076,11 @@ seafile_get_group_shared_repo_by_path (const char *repo_id,
int group_id,
int is_org,
GError **error);
GObject *
seafile_get_shared_repo_by_path (const char *repo_id,
const char *path,
const char *shared_to,
int is_org,
GError **error);
#endif

View File

@ -96,6 +96,7 @@ func_table = [
[ "object", ["string", "int", "string"] ],
[ "object", ["int", "string", "string"] ],
[ "object", ["string", "string", "int", "int"] ],
[ "object", ["string", "string", "string", "int"] ],
[ "object", ["string", "string", "string", "string", "string", "string", "string", "int", "int"] ],
[ "object", ["string", "string", "string", "string", "string", "string", "int", "string", "int", "int"] ],
]

View File

@ -566,6 +566,10 @@ class SeafServerThreadedRpcClient(ccnet.RpcClientBase):
def update_share_subdir_perm_for_user(repo_id, path, owner, share_user, permission):
pass
@searpc_func("object", ["string", "string", "string", "int"])
def get_shared_repo_by_path(repo_id, path, shared_to, is_org):
pass
@searpc_func("objlist", ["int", "string", "string", "int", "int"])
def seafile_list_org_share_repos(org_id, email, query_col, start, limit):
pass

View File

@ -381,6 +381,13 @@ class SeafileAPI(object):
return seafserv_threaded_rpc.update_share_subdir_perm_for_user(repo_id, path, owner,
share_user, permission)
def get_shared_repo_by_path(self, repo_id, path, shared_to, is_org=False):
"""
If path is not NULL, 'repo_id' represents for the repo we want,
otherwise, 'repo_id' represents for the origin repo, return virtual repo
"""
return seafserv_threaded_rpc.get_shared_repo_by_path(repo_id, path, shared_to, 1 if is_org else 0)
def get_share_out_repo_list(self, username, start, limit):
"""
Get repo list shared by this user.

View File

@ -416,6 +416,11 @@ static void start_rpc_service (CcnetClient *client, int cloud_mode)
"update_share_subdir_perm_for_user",
searpc_signature_int__string_string_string_string_string());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_shared_repo_by_path,
"get_shared_repo_by_path",
searpc_signature_object__string_string_string_int());
/* share repo to group */
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_group_share_repo,

View File

@ -608,3 +608,76 @@ seaf_share_manager_is_repo_shared (SeafShareManager *mgr,
return ret;
}
GObject *
seaf_get_shared_repo_by_path (SeafRepoManager *mgr,
const char *repo_id,
const char *path,
const char *shared_to,
int is_org,
GError **error)
{
char *sql;
char *real_repo_id = NULL;
GList *repo = NULL;
GObject *ret = NULL;
/* If path is not NULL, 'repo_id' represents for the repo we want,
* otherwise, 'repo_id' represents for the origin repo,
* find virtual repo by path first.
*/
if (path != NULL) {
real_repo_id = seaf_repo_manager_get_virtual_repo_id (mgr, repo_id, path, NULL);
if (!real_repo_id) {
seaf_warning ("Failed to get virtual repo_id by path %s, origin_repo: %s\n", path, repo_id);
return NULL;
}
}
if (!real_repo_id)
real_repo_id = g_strdup (repo_id);
if (!is_org)
sql = "SELECT sh.repo_id, v.repo_id, "
"from_email, permission, commit_id, s.size, "
"v.origin_repo, v.path, i.name, "
"i.update_time, i.version, i.is_encrypted, i.last_modifier FROM "
"SharedRepo sh LEFT JOIN VirtualRepo v ON "
"sh.repo_id=v.repo_id "
"LEFT JOIN RepoSize s ON sh.repo_id = s.repo_id "
"LEFT JOIN RepoInfo i ON sh.repo_id = i.repo_id, Branch b "
"WHERE to_email=? AND "
"sh.repo_id = b.repo_id AND sh.repo_id=? AND "
"b.name = 'master' ";
else
sql = "SELECT sh.repo_id, v.repo_id, "
"from_email, permission, commit_id, s.size, "
"v.origin_repo, v.path, i.name, "
"i.update_time, i.version, i.is_encrypted, i.last_modifier FROM "
"OrgSharedRepo sh LEFT JOIN VirtualRepo v ON "
"sh.repo_id=v.repo_id "
"LEFT JOIN RepoSize s ON sh.repo_id = s.repo_id "
"LEFT JOIN RepoInfo i ON sh.repo_id = i.repo_id, Branch b "
"WHERE to_email=? AND "
"sh.repo_id = b.repo_id AND sh.repo_id=? AND "
"b.name = 'master' ";
/* The list 'repo' should have only one repo,
* use existing api collect_repos() to get it.
*/
if (seaf_db_statement_foreach_row (mgr->seaf->db, sql,
collect_repos, &repo,
2, "string", shared_to, "string", real_repo_id) < 0) {
g_free (real_repo_id);
g_list_free (repo);
seaf_warning ("[share mgr] DB error when get shared repo "
"for %s, path:%s\n", shared_to, path);
return NULL;
}
g_free (real_repo_id);
if (repo) {
ret = (GObject *)(repo->data);
g_list_free (repo);
}
return ret;
}

View File

@ -75,5 +75,13 @@ int
seaf_share_manager_is_repo_shared (SeafShareManager *mgr,
const char *repo_id);
GObject *
seaf_get_shared_repo_by_path (SeafRepoManager *mgr,
const char *repo_id,
const char *path,
const char *shared_to,
int is_org,
GError **error);
#endif /* SHARE_MGR_H */