Complete quota management RPC.

This commit is contained in:
Jiaqiang Xu 2012-10-26 14:31:23 +08:00
parent 0263129880
commit 7a2805a412
7 changed files with 79 additions and 7 deletions

View File

@ -1721,6 +1721,25 @@ seafile_get_org_quota_usage (int org_id, GError **error)
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 = get_org_user_quota_usage (seaf, 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)
{

View File

@ -483,6 +483,9 @@ gint64 seafile_get_user_quota_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);

View File

@ -527,6 +527,16 @@ class SeafServerThreadedRpcClient(ccnet.RpcClientBase):
pass
get_user_quota_usage = seafile_get_user_quota_usage
@searpc_func("int64", ["int"])
def seafile_get_org_quota_usage(org_id):
pass
get_org_quota_usage = seafile_get_org_quota_usage
@searpc_func("int64", ["int", "string"])
def seafile_get_org_user_quota_usage(org_id, user):
pass
get_org_user_quota_usage = seafile_get_org_user_quota_usage
@searpc_func("int", ["string", "int64"])
def set_user_quota(user, quota):
pass

View File

@ -75,11 +75,16 @@ seaf_quota_manager_get_user_quota (SeafQuotaManager *mgr,
const char *user)
{
char sql[512];
gint64 quota;
snprintf (sql, sizeof(sql),
"SELECT quota FROM UserQuota WHERE user='%s'",
user);
return seaf_db_get_int64 (mgr->session->db, sql);
quota = seaf_db_get_int64 (mgr->session->db, sql);
if (quota <= 0)
quota = mgr->default_quota;
return quota;
}
int
@ -100,11 +105,16 @@ seaf_quota_manager_get_org_quota (SeafQuotaManager *mgr,
int org_id)
{
char sql[512];
gint64 quota;
snprintf (sql, sizeof(sql),
"SELECT quota FROM OrgQuota WHERE org_id='%d'",
org_id);
return seaf_db_get_int64 (mgr->session->db, sql);
quota = seaf_db_get_int64 (mgr->session->db, sql);
if (quota <= 0)
quota = mgr->default_quota;
return quota;
}
int
@ -127,11 +137,17 @@ seaf_quota_manager_get_org_user_quota (SeafQuotaManager *mgr,
const char *user)
{
char sql[512];
gint64 quota;
snprintf (sql, sizeof(sql),
"SELECT quota FROM OrgUserQuota WHERE org_id='%d' AND user='%s'",
org_id, user);
return seaf_db_get_int64 (mgr->session->db, sql);
quota = seaf_db_get_int64 (mgr->session->db, sql);
/* return org quota if per user quota is not set. */
if (quota <= 0)
quota = seaf_quota_manager_get_org_quota (mgr, org_id);
return quota;
}
int
@ -145,8 +161,6 @@ seaf_quota_manager_check_quota (SeafQuotaManager *mgr,
user = seaf_repo_manager_get_repo_owner (seaf->repo_mgr, repo_id);
if (user != NULL) {
quota = seaf_quota_manager_get_user_quota (mgr, user);
if (quota <= 0)
quota = mgr->default_quota;
} else if (seaf->cloud_mode) {
org_id = seaf_repo_manager_get_repo_org (seaf->repo_mgr, repo_id);
if (org_id < 0) {
@ -155,8 +169,6 @@ seaf_quota_manager_check_quota (SeafQuotaManager *mgr,
}
quota = seaf_quota_manager_get_org_quota (mgr, org_id);
if (quota <= 0)
quota = mgr->default_quota;
} else {
seaf_warning ("Repo %s has no owner.\n", repo_id);
return -1;

View File

@ -363,6 +363,10 @@ static void start_rpc_service (CcnetClient *client, int cloud_mode)
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());
/* -------- rpc services -------- */

View File

@ -283,3 +283,22 @@ get_org_quota_usage (SeafileSession *seaf, int org_id)
return ret;
}
gint64
get_org_user_quota_usage (SeafileSession *seaf,
int org_id,
const char *user)
{
char sql[256];
gint64 ret = 0;
snprintf (sql, sizeof(sql),
"SELECT size FROM OrgRepo, RepoSize WHERE "
"org_id=%d AND user = '%s' AND OrgRepo.repo_id=RepoSize.repo_id",
org_id, user);
if (seaf_db_foreach_selected_row (seaf->db, sql,
get_total_size, &ret) < 0)
return -1;
return ret;
}

View File

@ -102,4 +102,9 @@ get_user_quota_usage (SeafileSession *seaf, const char *user_id);
gint64
get_org_quota_usage (SeafileSession *seaf, int org_id);
gint64
get_org_user_quota_usage (SeafileSession *seaf,
int org_id,
const char *user);
#endif /* SEAFILE_H */