diff --git a/common/rpc-service.c b/common/rpc-service.c index edef1dc..3eac091 100644 --- a/common/rpc-service.c +++ b/common/rpc-service.c @@ -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 */ diff --git a/include/seafile-rpc.h b/include/seafile-rpc.h index 7d4aa06..ca863ae 100644 --- a/include/seafile-rpc.h +++ b/include/seafile-rpc.h @@ -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 diff --git a/lib/rpc_table.py b/lib/rpc_table.py index 5febc5e..d822585 100644 --- a/lib/rpc_table.py +++ b/lib/rpc_table.py @@ -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"] ], ] diff --git a/python/seafile/rpcclient.py b/python/seafile/rpcclient.py index 3687553..38cba60 100644 --- a/python/seafile/rpcclient.py +++ b/python/seafile/rpcclient.py @@ -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 diff --git a/python/seaserv/api.py b/python/seaserv/api.py index 118cac8..3f9aa76 100644 --- a/python/seaserv/api.py +++ b/python/seaserv/api.py @@ -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. diff --git a/server/seaf-server.c b/server/seaf-server.c index 3151630..3fcaeea 100644 --- a/server/seaf-server.c +++ b/server/seaf-server.c @@ -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, diff --git a/server/share-mgr.c b/server/share-mgr.c index f1fd5be..7cd077e 100644 --- a/server/share-mgr.c +++ b/server/share-mgr.c @@ -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; +} diff --git a/server/share-mgr.h b/server/share-mgr.h index bd2850f..00235ef 100644 --- a/server/share-mgr.h +++ b/server/share-mgr.h @@ -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 */