Remove unused code.

This commit is contained in:
Jiaqiang Xu 2014-05-05 16:32:30 +08:00
parent 5a73198dca
commit aa3d1a2cdf
10 changed files with 15 additions and 1786 deletions

View File

@ -1890,39 +1890,6 @@ seafile_get_user_share_usage (const char *email, GError **error)
return ret;
}
gint64
seafile_get_org_quota_usage (int org_id, GError **error)
{
gint64 ret;
ret = seaf_quota_manager_get_org_usage (seaf->quota_mgr, org_id);
if (ret < 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Internal server error");
return -1;
}
return ret;
}
gint64
seafile_get_org_user_quota_usage (int org_id, const char *user, GError **error)
{
gint64 ret;
if (!user) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Bad user id");
return -1;
}
ret = seaf_quota_manager_get_org_user_usage (seaf->quota_mgr, org_id, user);
if (ret < 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Internal server error");
return -1;
}
return ret;
}
gint64
seafile_server_repo_size(const char *repo_id, GError **error)
{
@ -2115,22 +2082,6 @@ seafile_list_share_repos (const char *email, const char *type,
start, limit);
}
GList *
seafile_list_org_share_repos (int org_id, const char *email, const char *type,
int start, int limit, GError **error)
{
if (g_strcmp0 (type, "from_email") != 0 &&
g_strcmp0 (type, "to_email") != 0 ) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Wrong type argument");
return NULL;
}
return seaf_share_manager_list_org_share_repos (seaf->share_mgr,
org_id, email, type,
start, limit);
}
int
seafile_remove_share (const char *repo_id, const char *from_email,
const char *to_email, GError **error)
@ -2398,277 +2349,6 @@ seafile_is_inner_pub_repo (const char *repo_id, GError **error)
return seaf_repo_manager_is_inner_pub_repo (seaf->repo_mgr, repo_id);
}
/* Org Repo RPC. */
GList *
seafile_get_org_repo_list (int org_id, int start, int limit, GError **error)
{
GList *repos = NULL;
GList *ret = NULL;
if (org_id < 0 || start < 0 || limit < 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Bad args");
return NULL;
}
repos = seaf_repo_manager_get_org_repo_list (seaf->repo_mgr, org_id,
start ,limit);
ret = convert_repo_list (repos);
GList *ptr;
for (ptr = repos; ptr != NULL; ptr = ptr->next)
seaf_repo_unref ((SeafRepo *)ptr->data);
g_list_free (repos);
return ret;
}
int
seafile_remove_org_repo_by_org_id (int org_id, GError **error)
{
if (org_id < 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Bad args");
return -1;
}
return seaf_repo_manager_remove_org_repo_by_org_id (seaf->repo_mgr, org_id);
}
/* Org Group Repo RPC. */
int
seafile_add_org_group_repo (const char *repo_id,
int org_id,
int group_id,
const char *owner,
const char *permission,
GError **error)
{
if (!repo_id || !owner || org_id < 0 || group_id < 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Bad args");
return -1;
}
if (!is_uuid_valid (repo_id)) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Invalid repo id");
return -1;
}
return seaf_repo_manager_add_org_group_repo (seaf->repo_mgr,
repo_id,
org_id,
group_id,
owner,
permission,
error);
}
int
seafile_del_org_group_repo (const char *repo_id,
int org_id,
int group_id,
GError **error)
{
if (!repo_id || org_id < 0 || group_id < 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Bad args");
return -1;
}
if (!is_uuid_valid (repo_id)) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Invalid repo id");
return -1;
}
return seaf_repo_manager_del_org_group_repo (seaf->repo_mgr,
repo_id,
org_id,
group_id,
error);
}
char *
seafile_get_org_group_repoids (int org_id, int group_id, GError **error)
{
SeafRepoManager *mgr = seaf->repo_mgr;
GList *repo_ids = NULL, *ptr;
GString *result;
if (org_id < 0 || group_id < 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Bad args");
return NULL;
}
repo_ids = seaf_repo_manager_get_org_group_repoids (mgr, org_id, group_id,
error);
if (!repo_ids) {
return NULL;
}
result = g_string_new("");
ptr = repo_ids;
while (ptr) {
g_string_append_printf (result, "%s\n", (char *)ptr->data);
g_free (ptr->data);
ptr = ptr->next;
}
g_list_free (repo_ids);
return g_string_free (result, FALSE);
}
char *
seafile_get_org_group_repo_owner (int org_id, int group_id,
const char *repo_id, GError **error)
{
SeafRepoManager *mgr = seaf->repo_mgr;
GString *result = g_string_new ("");
if (!is_uuid_valid (repo_id)) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Invalid repo id");
return NULL;
}
char *owner = seaf_repo_manager_get_org_group_repo_owner (mgr, org_id,
group_id,
repo_id, error);
if (owner) {
g_string_append_printf (result, "%s", owner);
g_free (owner);
}
return g_string_free (result, FALSE);
}
GList *
seafile_get_org_group_repos_by_owner (int org_id, const char *user,
GError **error)
{
SeafRepoManager *mgr = seaf->repo_mgr;
GList *ret = NULL;
if (!user || org_id < 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Bad arguments");
return NULL;
}
ret = seaf_repo_manager_get_org_group_repos_by_owner (mgr, org_id, user,
error);
if (!ret) {
return NULL;
}
return g_list_reverse (ret);
}
char *
seafile_get_org_groups_by_repo (int org_id, const char *repo_id,
GError **error)
{
SeafRepoManager *mgr = seaf->repo_mgr;
GList *group_ids = NULL, *ptr;
GString *result;
if (!repo_id || org_id < 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Bad arguments");
return NULL;
}
if (!is_uuid_valid (repo_id)) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Invalid repo id");
return NULL;
}
group_ids = seaf_repo_manager_get_org_groups_by_repo (mgr, org_id,
repo_id, error);
if (!group_ids) {
return NULL;
}
result = g_string_new("");
ptr = group_ids;
while (ptr) {
g_string_append_printf (result, "%d\n", (int)(long)ptr->data);
ptr = ptr->next;
}
g_list_free (group_ids);
return g_string_free (result, FALSE);
}
/* Org inner public repo RPC */
int
seafile_set_org_inner_pub_repo (int org_id,
const char *repo_id,
const char *permission,
GError **error)
{
if (!repo_id) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Bad args");
return -1;
}
if (!is_uuid_valid (repo_id)) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Invalid repo id");
return -1;
}
if (seaf_repo_manager_set_org_inner_pub_repo (seaf->repo_mgr,
org_id, repo_id,
permission) < 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Internal error");
return -1;
}
return 0;
}
int
seafile_unset_org_inner_pub_repo (int org_id, const char *repo_id, GError **error)
{
if (!repo_id) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Bad args");
return -1;
}
if (!is_uuid_valid (repo_id)) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Invalid repo id");
return -1;
}
if (seaf_repo_manager_unset_org_inner_pub_repo (seaf->repo_mgr,
org_id, repo_id) < 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Internal error");
return -1;
}
return 0;
}
GList *
seafile_list_org_inner_pub_repos (int org_id, GError **error)
{
return seaf_repo_manager_list_org_inner_pub_repos (seaf->repo_mgr, org_id);
}
GList *
seafile_list_org_inner_pub_repos_by_owner (int org_id,
const char *user,
GError **error)
{
if (!user) {
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Bad arguments");
return NULL;
}
return seaf_repo_manager_list_org_inner_pub_repos_by_owner (seaf->repo_mgr,
org_id, user);
}
gint64
seafile_get_file_size (const char *store_id, int version,
const char *file_id, GError **error)
@ -3203,30 +2883,6 @@ seafile_create_repo (const char *repo_name,
return repo_id;
}
char *
seafile_create_org_repo (const char *repo_name,
const char *repo_desc,
const char *user,
const char *passwd,
int org_id,
GError **error)
{
if (!repo_name || !repo_desc || !user || org_id <= 0) {
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Bad arguments");
return NULL;
}
char *repo_id;
repo_id = seaf_repo_manager_create_org_repo (seaf->repo_mgr,
repo_name, repo_desc,
user,
passwd,
org_id, error);
return repo_id;
}
char *
seafile_create_enc_repo (const char *repo_id,
const char *repo_name,
@ -3252,104 +2908,6 @@ seafile_create_enc_repo (const char *repo_id,
return ret;
}
char *
seafile_create_org_enc_repo (const char *repo_id,
const char *repo_name,
const char *repo_desc,
const char *user,
const char *magic,
const char *random_key,
int enc_version,
int org_id,
GError **error)
{
if (!repo_id || !repo_name || !repo_desc || !user || org_id <= 0) {
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Bad arguments");
return NULL;
}
char *ret;
ret = seaf_repo_manager_create_org_enc_repo (seaf->repo_mgr,
repo_id, repo_name, repo_desc,
user,
magic, random_key, enc_version,
org_id, error);
return ret;
}
GList *
seafile_list_org_repos_by_owner (int org_id, const char *user, GError **error)
{
GList *ret = NULL;
GList *repos, *ptr;
SeafRepo *r;
SeafileRepo *repo;
repos = seaf_repo_manager_get_org_repos_by_owner (seaf->repo_mgr, org_id,
user);
ptr = repos;
while (ptr) {
r = ptr->data;
repo = seafile_repo_new ();
g_object_set (repo, "id", r->id, "name", r->name,
"desc", r->desc, "encrypted", r->encrypted,
"enc_version", r->enc_version,
"version", r->version,
"store_id", r->store_id,
NULL);
if (r->encrypted && r->enc_version == 2)
g_object_set (repo, "magic", r->magic,
"random_key", r->random_key, NULL);
ret = g_list_prepend (ret, repo);
seaf_repo_unref (r);
ptr = ptr->next;
}
g_list_free (repos);
ret = g_list_reverse (ret);
return ret;
}
char *
seafile_get_org_repo_owner (const char *repo_id, GError **error)
{
SeafRepoManager *mgr = seaf->repo_mgr;
GString *result = g_string_new ("");
if (!is_uuid_valid (repo_id)) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Invalid repo id");
return NULL;
}
char *owner = seaf_repo_manager_get_org_repo_owner (mgr, repo_id);
if (owner) {
g_string_append_printf (result, "%s", owner);
g_free (owner);
}
return g_string_free (result, FALSE);
}
int
seafile_get_org_id_by_repo_id (const char *repo_id, GError **error)
{
if (!repo_id) {
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Bad arguments");
return -1;
}
if (!is_uuid_valid (repo_id)) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Invalid repo id");
return -1;
}
return seaf_repo_manager_get_org_id_by_repo_id (seaf->repo_mgr, repo_id,
error);
}
int
seafile_set_user_quota (const char *user, gint64 quota, GError **error)
{
@ -3374,43 +2932,6 @@ seafile_get_user_quota (const char *user, GError **error)
return seaf_quota_manager_get_user_quota (seaf->quota_mgr, user);
}
int
seafile_set_org_quota (int org_id, gint64 quota, GError **error)
{
return seaf_quota_manager_set_org_quota (seaf->quota_mgr, org_id, quota);
}
gint64
seafile_get_org_quota (int org_id, GError **error)
{
return seaf_quota_manager_get_org_quota (seaf->quota_mgr, org_id);
}
int
seafile_set_org_user_quota (int org_id, const char *user, gint64 quota, GError **error)
{
if (!user) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Bad arguments");
return -1;
}
return seaf_quota_manager_set_org_user_quota (seaf->quota_mgr,
org_id, user, quota);
}
gint64
seafile_get_org_user_quota (int org_id, const char *user, GError **error)
{
if (!user) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Bad arguments");
return -1;
}
return seaf_quota_manager_get_org_user_quota (seaf->quota_mgr, org_id, user);
}
int
seafile_check_quota (const char *repo_id, GError **error)
{
@ -3887,31 +3408,6 @@ seafile_set_group_repo_permission (int group_id,
error);
}
int
seafile_set_org_group_repo_permission (int org_id,
int group_id,
const char *repo_id,
const char *permission,
GError **error)
{
if (!repo_id || !permission) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Arguments should not be empty");
return -1;
}
if (!is_uuid_valid (repo_id)) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Invalid repo id");
return -1;
}
return seaf_repo_manager_set_org_group_repo_perm (seaf->repo_mgr,
repo_id,
org_id,
group_id,
permission,
error);
}
char *
seafile_get_file_id_by_commit_and_path(const char *repo_id,
const char *commit_id,

View File

@ -431,11 +431,6 @@ gint64 seafile_get_user_quota_usage (const char *email, GError **error);
gint64 seafile_get_user_share_usage (const char *email, GError **error);
gint64 seafile_get_org_quota_usage (int org_id, GError **error);
gint64
seafile_get_org_user_quota_usage (int org_id, const char *user, GError **error);
gint64
seafile_server_repo_size(const char *repo_id, GError **error);
@ -471,10 +466,6 @@ GList *
seafile_list_share_repos (const char *email, const char *type,
int start, int limit, GError **error);
GList *
seafile_list_org_share_repos (int org_id, const char *email, const char *type,
int start, int limit, GError **error);
int
seafile_remove_share (const char *repo_id, const char *from_email,
const char *to_email, GError **error);
@ -503,18 +494,6 @@ seafile_get_group_repo_owner (const char *repo_id, GError **error);
int
seafile_remove_repo_group(int group_id, const char *username, GError **error);
GList *
seafile_get_org_repo_list (int org_id, int start, int limit, GError **error);
int
seafile_remove_org_repo_by_org_id (int org_id, GError **error);
GList *
seafile_list_org_repos_by_owner (int org_id, const char *user, GError **error);
char *
seafile_get_org_repo_owner (const char *repo_id, GError **error);
gint64
seafile_get_file_size (const char *store_id, int version,
const char *file_id, GError **error);
@ -712,18 +691,6 @@ seafile_set_user_quota (const char *user, gint64 quota, GError **error);
gint64
seafile_get_user_quota (const char *user, GError **error);
int
seafile_set_org_quota (int org_id, gint64 quota, GError **error);
gint64
seafile_get_org_quota (int org_id, GError **error);
int
seafile_set_org_user_quota (int org_id, const char *user, gint64 quota, GError **error);
gint64
seafile_get_org_user_quota (int org_id, const char *user, GError **error);
int
seafile_check_quota (const char *repo_id, GError **error);
@ -807,14 +774,6 @@ seafile_create_repo (const char *repo_name,
const char *passwd,
GError **error);
char *
seafile_create_org_repo (const char *repo_name,
const char *repo_desc,
const char *user,
const char *passwd,
int org_id,
GError **error);
char *
seafile_create_enc_repo (const char *repo_id,
const char *repo_name,
@ -825,52 +784,9 @@ seafile_create_enc_repo (const char *repo_id,
int enc_version,
GError **error);
char *
seafile_create_org_enc_repo (const char *repo_id,
const char *repo_name,
const char *repo_desc,
const char *user,
const char *magic,
const char *random_key,
int enc_version,
int org_id,
GError **error);
int
seafile_get_org_id_by_repo_id (const char *repo_id, GError **error);
char *
seafile_check_permission (const char *repo_id, const char *user, GError **error);
int
seafile_add_org_group_repo (const char *repo_id,
int org_id,
int group_id,
const char *owner,
const char *permission,
GError **error);
int
seafile_del_org_group_repo (const char *repo_id,
int org_id,
int group_id,
GError **error);
char *
seafile_get_org_group_repoids (int org_id, int group_id, GError **error);
char *
seafile_get_org_group_repo_owner (int org_id, int group_id,
const char *repo_id, GError **error);
GList *
seafile_get_org_group_repos_by_owner (int org_id, const char *user,
GError **error);
char *
seafile_get_org_groups_by_repo (int org_id, const char *repo_id,
GError **error);
int
seafile_set_inner_pub_repo (const char *repo_id,
const char *permission,
@ -891,23 +807,6 @@ seafile_list_inner_pub_repos_by_owner (const char *user, GError **error);
int
seafile_is_inner_pub_repo (const char *repo_id, GError **error);
int
seafile_set_org_inner_pub_repo (int org_id,
const char *repo_id,
const char *permission,
GError **error);
int
seafile_unset_org_inner_pub_repo (int org_id, const char *repo_id, GError **error);
GList *
seafile_list_org_inner_pub_repos (int org_id, GError **error);
GList *
seafile_list_org_inner_pub_repos_by_owner (int org_id,
const char *user,
GError **error);
int
seafile_set_share_permission (const char *repo_id,
const char *from_email,
@ -921,12 +820,6 @@ seafile_set_group_repo_permission (int group_id,
const char *permission,
GError **error);
int
seafile_set_org_group_repo_permission (int org_id,
int group_id,
const char *repo_id,
const char *permission,
GError **error);
char *
seafile_get_file_id_by_commit_and_path(const char *repo_id,
const char *commit_id,

View File

@ -279,7 +279,6 @@ seaf_quota_manager_check_quota (SeafQuotaManager *mgr,
SeafVirtRepo *vinfo;
const char *r_repo_id = repo_id;
char *user = NULL;
int org_id;
gint64 quota, usage;
int ret = 0;
@ -291,15 +290,6 @@ seaf_quota_manager_check_quota (SeafQuotaManager *mgr,
user = seaf_repo_manager_get_repo_owner (seaf->repo_mgr, r_repo_id);
if (user != NULL) {
quota = seaf_quota_manager_get_user_quota (mgr, user);
} else if (seaf->cloud_mode) {
org_id = seaf_repo_manager_get_repo_org (seaf->repo_mgr, r_repo_id);
if (org_id < 0) {
seaf_warning ("Repo %s has no owner.\n", r_repo_id);
ret = -1;
goto out;
}
quota = seaf_quota_manager_get_org_quota (mgr, org_id);
} else {
seaf_warning ("Repo %s has no owner.\n", r_repo_id);
ret = -1;
@ -309,25 +299,22 @@ seaf_quota_manager_check_quota (SeafQuotaManager *mgr,
if (quota == INFINITE_QUOTA)
goto out;
if (user) {
if (!mgr->calc_share_usage) {
usage = seaf_quota_manager_get_user_usage (mgr, user);
} else {
gint64 my_usage, share_usage;
share_usage = seaf_quota_manager_get_user_share_usage (mgr, user);
if (share_usage < 0) {
ret = -1;
goto out;
}
my_usage = seaf_quota_manager_get_user_usage (mgr, user);
if (my_usage < 0) {
ret = -1;
goto out;
}
usage = my_usage + share_usage;
if (!mgr->calc_share_usage) {
usage = seaf_quota_manager_get_user_usage (mgr, user);
} else {
gint64 my_usage, share_usage;
share_usage = seaf_quota_manager_get_user_share_usage (mgr, user);
if (share_usage < 0) {
ret = -1;
goto out;
}
} else
usage = seaf_quota_manager_get_org_usage (mgr, org_id);
my_usage = seaf_quota_manager_get_user_usage (mgr, user);
if (my_usage < 0) {
ret = -1;
goto out;
}
usage = my_usage + share_usage;
}
if (usage < 0 || usage >= quota)
ret = -1;

View File

@ -29,34 +29,10 @@ gint64
seaf_quota_manager_get_user_quota (SeafQuotaManager *mgr,
const char *user);
/* Set/get quota for a business acount. */
int
seaf_quota_manager_set_org_quota (SeafQuotaManager *mgr,
int org_id,
gint64 quota);
gint64
seaf_quota_manager_get_org_quota (SeafQuotaManager *mgr,
int org_id);
gint64
seaf_quota_manager_get_user_share_usage (SeafQuotaManager *mgr,
const char *user);
/* Set/get quota for a user in a business account.
* The caller should make sure the user is a member of the organization.
*/
int
seaf_quota_manager_set_org_user_quota (SeafQuotaManager *mgr,
int org_id,
const char *user,
gint64 quota);
gint64
seaf_quota_manager_get_org_user_quota (SeafQuotaManager *mgr,
int org_id,
const char *user);
/*
* Check if @repo_id still has free space for upload.
*/
@ -67,12 +43,4 @@ seaf_quota_manager_check_quota (SeafQuotaManager *mgr,
gint64
seaf_quota_manager_get_user_usage (SeafQuotaManager *mgr, const char *user);
gint64
seaf_quota_manager_get_org_usage (SeafQuotaManager *mgr, int org_id);
gint64
seaf_quota_manager_get_org_user_usage (SeafQuotaManager *mgr,
int org_id,
const char *user);
#endif

View File

@ -434,17 +434,6 @@ remove_repo_ondisk (SeafRepoManager *mgr,
1, "string", repo_id);
}
if (seaf->cloud_mode) {
seaf_db_statement_query (db, "DELETE FROM OrgRepo WHERE repo_id = ?",
1, "string", repo_id);
seaf_db_statement_query (db, "DELETE FROM OrgGroupRepo WHERE repo_id = ?",
1, "string", repo_id);
seaf_db_statement_query (db, "DELETE FROM OrgInnerPubRepo WHERE repo_id = ?",
1, "string", repo_id);
}
seaf_db_statement_query (db, "DELETE FROM RepoUserToken WHERE repo_id = ?",
1, "string", repo_id);
@ -678,34 +667,6 @@ create_tables_mysql (SeafRepoManager *mgr)
return -1;
}
if (mgr->seaf->cloud_mode) {
sql = "CREATE TABLE IF NOT EXISTS OrgRepo (org_id INTEGER, "
"repo_id CHAR(37), "
"user VARCHAR(255), "
"INDEX (org_id, repo_id), UNIQUE INDEX (repo_id), "
"INDEX (org_id, user))"
"ENGINE=INNODB";
if (seaf_db_query (db, sql) < 0)
return -1;
sql = "CREATE TABLE IF NOT EXISTS OrgGroupRepo ("
"org_id INTEGER, repo_id CHAR(37), "
"group_id INTEGER, owner VARCHAR(255), permission CHAR(15), "
"UNIQUE INDEX (org_id, group_id, repo_id), "
"INDEX (repo_id), INDEX (owner))"
"ENGINE=INNODB";
if (seaf_db_query (db, sql) < 0)
return -1;
sql = "CREATE TABLE IF NOT EXISTS OrgInnerPubRepo ("
"org_id INTEGER, repo_id CHAR(37),"
"PRIMARY KEY (org_id, repo_id), "
"permission CHAR(15))"
"ENGINE=INNODB";
if (seaf_db_query (db, sql) < 0)
return -1;
}
sql = "CREATE TABLE IF NOT EXISTS RepoUserToken ("
"repo_id CHAR(37), "
"email VARCHAR(255), "
@ -822,62 +783,6 @@ create_tables_sqlite (SeafRepoManager *mgr)
return -1;
}
if (mgr->seaf->cloud_mode) {
/* Org repo */
sql = "CREATE TABLE IF NOT EXISTS OrgRepo (org_id INTEGER, "
"repo_id CHAR(37), user VARCHAR(255))";
if (seaf_db_query (db, sql) < 0)
return -1;
sql = "CREATE UNIQUE INDEX IF NOT EXISTS repoid_indx on "
"OrgRepo (repo_id)";
if (seaf_db_query (db, sql) < 0)
return -1;
sql = "CREATE INDEX IF NOT EXISTS orgid_repoid_indx on "
"OrgRepo (org_id, repo_id)";
if (seaf_db_query (db, sql) < 0)
return -1;
sql = "CREATE INDEX IF NOT EXISTS orgrepo_orgid_user_indx on "
"OrgRepo (org_id, user)";
if (seaf_db_query (db, sql) < 0)
return -1;
/* Org group repo */
sql = "CREATE TABLE IF NOT EXISTS OrgGroupRepo ("
"org_id INTEGER, repo_id CHAR(37), "
"group_id INTEGER, owner VARCHAR(255), permission CHAR(15))";
if (seaf_db_query (db, sql) < 0)
return -1;
sql = "CREATE UNIQUE INDEX IF NOT EXISTS orgid_groupid_repoid_indx on "
"OrgGroupRepo (org_id, group_id, repo_id)";
if (seaf_db_query (db, sql) < 0)
return -1;
sql = "CREATE INDEX IF NOT EXISTS org_repoid_index on "
"OrgGroupRepo (repo_id)";
if (seaf_db_query (db, sql) < 0)
return -1;
sql = "CREATE INDEX IF NOT EXISTS org_owner_indx on "
"OrgGroupRepo (owner)";
if (seaf_db_query (db, sql) < 0)
return -1;
/* Org public repo */
sql = "CREATE TABLE IF NOT EXISTS OrgInnerPubRepo ("
"org_id INTEGER, repo_id CHAR(37),"
"permission CHAR(15),"
"PRIMARY KEY (org_id, repo_id))";
if (seaf_db_query (db, sql) < 0)
return -1;
}
sql = "CREATE TABLE IF NOT EXISTS RepoUserToken ("
"repo_id CHAR(37), "
"email VARCHAR(255), "
@ -996,53 +901,6 @@ create_tables_pgsql (SeafRepoManager *mgr)
return -1;
}
if (mgr->seaf->cloud_mode) {
sql = "CREATE TABLE IF NOT EXISTS OrgRepo (org_id INTEGER, "
"repo_id CHAR(36), "
"\"user\" VARCHAR(255), "
"UNIQUE (repo_id))";
if (seaf_db_query (db, sql) < 0)
return -1;
if (!pgsql_index_exists (db, "orgrepo_orgid_repoid_idx")) {
sql = "CREATE INDEX orgrepo_orgid_repoid_idx ON OrgRepo (org_id, repo_id)";
if (seaf_db_query (db, sql) < 0)
return -1;
}
if (!pgsql_index_exists (db, "orgrepo_orgid_user_idx")) {
sql = "CREATE INDEX orgrepo_orgid_user_idx ON OrgRepo (org_id, \"user\")";
if (seaf_db_query (db, sql) < 0)
return -1;
}
sql = "CREATE TABLE IF NOT EXISTS OrgGroupRepo ("
"org_id INTEGER, repo_id CHAR(36), "
"group_id INTEGER, owner VARCHAR(255), permission VARCHAR(15), "
"UNIQUE (org_id, group_id, repo_id))";
if (seaf_db_query (db, sql) < 0)
return -1;
if (!pgsql_index_exists (db, "orggrouprepo_repoid_idx")) {
sql = "CREATE INDEX orggrouprepo_repoid_idx ON OrgGroupRepo (repo_id)";
if (seaf_db_query (db, sql) < 0)
return -1;
}
if (!pgsql_index_exists (db, "orggrouprepo_owner_idx")) {
sql = "CREATE INDEX orggrouprepo_owner_idx ON OrgGroupRepo (owner)";
if (seaf_db_query (db, sql) < 0)
return -1;
}
sql = "CREATE TABLE IF NOT EXISTS OrgInnerPubRepo ("
"org_id INTEGER, repo_id CHAR(36),"
"PRIMARY KEY (org_id, repo_id), "
"permission VARCHAR(15))";
if (seaf_db_query (db, sql) < 0)
return -1;
}
sql = "CREATE TABLE IF NOT EXISTS RepoUserToken ("
"repo_id CHAR(36), "
"email VARCHAR(255), "
@ -2337,436 +2195,6 @@ seaf_repo_manager_get_inner_pub_repo_perm (SeafRepoManager *mgr,
return seaf_db_statement_get_string(mgr->seaf->db, sql, 1, "string", repo_id);
}
/* Org repos. */
int
seaf_repo_manager_get_repo_org (SeafRepoManager *mgr,
const char *repo_id)
{
char *sql;
sql = "SELECT org_id FROM OrgRepo WHERE repo_id = ?";
return seaf_db_statement_get_int (mgr->seaf->db, sql, 1, "string", repo_id);
}
char *
seaf_repo_manager_get_org_repo_owner (SeafRepoManager *mgr,
const char *repo_id)
{
char *sql;
sql = "SELECT user FROM OrgRepo WHERE repo_id = ?";
char *owner = seaf_db_statement_get_string (mgr->seaf->db, sql,
1, "string", repo_id);
char *owner_l = g_ascii_strdown (owner, -1);
g_free (owner);
return owner_l;
}
int
seaf_repo_manager_set_org_repo (SeafRepoManager *mgr,
int org_id,
const char *repo_id,
const char *user)
{
if (seaf_db_statement_query (mgr->seaf->db,
"INSERT INTO OrgRepo VALUES (?, ?, ?)",
3, "int", org_id, "string", repo_id,
"string", user) < 0)
return -1;
return 0;
}
GList *
seaf_repo_manager_get_org_repo_list (SeafRepoManager *mgr,
int org_id,
int start,
int limit)
{
char *sql;
GList *id_list = NULL, *ptr;
GList *ret = NULL;
sql = "SELECT repo_id FROM OrgRepo "
"WHERE org_id = ? ORDER BY repo_id LIMIT ? OFFSET ?";
if (seaf_db_statement_foreach_row (mgr->seaf->db, sql,
collect_repo_id, &id_list,
3, "int", org_id, "int", limit,
"int", start) < 0) {
return NULL;
}
for (ptr = id_list; ptr; ptr = ptr->next) {
char *repo_id = ptr->data;
SeafRepo *repo = seaf_repo_manager_get_repo (mgr, repo_id);
if (repo != NULL)
ret = g_list_prepend (ret, repo);
}
string_list_free (id_list);
return ret;
}
int
seaf_repo_manager_remove_org_repo_by_org_id (SeafRepoManager *mgr,
int org_id)
{
return seaf_db_statement_query (mgr->seaf->db,
"DELETE FROM OrgRepo WHERE org_id = ?",
1, "int", org_id);
}
GList *
seaf_repo_manager_get_org_repos_by_owner (SeafRepoManager *mgr,
int org_id,
const char *user)
{
GList *id_list = NULL, *ptr;
GList *ret = NULL;
int rc;
if (seaf_db_type(mgr->seaf->db) != SEAF_DB_TYPE_PGSQL)
rc = seaf_db_statement_foreach_row (mgr->seaf->db,
"SELECT repo_id FROM OrgRepo "
"WHERE org_id=? AND user=?",
collect_repo_id, &id_list,
2, "int", org_id, "string", user);
else
rc = seaf_db_statement_foreach_row (mgr->seaf->db,
"SELECT repo_id FROM OrgRepo "
"WHERE org_id=? AND \"user\"=?",
collect_repo_id, &id_list,
2, "int", org_id, "string", user);
if (rc < 0)
return NULL;
for (ptr = id_list; ptr; ptr = ptr->next) {
char *repo_id = ptr->data;
SeafRepo *repo = seaf_repo_manager_get_repo (mgr, repo_id);
if (repo != NULL)
ret = g_list_prepend (ret, repo);
}
string_list_free (id_list);
return ret;
}
int
seaf_repo_manager_get_org_id_by_repo_id (SeafRepoManager *mgr,
const char *repo_id,
GError **error)
{
char *sql;
sql = "SELECT org_id FROM OrgRepo WHERE repo_id = ?";
return seaf_db_statement_get_int (mgr->seaf->db, sql, 1, "string", repo_id);
}
/* Org group repos. */
int
seaf_repo_manager_add_org_group_repo (SeafRepoManager *mgr,
const char *repo_id,
int org_id,
int group_id,
const char *owner,
const char *permission,
GError **error)
{
if (seaf_db_statement_query (mgr->seaf->db,
"INSERT INTO OrgGroupRepo VALUES (?, ?, ?, ?, ?)",
5, "int", org_id, "string", repo_id,
"int", group_id, "string", owner,
"string", permission) < 0)
return -1;
return 0;
}
int
seaf_repo_manager_del_org_group_repo (SeafRepoManager *mgr,
const char *repo_id,
int org_id,
int group_id,
GError **error)
{
return seaf_db_statement_query (mgr->seaf->db,
"DELETE FROM OrgGroupRepo WHERE "
"org_id=? AND group_id=? AND repo_id=?",
3, "int", org_id, "int", group_id,
"string", repo_id);
}
GList *
seaf_repo_manager_get_org_group_repoids (SeafRepoManager *mgr,
int org_id,
int group_id,
GError **error)
{
char *sql;
GList *repo_ids = NULL;
sql = "SELECT repo_id FROM OrgGroupRepo "
"WHERE org_id = ? AND group_id = ?";
if (seaf_db_statement_foreach_row (mgr->seaf->db, sql, get_group_repoids_cb,
&repo_ids,
2, "int", org_id, "int", group_id) < 0)
return NULL;
return g_list_reverse (repo_ids);
}
GList *
seaf_repo_manager_get_org_groups_by_repo (SeafRepoManager *mgr,
int org_id,
const char *repo_id,
GError **error)
{
char *sql;
GList *group_ids = NULL;
sql = "SELECT group_id FROM OrgGroupRepo "
"WHERE org_id = %d AND repo_id = ?";
if (seaf_db_statement_foreach_row (mgr->seaf->db, sql, get_group_ids_cb,
&group_ids,
2, "int", org_id, "string", repo_id) < 0) {
g_list_free (group_ids);
return NULL;
}
return g_list_reverse (group_ids);
}
GList *
seaf_repo_manager_get_org_group_perm_by_repo (SeafRepoManager *mgr,
int org_id,
const char *repo_id,
GError **error)
{
char *sql;
GList *group_perms = NULL, *p;
sql = "SELECT group_id, permission FROM OrgGroupRepo "
"WHERE org_id = ? AND repo_id = ?";
if (seaf_db_statement_foreach_row (mgr->seaf->db, sql, get_group_perms_cb,
&group_perms,
2, "int", org_id, "string", repo_id) < 0) {
for (p = group_perms; p != NULL; p = p->next)
g_free (p->data);
g_list_free (group_perms);
return NULL;
}
return g_list_reverse (group_perms);
}
int
seaf_repo_manager_set_org_group_repo_perm (SeafRepoManager *mgr,
const char *repo_id,
int org_id,
int group_id,
const char *permission,
GError **error)
{
return seaf_db_statement_query (mgr->seaf->db,
"UPDATE OrgGroupRepo SET permission=? WHERE "
"repo_id=? AND org_id=? AND group_id=?",
4, "string", permission, "string", repo_id,
"int", org_id, "int", group_id);
}
char *
seaf_repo_manager_get_org_group_repo_owner (SeafRepoManager *mgr,
int org_id,
int group_id,
const char *repo_id,
GError **error)
{
char *sql;
char *ret = NULL;
sql = "SELECT owner FROM OrgGroupRepo WHERE "
"org_id =? AND group_id = ? AND repo_id = ?";
if (seaf_db_statement_foreach_row (mgr->seaf->db, sql,
get_group_repo_owner, &ret,
3, "int", org_id, "int", group_id,
"string", repo_id) < 0) {
seaf_warning ("DB error when get repo owner from for org repo %s.\n",
repo_id);
return NULL;
}
return ret;
}
GList *
seaf_repo_manager_get_org_group_repos_by_owner (SeafRepoManager *mgr,
int org_id,
const char *owner,
GError **error)
{
char *sql;
GList *repos = NULL;
sql = "SELECT OrgGroupRepo.repo_id, VirtualRepo.repo_id, "
"group_id, owner, permission, commit_id "
"FROM OrgGroupRepo LEFT JOIN VirtualRepo ON "
"OrgGroupRepo.repo_id = VirtualRepo.repo_id, "
"Branch "
"WHERE owner = ? AND "
"OrgGroupRepo.repo_id = Branch.repo_id AND Branch.name = 'master'";
if (seaf_db_statement_foreach_row (mgr->seaf->db, sql, get_group_repos_cb,
&repos, 1, "string", owner) < 0)
return NULL;
return g_list_reverse (repos);
}
/* Org inner public repos */
int
seaf_repo_manager_set_org_inner_pub_repo (SeafRepoManager *mgr,
int org_id,
const char *repo_id,
const char *permission)
{
SeafDB *db = mgr->seaf->db;
char sql[256];
if (seaf_db_type(db) == SEAF_DB_TYPE_PGSQL) {
gboolean err;
snprintf (sql, sizeof(sql),
"SELECT repo_id FROM OrgInnerPubRepo WHERE "
"org_id=%d AND repo_id='%s'", org_id, repo_id);
if (seaf_db_check_for_existence(db, sql, &err))
snprintf(sql, sizeof(sql),
"UPDATE OrgInnerPubRepo SET permission='%s' WHERE"
"org_id=%d AND repo_id='%s'", permission, org_id, repo_id);
else
snprintf(sql, sizeof(sql),
"INSERT INTO OrgIneerPubRepo VALUES "
"(%d, '%s', '%s')", org_id, repo_id, permission);
if (err)
return -1;
return seaf_db_query (db, sql);
} else {
return seaf_db_statement_query (db,
"REPLACE INTO OrgInnerPubRepo VALUES (?, ?, ?)",
3, "int", org_id, "string", repo_id,
"string", permission);
}
return -1;
}
int
seaf_repo_manager_unset_org_inner_pub_repo (SeafRepoManager *mgr,
int org_id,
const char *repo_id)
{
return seaf_db_statement_query (mgr->seaf->db,
"DELETE FROM OrgInnerPubRepo "
"WHERE org_id = ? AND repo_id = ?",
2, "int", org_id, "string", repo_id);
}
gboolean
seaf_repo_manager_is_org_inner_pub_repo (SeafRepoManager *mgr,
int org_id,
const char *repo_id)
{
gboolean db_err = FALSE;
return seaf_db_statement_exists (mgr->seaf->db,
"SELECT repo_id FROM OrgInnerPubRepo WHERE "
"org_id = ? AND repo_id=?", &db_err,
2, "int", org_id, "string", repo_id);
}
GList *
seaf_repo_manager_list_org_inner_pub_repos (SeafRepoManager *mgr,
int org_id)
{
GList *ret = NULL;
char *sql;
sql = "SELECT OrgInnerPubRepo.repo_id, VirtualRepo.repo_id, "
"user, permission, commit_id "
"FROM OrgInnerPubRepo LEFT JOIN VirtualRepo ON "
"OrgInnerPubRepo.repo_id = VirtualRepo.repo_id, OrgRepo, Branch "
"WHERE OrgInnerPubRepo.org_id=? AND "
"OrgInnerPubRepo.repo_id=OrgRepo.repo_id AND "
"OrgInnerPubRepo.org_id=OrgRepo.org_id AND "
"OrgInnerPubRepo.repo_id = Branch.repo_id AND Branch.name = 'master'";
if (seaf_db_statement_foreach_row (mgr->seaf->db, sql,
collect_public_repos, &ret,
1, "int", org_id) < 0)
return NULL;
return g_list_reverse (ret);
}
GList *
seaf_repo_manager_list_org_inner_pub_repos_by_owner (SeafRepoManager *mgr,
int org_id,
const char *user)
{
GList *ret = NULL, *p;
char *sql;
if (seaf_db_type(mgr->seaf->db) != SEAF_DB_TYPE_PGSQL)
sql = "SELECT OrgInnerPubRepo.repo_id, VirtualRepo.repo_id, "
"user, permission, commit_id "
"FROM OrgInnerPubRepo LEFT JOIN VirtualRepo ON "
"OrgInnerPubRepo.repo_id = VirtualRepo.repo_id, OrgRepo, Branch "
"WHERE OrgInnerPubRepo.org_id=%d AND user=? AND "
"OrgInnerPubRepo.repo_id=OrgRepo.repo_id AND "
"OrgInnerPubRepo.org_id=OrgRepo.org_id AND "
"OrgInnerPubRepo.repo_id = Branch.repo_id AND Branch.name = 'master'";
else
sql = "SELECT OrgInnerPubRepo.repo_id, VirtualRepo.repo_id, "
"user, permission, commit_id "
"FROM OrgInnerPubRepo LEFT JOIN VirtualRepo ON "
"OrgInnerPubRepo.repo_id = VirtualRepo.repo_id, OrgRepo, Branch "
"WHERE OrgInnerPubRepo.org_id=%d AND \"user\"=? AND "
"OrgInnerPubRepo.repo_id=OrgRepo.repo_id AND "
"OrgInnerPubRepo.org_id=OrgRepo.org_id AND "
"OrgInnerPubRepo.repo_id = Branch.repo_id AND Branch.name = 'master'";
if (seaf_db_statement_foreach_row (mgr->seaf->db, sql,
collect_public_repos, &ret,
2, "int", org_id, "string", user) < 0) {
for (p = ret; p != NULL; p = p->next)
g_object_unref (p->data);
g_list_free (ret);
return NULL;
}
return g_list_reverse (ret);
}
char *
seaf_repo_manager_get_org_inner_pub_repo_perm (SeafRepoManager *mgr,
int org_id,
const char *repo_id)
{
char *sql;
sql = "SELECT permission FROM OrgInnerPubRepo WHERE "
"org_id=? AND repo_id=?";
return seaf_db_statement_get_string(mgr->seaf->db, sql,
2, "int", org_id, "string", repo_id);
}
int
seaf_repo_manager_is_valid_filename (SeafRepoManager *mgr,
@ -2923,52 +2351,6 @@ bad:
return NULL;
}
char *
seaf_repo_manager_create_org_repo (SeafRepoManager *mgr,
const char *repo_name,
const char *repo_desc,
const char *user,
const char *passwd,
int org_id,
GError **error)
{
char *repo_id = NULL;
char magic[65], random_key[97];
repo_id = gen_uuid ();
if (passwd && passwd[0] != 0) {
seafile_generate_magic (2, repo_id, passwd, magic);
seafile_generate_random_key (passwd, random_key);
}
int rc;
if (passwd)
rc = create_repo_common (mgr, repo_id, repo_name, repo_desc, user,
magic, random_key, CURRENT_ENC_VERSION,
error);
else
rc = create_repo_common (mgr, repo_id, repo_name, repo_desc, user,
NULL, NULL, -1,
error);
if (rc < 0)
goto bad;
if (seaf_repo_manager_set_org_repo (mgr, org_id, repo_id, user) < 0) {
seaf_warning ("Failed to set org repo.\n");
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
"Failed to set org repo.");
goto bad;
}
return repo_id;
bad:
if (repo_id)
g_free (repo_id);
return NULL;
}
char *
seaf_repo_manager_create_enc_repo (SeafRepoManager *mgr,
const char *repo_id,
@ -3008,46 +2390,6 @@ seaf_repo_manager_create_enc_repo (SeafRepoManager *mgr,
return g_strdup (repo_id);
}
char *
seaf_repo_manager_create_org_enc_repo (SeafRepoManager *mgr,
const char *repo_id,
const char *repo_name,
const char *repo_desc,
const char *user,
const char *magic,
const char *random_key,
int enc_version,
int org_id,
GError **error)
{
if (!repo_id || !is_uuid_valid (repo_id)) {
seaf_warning ("Invalid repo_id.\n");
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Invalid repo id");
return NULL;
}
if (seaf_repo_manager_repo_exists (mgr, repo_id)) {
seaf_warning ("Repo %s exists, refuse to create.\n", repo_id);
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
"Repo already exists");
return NULL;
}
if (create_repo_common (mgr, repo_id, repo_name, repo_desc, user,
magic, random_key, enc_version, error) < 0)
return NULL;
if (seaf_repo_manager_set_org_repo (mgr, org_id, repo_id, user) < 0) {
seaf_warning ("Failed to set org repo.\n");
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
"Failed to set org repo.");
return NULL;
}
return g_strdup(repo_id);
}
static int reap_token (void *data)
{
SeafRepoManager *mgr = data;

View File

@ -396,15 +396,6 @@ seaf_repo_manager_create_new_repo (SeafRepoManager *mgr,
const char *passwd,
GError **error);
char *
seaf_repo_manager_create_org_repo (SeafRepoManager *mgr,
const char *repo_name,
const char *repo_desc,
const char *user,
const char *passwd,
int org_id,
GError **error);
char *
seaf_repo_manager_create_enc_repo (SeafRepoManager *mgr,
const char *repo_id,
@ -416,18 +407,6 @@ seaf_repo_manager_create_enc_repo (SeafRepoManager *mgr,
int enc_version,
GError **error);
char *
seaf_repo_manager_create_org_enc_repo (SeafRepoManager *mgr,
const char *repo_id,
const char *repo_name,
const char *repo_desc,
const char *user,
const char *magic,
const char *random_key,
int enc_version,
int org_id,
GError **error);
/* Give a repo and a path in this repo, returns a list of commits, where every
* commit contains a unique version of the file. The commits are sorted in
* ascending order of commit time. */
@ -602,123 +581,6 @@ char *
seaf_repo_manager_get_inner_pub_repo_perm (SeafRepoManager *mgr,
const char *repo_id);
/* Org repos */
int
seaf_repo_manager_get_repo_org (SeafRepoManager *mgr,
const char *repo_id);
char *
seaf_repo_manager_get_org_repo_owner (SeafRepoManager *mgr,
const char *repo_id);
GList *
seaf_repo_manager_get_org_repo_list (SeafRepoManager *mgr,
int org_id,
int start,
int limit);
int
seaf_repo_manager_remove_org_repo_by_org_id (SeafRepoManager *mgr,
int org_id);
GList *
seaf_repo_manager_get_org_repos_by_owner (SeafRepoManager *mgr,
int org_id,
const char *user);
int
seaf_repo_manager_get_org_id_by_repo_id (SeafRepoManager *mgr,
const char *repo_id,
GError **error);
/* Org group repos */
int
seaf_repo_manager_add_org_group_repo (SeafRepoManager *mgr,
const char *repo_id,
int org_id,
int group_id,
const char *owner,
const char *permission,
GError **error);
int
seaf_repo_manager_del_org_group_repo (SeafRepoManager *mgr,
const char *repo_id,
int org_id,
int group_id,
GError **error);
GList *
seaf_repo_manager_get_org_group_repoids (SeafRepoManager *mgr,
int org_id,
int group_id,
GError **error);
GList *
seaf_repo_manager_get_org_groups_by_repo (SeafRepoManager *mgr,
int org_id,
const char *repo_id,
GError **error);
GList *
seaf_repo_manager_get_org_group_perm_by_repo (SeafRepoManager *mgr,
int org_id,
const char *repo_id,
GError **error);
int
seaf_repo_manager_set_org_group_repo_perm (SeafRepoManager *mgr,
const char *repo_id,
int org_id,
int group_id,
const char *permission,
GError **error);
char *
seaf_repo_manager_get_org_group_repo_owner (SeafRepoManager *mgr,
int org_id,
int group_id,
const char *repo_id,
GError **error);
GList *
seaf_repo_manager_get_org_group_repos_by_owner (SeafRepoManager *mgr,
int org_id,
const char *owner,
GError **error);
/* Org inner public repos */
int
seaf_repo_manager_set_org_inner_pub_repo (SeafRepoManager *mgr,
int org_id,
const char *repo_id,
const char *permission);
int
seaf_repo_manager_unset_org_inner_pub_repo (SeafRepoManager *mgr,
int org_id,
const char *repo_id);
gboolean
seaf_repo_manager_is_org_inner_pub_repo (SeafRepoManager *mgr,
int org_id,
const char *repo_id);
GList *
seaf_repo_manager_list_org_inner_pub_repos (SeafRepoManager *mgr, int org_id);
GList *
seaf_repo_manager_list_org_inner_pub_repos_by_owner (SeafRepoManager *mgr,
int org_id,
const char *user);
char *
seaf_repo_manager_get_org_inner_pub_repo_perm (SeafRepoManager *mgr,
int org_id,
const char *repo_id);
/*
* Comprehensive repo permission checker.
* It checks if @user have permission to access @repo_id.

View File

@ -94,92 +94,6 @@ group_out:
return NULL;
}
static char *
check_org_repo_share_permission (SeafRepoManager *mgr,
int org_id,
const char *repo_id,
const char *user_name)
{
SearpcClient *rpc_client;
GList *groups, *p1;
GList *group_perms, *p2;
CcnetGroup *group;
GroupPerm *perm;
int group_id;
char *permission;
rpc_client = ccnet_create_pooled_rpc_client (seaf->client_pool,
NULL,
"ccnet-threaded-rpcserver");
if (!rpc_client)
return NULL;
if (!ccnet_org_user_exists (rpc_client, org_id, user_name)) {
ccnet_rpc_client_free (rpc_client);
return NULL;
}
permission = seaf_share_manager_check_permission (seaf->share_mgr,
repo_id,
user_name);
if (permission != NULL) {
ccnet_rpc_client_free (rpc_client);
return permission;
}
g_free (permission);
/* Get the groups this user belongs to. */
groups = ccnet_get_groups_by_user (rpc_client, user_name);
ccnet_rpc_client_free (rpc_client);
/* Get the groups this repo shared to. */
group_perms = seaf_repo_manager_get_org_group_perm_by_repo (mgr,
org_id,
repo_id,
NULL);
permission = NULL;
/* Check if any one group overlaps. */
for (p1 = groups; p1 != NULL; p1 = p1->next) {
group = p1->data;
g_object_get (group, "id", &group_id, NULL);
for (p2 = group_perms; p2 != NULL; p2 = p2->next) {
perm = p2->data;
if (group_id == perm->group_id) {
/* If the repo is shared to more than 1 groups,
* and user is in more than 1 of these groups,
* "rw" permission will overwrite "ro" permission.
*/
if (g_strcmp0(perm->permission, "rw") == 0) {
permission = perm->permission;
goto group_out;
} else if (g_strcmp0(perm->permission, "r") == 0 &&
!permission) {
permission = perm->permission;
}
}
}
}
group_out:
if (permission != NULL)
permission = g_strdup(permission);
for (p1 = groups; p1 != NULL; p1 = p1->next)
g_object_unref ((GObject *)p1->data);
g_list_free (groups);
for (p2 = group_perms; p2 != NULL; p2 = p2->next)
g_free (p2->data);
g_list_free (group_perms);
if (permission != NULL)
return permission;
return seaf_repo_manager_get_org_inner_pub_repo_perm (mgr, org_id, repo_id);
}
static char *
check_virtual_repo_permission (SeafRepoManager *mgr,
const char *repo_id,
@ -225,7 +139,6 @@ seaf_repo_manager_check_permission (SeafRepoManager *mgr,
{
SeafVirtRepo *vinfo;
char *owner = NULL;
int org_id;
char *permission = NULL;
/* This is a virtual repo.*/
@ -243,25 +156,6 @@ seaf_repo_manager_check_permission (SeafRepoManager *mgr,
permission = g_strdup("rw");
else
permission = check_repo_share_permission (mgr, repo_id, user);
} else if (mgr->seaf->cloud_mode) {
/* Org repo. */
owner = seaf_repo_manager_get_org_repo_owner (mgr, repo_id);
if (!owner) {
seaf_warning ("Failed to get owner of org repo %.10s.\n", repo_id);
goto out;
}
org_id = seaf_repo_manager_get_repo_org (mgr, repo_id);
if (org_id < 0) {
seaf_warning ("Failed to get org of repo %.10s.\n", repo_id);
goto out;
}
if (strcmp (owner, user) == 0)
permission = g_strdup("rw");
else
permission = check_org_repo_share_permission (mgr, org_id,
repo_id, user);
}
out:

View File

@ -333,10 +333,6 @@ static void start_rpc_service (CcnetClient *client, int cloud_mode)
seafile_list_share_repos,
"seafile_list_share_repos",
searpc_signature_objlist__string_string_int_int());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_list_org_share_repos,
"seafile_list_org_share_repos",
searpc_signature_objlist__int_string_string_int_int());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_remove_share,
"seafile_remove_share",
@ -428,14 +424,6 @@ static void start_rpc_service (CcnetClient *client, int cloud_mode)
seafile_get_user_share_usage,
"seafile_get_user_share_usage",
searpc_signature_int64__string());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_org_quota_usage,
"seafile_get_org_quota_usage",
searpc_signature_int64__int());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_org_user_quota_usage,
"seafile_get_org_user_quota_usage",
searpc_signature_int64__int_string());
/* virtual repo */
searpc_server_register_function ("seafserv-threaded-rpcserver",
@ -521,22 +509,6 @@ static void start_rpc_service (CcnetClient *client, int cloud_mode)
seafile_get_user_quota,
"get_user_quota",
searpc_signature_int64__string());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_set_org_quota,
"set_org_quota",
searpc_signature_int__int_int64());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_org_quota,
"get_org_quota",
searpc_signature_int64__int());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_set_org_user_quota,
"set_org_user_quota",
searpc_signature_int__int_string_int64());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_org_user_quota,
"get_org_user_quota",
searpc_signature_int64__int_string());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_check_quota,
"check_quota",
@ -580,89 +552,6 @@ static void start_rpc_service (CcnetClient *client, int cloud_mode)
searpc_signature_objlist__string());
}
/* Org repo */
if (cloud_mode) {
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_create_org_repo,
"seafile_create_org_repo",
searpc_signature_string__string_string_string_string_int());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_create_org_enc_repo,
"seafile_create_org_enc_repo",
searpc_signature_string__string_string_string_string_string_string_int_int());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_org_id_by_repo_id,
"seafile_get_org_id_by_repo_id",
searpc_signature_int__string());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_org_repo_list,
"seafile_get_org_repo_list",
searpc_signature_objlist__int_int_int());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_remove_org_repo_by_org_id,
"seafile_remove_org_repo_by_org_id",
searpc_signature_int__int());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_list_org_repos_by_owner,
"list_org_repos_by_owner",
searpc_signature_objlist__int_string());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_org_repo_owner,
"get_org_repo_owner",
searpc_signature_string__string());
/* org group repo */
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_add_org_group_repo,
"add_org_group_repo",
searpc_signature_int__string_int_int_string_string());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_del_org_group_repo,
"del_org_group_repo",
searpc_signature_int__string_int_int());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_org_group_repoids,
"get_org_group_repoids",
searpc_signature_string__int_int());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_org_group_repo_owner,
"get_org_group_repo_owner",
searpc_signature_string__int_int_string());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_org_group_repos_by_owner,
"get_org_group_repos_by_owner",
searpc_signature_objlist__int_string());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_org_groups_by_repo,
"get_org_groups_by_repo",
searpc_signature_string__int_string());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_set_org_group_repo_permission,
"set_org_group_repo_permission",
searpc_signature_int__int_int_string_string());
/* org inner pub repo */
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_set_org_inner_pub_repo,
"set_org_inner_pub_repo",
searpc_signature_int__int_string_string());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_unset_org_inner_pub_repo,
"unset_org_inner_pub_repo",
searpc_signature_int__int_string());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_list_org_inner_pub_repos,
"list_org_inner_pub_repos",
searpc_signature_objlist__int());
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_list_org_inner_pub_repos_by_owner,
"list_org_inner_pub_repos_by_owner",
searpc_signature_objlist__int_string());
}
/* History */
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_set_repo_history_limit,

View File

@ -240,101 +240,6 @@ seaf_share_manager_list_share_repos (SeafShareManager *mgr, const char *email,
return g_list_reverse (ret);
}
GList*
seaf_share_manager_list_org_share_repos (SeafShareManager *mgr,
int org_id,
const char *email,
const char *type,
int start, int limit)
{
GList *ret = NULL, *p;
char *sql;
if (start == -1 && limit == -1) {
if (g_strcmp0 (type, "from_email") == 0) {
sql = "SELECT SharedRepo.repo_id, VirtualRepo.repo_id, "
"to_email, permission, commit_id FROM "
"SharedRepo LEFT JOIN VirtualRepo ON "
"SharedRepo.repo_id = VirtualRepo.repo_id, "
"OrgRepo, Branch "
"WHERE from_email=? AND "
"OrgRepo.org_id=? AND "
"SharedRepo.repo_id=OrgRepo.repo_id AND "
"SharedRepo.repo_id = Branch.repo_id AND "
"Branch.name = 'master'";
} else if (g_strcmp0 (type, "to_email") == 0) {
sql = "SELECT SharedRepo.repo_id, NULL, "
"from_email, permission, commit_id FROM "
"SharedRepo, OrgRepo, Branch "
"WHERE to_email=? AND "
"OrgRepo.org_id=? AND "
"SharedRepo.repo_id=OrgRepo.repo_id AND "
"SharedRepo.repo_id = Branch.repo_id AND "
"Branch.name = 'master'";
} else {
/* should never reach here */
g_warning ("[share mgr] Wrong column type");
return NULL;
}
if (seaf_db_statement_foreach_row (mgr->seaf->db, sql,
collect_repos, &ret,
2, "string", email, "int", org_id) < 0) {
g_warning ("[share mgr] DB error when get shared repo id and email "
"for %s.\n", email);
for (p = ret; p; p = p->next)
g_object_unref (p->data);
g_list_free (ret);
return NULL;
}
}
else {
if (g_strcmp0 (type, "from_email") == 0) {
sql = "SELECT SharedRepo.repo_id, VirtualRepo.repo_id, "
"to_email, permission, commit_id FROM "
"SharedRepo LEFT JOIN VirtualRepo ON "
"SharedRepo.repo_id = VirtualRepo.repo_id, "
"OrgRepo, Branch "
"WHERE from_email=? AND "
"OrgRepo.org_id=? AND "
"SharedRepo.repo_id=OrgRepo.repo_id AND "
"SharedRepo.repo_id = Branch.repo_id AND "
"Branch.name = 'master' "
"ORDER BY SharedRepo.repo_id "
"LIMIT ? OFFSET ?";
} else if (g_strcmp0 (type, "to_email") == 0) {
sql = "SELECT SharedRepo.repo_id, NULL, "
"from_email, permission FROM "
"SharedRepo, OrgRepo, Branch WHERE "
"to_email=? AND "
"OrgRepo.org_id=? AND "
"SharedRepo.repo_id=OrgRepo.repo_id "
"SharedRepo.repo_id = Branch.repo_id AND "
"Branch.name = 'master' "
"ORDER BY SharedRepo.repo_id "
"LIMIT ? OFFSET ?";
} else {
/* should never reach here */
g_warning ("[share mgr] Wrong column type");
return NULL;
}
if (seaf_db_statement_foreach_row (mgr->seaf->db, sql,
collect_repos, &ret,
4, "string", email, "int", org_id,
"int", limit, "int", start) < 0) {
g_warning ("[share mgr] DB error when get shared repo id and email "
"for %s.\n", email);
for (p = ret; p; p = p->next)
g_object_unref (p->data);
g_list_free (ret);
return NULL;
}
}
return g_list_reverse (ret);
}
static gboolean
collect_shared_to (SeafDBRow *row, void *data)
{

View File

@ -36,13 +36,6 @@ GList*
seaf_share_manager_list_share_repos (SeafShareManager *mgr, const char *email,
const char *type, int start, int limit);
GList*
seaf_share_manager_list_org_share_repos (SeafShareManager *mgr,
int org_id,
const char *email,
const char *type,
int start, int limit);
GList *
seaf_share_manager_list_shared_to (SeafShareManager *mgr,
const char *owner,