mirror of
https://github.com/haiwen/seafile.git
synced 2025-01-09 04:17:30 +08:00
Add read/write permission control to share.
This commit is contained in:
parent
ccab1a3786
commit
a5c4db212b
@ -1861,9 +1861,12 @@ seafile_list_share_repos (const char *email, const char *type,
|
||||
"name", repoInfo->repo->name,
|
||||
"desc", repoInfo->repo->desc,
|
||||
"encrypted", repoInfo->repo->encrypted,
|
||||
"shared_email", repoInfo->email, NULL);
|
||||
"shared_email", repoInfo->email,
|
||||
"share_permission", repoInfo->permission,
|
||||
NULL);
|
||||
seaf_repo_unref (repoInfo->repo);
|
||||
g_free (repoInfo->email);
|
||||
g_free (repoInfo->permission);
|
||||
g_free (repoInfo);
|
||||
ret = g_list_prepend (ret, repo);
|
||||
ptr = ptr->next;
|
||||
@ -2947,16 +2950,73 @@ seafile_get_repo_token_nonnull (const char *repo_id,
|
||||
return token;
|
||||
}
|
||||
|
||||
int
|
||||
char *
|
||||
seafile_check_permission (const char *repo_id, const char *user, GError **error)
|
||||
{
|
||||
if (!repo_id || !user) {
|
||||
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Arguments should not be empty");
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return seaf_repo_manager_check_permission (seaf->repo_mgr,
|
||||
repo_id, user, error);
|
||||
}
|
||||
|
||||
int
|
||||
seafile_set_share_permission (const char *repo_id,
|
||||
const char *from_email,
|
||||
const char *to_email,
|
||||
const char *permission,
|
||||
GError **error)
|
||||
{
|
||||
if (!repo_id || !from_email || !to_email || !permission) {
|
||||
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Arguments should not be empty");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return seaf_share_manager_set_permission (seaf->share_mgr,
|
||||
repo_id,
|
||||
from_email,
|
||||
to_email,
|
||||
permission);
|
||||
}
|
||||
|
||||
int
|
||||
seafile_set_group_repo_permission (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;
|
||||
}
|
||||
|
||||
return seaf_repo_manager_set_group_repo_perm (seaf->repo_mgr,
|
||||
repo_id,
|
||||
group_id,
|
||||
permission,
|
||||
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;
|
||||
}
|
||||
|
||||
return seaf_repo_manager_set_org_group_repo_perm (seaf->repo_mgr,
|
||||
repo_id,
|
||||
org_id,
|
||||
group_id,
|
||||
permission,
|
||||
error);
|
||||
}
|
||||
|
||||
#endif /* SEAFILE_SERVER */
|
||||
|
@ -738,7 +738,7 @@ seafile_create_org_repo (const char *repo_name,
|
||||
int
|
||||
seafile_get_org_id_by_repo_id (const char *repo_id, GError **error);
|
||||
|
||||
int
|
||||
char *
|
||||
seafile_check_permission (const char *repo_id, const char *user, GError **error);
|
||||
|
||||
int
|
||||
@ -791,6 +791,26 @@ seafile_unset_org_inner_pub_repo (int org_id, const char *repo_id, GError **erro
|
||||
GList *
|
||||
seafile_list_org_inner_pub_repos (int org_id, GError **error);
|
||||
|
||||
int
|
||||
seafile_set_share_permission (const char *repo_id,
|
||||
const char *from_email,
|
||||
const char *to_email,
|
||||
const char *permission,
|
||||
GError **error);
|
||||
|
||||
int
|
||||
seafile_set_group_repo_permission (int group_id,
|
||||
const char *repo_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);
|
||||
|
||||
/* ------------------ Public RPC calls. ------------ */
|
||||
|
||||
GList* seafile_get_repo_list_pub (int start, int limit, GError **error);
|
||||
|
@ -57,6 +57,8 @@ public class Repo : Object {
|
||||
|
||||
public string shared_email { get; set; }
|
||||
|
||||
public string share_permission { get; set; }
|
||||
|
||||
public bool no_local_history { get; set; }
|
||||
}
|
||||
|
||||
@ -101,6 +103,7 @@ public class RepoGroup : Object {
|
||||
public string repo_id { get; set; }
|
||||
public int group_id { get; set; }
|
||||
public string user_name { get; set; }
|
||||
public string permission { get; set; }
|
||||
}
|
||||
|
||||
public class DiffEntry : Object {
|
||||
|
@ -11,6 +11,7 @@ func_table = [
|
||||
[ "int", ["int", "string", "int"] ],
|
||||
[ "int", ["int", "string", "string"] ],
|
||||
[ "int", ["int", "string", "int", "int"] ],
|
||||
[ "int", ["int", "int", "string", "string"] ],
|
||||
[ "int", ["string"] ],
|
||||
[ "int", ["string", "int"] ],
|
||||
[ "int", ["string", "int", "int"] ],
|
||||
|
@ -431,6 +431,10 @@ class SeafServerThreadedRpcClient(ccnet.RpcClientBase):
|
||||
pass
|
||||
remove_share = seafile_remove_share
|
||||
|
||||
@searpc_func("int", ["string", "string", "string", "string"])
|
||||
def set_share_permission(repo_id, from_email, to_email, permission):
|
||||
pass
|
||||
|
||||
# share repo to group
|
||||
@searpc_func("int", ["string", "int", "string", "string"])
|
||||
def seafile_group_share_repo(repo_id, group_id, user_name, permisson):
|
||||
@ -464,6 +468,10 @@ class SeafServerThreadedRpcClient(ccnet.RpcClientBase):
|
||||
def seafile_remove_repo_group(group_id, user_name):
|
||||
pass
|
||||
remove_repo_group = seafile_remove_repo_group
|
||||
|
||||
@searpc_func("int", ["int", "string", "string"])
|
||||
def set_group_repo_permission(group_id, repo_id, permission):
|
||||
pass
|
||||
|
||||
# branch and commit
|
||||
@searpc_func("objlist", ["string"])
|
||||
@ -541,7 +549,7 @@ class SeafServerThreadedRpcClient(ccnet.RpcClientBase):
|
||||
create_repo = seafile_create_repo
|
||||
|
||||
# repo permission checking
|
||||
@searpc_func("int", ["string", "string"])
|
||||
@searpc_func("string", ["string", "string"])
|
||||
def check_permission(repo_id, user):
|
||||
pass
|
||||
|
||||
@ -598,6 +606,10 @@ class SeafServerThreadedRpcClient(ccnet.RpcClientBase):
|
||||
@searpc_func("string", ["int", "string"])
|
||||
def get_org_groups_by_repo(org_id, repo_id):
|
||||
pass
|
||||
|
||||
@searpc_func("int", ["int", "int", "string", "string"])
|
||||
def set_org_group_repo_permission(org_id, group_id, repo_id, permission):
|
||||
pass
|
||||
|
||||
# inner pub repo
|
||||
@searpc_func("int", ["string"])
|
||||
|
@ -150,7 +150,7 @@ check_repo_share_permission (SearpcClient *rpc_client,
|
||||
|
||||
if (seaf_share_manager_check_permission (seaf->share_mgr,
|
||||
repo_id,
|
||||
user_name) == 0)
|
||||
user_name) != NULL)
|
||||
return TRUE;
|
||||
|
||||
groups = ccnet_get_groups_by_user (rpc_client, user_name);
|
||||
|
@ -228,8 +228,11 @@ check_tx (void *vprocessor)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (seaf_repo_manager_check_permission (seaf->repo_mgr,
|
||||
repo_id, user, NULL) < 0) {
|
||||
char *perm = seaf_repo_manager_check_permission (seaf->repo_mgr,
|
||||
repo_id, user, NULL);
|
||||
if (!perm ||
|
||||
(strcmp (perm, "r") == 0 && priv->type == CHECK_TX_TYPE_UPLOAD))
|
||||
{
|
||||
priv->rsp_code = g_strdup(SC_ACCESS_DENIED);
|
||||
priv->rsp_msg = g_strdup(SS_ACCESS_DENIED);
|
||||
goto out;
|
||||
|
@ -1349,6 +1349,58 @@ seaf_repo_manager_get_groups_by_repo (SeafRepoManager *mgr,
|
||||
return g_list_reverse (group_ids);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_group_perms_cb (SeafDBRow *row, void *data)
|
||||
{
|
||||
GList **plist = data;
|
||||
GroupPerm *perm = g_new0 (GroupPerm, 1);
|
||||
|
||||
perm->group_id = seaf_db_row_get_column_int (row, 0);
|
||||
perm->permission = g_strdup(seaf_db_row_get_column_text(row, 1));
|
||||
|
||||
*plist = g_list_prepend (*plist, perm);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GList *
|
||||
seaf_repo_manager_get_group_perm_by_repo (SeafRepoManager *mgr,
|
||||
const char *repo_id,
|
||||
GError **error)
|
||||
{
|
||||
char sql[512];
|
||||
GList *group_perms = NULL, *p;
|
||||
|
||||
snprintf (sql, sizeof(sql), "SELECT group_id, permission FROM RepoGroup "
|
||||
"WHERE repo_id = '%s'", repo_id);
|
||||
|
||||
if (seaf_db_foreach_selected_row (mgr->seaf->db, sql, get_group_perms_cb,
|
||||
&group_perms) < 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_group_repo_perm (SeafRepoManager *mgr,
|
||||
const char *repo_id,
|
||||
int group_id,
|
||||
const char *permission,
|
||||
GError **error)
|
||||
{
|
||||
char sql[512];
|
||||
|
||||
snprintf (sql, sizeof(sql),
|
||||
"UPDATE RepoGroup SET permission='%s' WHERE "
|
||||
"repo_id='%s' AND group_id=%d",
|
||||
permission, repo_id, group_id);
|
||||
return seaf_db_query (mgr->seaf->db, sql);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_group_repoids_cb (SeafDBRow *row, void *data)
|
||||
{
|
||||
@ -1384,13 +1436,16 @@ get_group_repos_cb (SeafDBRow *row, void *data)
|
||||
GList **p_list = data;
|
||||
SeafileRepoGroup *repo_group = NULL;
|
||||
|
||||
char *repo_id = g_strdup ((const char *)seaf_db_row_get_column_text (row, 0));
|
||||
const char *repo_id = seaf_db_row_get_column_text (row, 0);
|
||||
int group_id = seaf_db_row_get_column_int (row, 1);
|
||||
char *user_name = g_strdup ((const char *)seaf_db_row_get_column_text (row, 2));
|
||||
const char *user_name = seaf_db_row_get_column_text (row, 2);
|
||||
const char *permission = seaf_db_row_get_column_text (row, 3);
|
||||
|
||||
repo_group = g_object_new (SEAFILE_TYPE_REPO_GROUP,
|
||||
"repo_id", repo_id,
|
||||
"group_id", group_id,
|
||||
"user_name", user_name,
|
||||
"permission", permission,
|
||||
NULL);
|
||||
if (repo_group != NULL) {
|
||||
/* g_object_ref (repo_group); */
|
||||
@ -1408,7 +1463,7 @@ seaf_repo_manager_get_group_repos_by_owner (SeafRepoManager *mgr,
|
||||
char sql[512];
|
||||
GList *repos = NULL;
|
||||
|
||||
snprintf (sql, sizeof(sql), "SELECT repo_id, group_id, user_name "
|
||||
snprintf (sql, sizeof(sql), "SELECT repo_id, group_id, user_name, permission "
|
||||
"FROM RepoGroup WHERE user_name = '%s'", owner);
|
||||
if (seaf_db_foreach_selected_row (mgr->seaf->db, sql, get_group_repos_cb,
|
||||
&repos) < 0)
|
||||
@ -1705,6 +1760,47 @@ seaf_repo_manager_get_org_groups_by_repo (SeafRepoManager *mgr,
|
||||
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[512];
|
||||
GList *group_perms = NULL, *p;
|
||||
|
||||
snprintf (sql, sizeof(sql), "SELECT group_id, permission FROM OrgGroupRepo "
|
||||
"WHERE org_id = %d AND repo_id = '%s'",
|
||||
org_id, repo_id);
|
||||
|
||||
if (seaf_db_foreach_selected_row (mgr->seaf->db, sql, get_group_perms_cb,
|
||||
&group_perms) < 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)
|
||||
{
|
||||
char sql[512];
|
||||
|
||||
snprintf (sql, sizeof(sql),
|
||||
"UPDATE OrgGroupRepo SET permission='%s' WHERE "
|
||||
"repo_id='%s' AND org_id=%d AND group_id=%d",
|
||||
permission, repo_id, org_id, group_id);
|
||||
return seaf_db_query (mgr->seaf->db, sql);
|
||||
}
|
||||
|
||||
char *
|
||||
seaf_repo_manager_get_org_group_repo_owner (SeafRepoManager *mgr,
|
||||
int org_id,
|
||||
@ -1737,7 +1833,7 @@ seaf_repo_manager_get_org_group_repos_by_owner (SeafRepoManager *mgr,
|
||||
char sql[512];
|
||||
GList *repos = NULL;
|
||||
|
||||
snprintf (sql, sizeof(sql), "SELECT repo_id, group_id, owner "
|
||||
snprintf (sql, sizeof(sql), "SELECT repo_id, group_id, owner, permission "
|
||||
"FROM OrgGroupRepo WHERE owner = '%s'", owner);
|
||||
if (seaf_db_foreach_selected_row (mgr->seaf->db, sql, get_group_repos_cb,
|
||||
&repos) < 0)
|
||||
@ -1805,32 +1901,35 @@ seaf_repo_manager_list_org_inner_pub_repos (SeafRepoManager *mgr,
|
||||
return g_list_reverse (ret);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
static char *
|
||||
check_repo_share_permission (SeafRepoManager *mgr,
|
||||
const char *repo_id,
|
||||
const char *user_name)
|
||||
{
|
||||
SearpcClient *rpc_client;
|
||||
GList *groups, *p1;
|
||||
GList *repo_groups, *p2;
|
||||
GList *group_perms, *p2;
|
||||
CcnetGroup *group;
|
||||
int group_id, repo_group_id;
|
||||
gboolean ret = FALSE;
|
||||
GroupPerm *perm;
|
||||
int group_id;
|
||||
char *permission;
|
||||
|
||||
if (!mgr->seaf->cloud_mode &&
|
||||
seaf_repo_manager_is_inner_pub_repo (mgr, repo_id))
|
||||
return TRUE;
|
||||
return g_strdup("rw");
|
||||
|
||||
if (seaf_share_manager_check_permission (seaf->share_mgr,
|
||||
repo_id,
|
||||
user_name) == 0)
|
||||
return TRUE;
|
||||
permission = seaf_share_manager_check_permission (seaf->share_mgr,
|
||||
repo_id,
|
||||
user_name);
|
||||
if (g_strcmp0(permission, "rw") == 0 || g_strcmp0(permission, "r") == 0)
|
||||
return permission;
|
||||
g_free (permission);
|
||||
|
||||
rpc_client = ccnet_create_pooled_rpc_client (seaf->client_pool,
|
||||
NULL,
|
||||
"ccnet-threaded-rpcserver");
|
||||
if (!rpc_client)
|
||||
return FALSE;
|
||||
return NULL;
|
||||
|
||||
/* Get the groups this user belongs to. */
|
||||
groups = ccnet_get_groups_by_user (rpc_client, user_name);
|
||||
@ -1838,18 +1937,28 @@ check_repo_share_permission (SeafRepoManager *mgr,
|
||||
ccnet_rpc_client_free (rpc_client);
|
||||
|
||||
/* Get the groups this repo shared to. */
|
||||
repo_groups = seaf_repo_manager_get_groups_by_repo (mgr, repo_id, NULL);
|
||||
group_perms = seaf_repo_manager_get_group_perm_by_repo (mgr, 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 = repo_groups; p2 != NULL; p2 = p2->next) {
|
||||
repo_group_id = (int)(long)(p2->data);
|
||||
if (group_id == repo_group_id) {
|
||||
ret = TRUE;
|
||||
goto out;
|
||||
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 out;
|
||||
} else if (g_strcmp0(perm->permission, "r") == 0 &&
|
||||
!permission) {
|
||||
permission = perm->permission;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1858,11 +1967,14 @@ out:
|
||||
for (p1 = groups; p1 != NULL; p1 = p1->next)
|
||||
g_object_unref ((GObject *)p1->data);
|
||||
g_list_free (groups);
|
||||
g_list_free (repo_groups);
|
||||
return ret;
|
||||
for (p2 = group_perms; p2 != NULL; p2 = p2->next)
|
||||
g_free (p2->data);
|
||||
g_list_free (group_perms);
|
||||
|
||||
return g_strdup(permission);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
static char *
|
||||
check_org_repo_share_permission (SeafRepoManager *mgr,
|
||||
int org_id,
|
||||
const char *repo_id,
|
||||
@ -1870,48 +1982,68 @@ check_org_repo_share_permission (SeafRepoManager *mgr,
|
||||
{
|
||||
SearpcClient *rpc_client;
|
||||
GList *groups, *p1;
|
||||
GList *repo_groups, *p2;
|
||||
GList *group_perms, *p2;
|
||||
CcnetGroup *group;
|
||||
int group_id, repo_group_id;
|
||||
gboolean ret = FALSE;
|
||||
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 FALSE;
|
||||
return NULL;
|
||||
|
||||
if (!ccnet_org_user_exists (rpc_client, org_id, user_name)) {
|
||||
ccnet_rpc_client_free (rpc_client);
|
||||
return FALSE;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (seaf_repo_manager_is_org_inner_pub_repo (mgr, org_id, repo_id)) {
|
||||
ccnet_rpc_client_free (rpc_client);
|
||||
return TRUE;
|
||||
return g_strdup("rw");
|
||||
}
|
||||
|
||||
permission = seaf_share_manager_check_permission (seaf->share_mgr,
|
||||
repo_id,
|
||||
user_name);
|
||||
if (g_strcmp0(permission, "rw") == 0 || g_strcmp0(permission, "r") == 0) {
|
||||
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. */
|
||||
repo_groups = seaf_repo_manager_get_org_groups_by_repo (mgr,
|
||||
org_id,
|
||||
repo_id,
|
||||
NULL);
|
||||
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 = repo_groups; p2 != NULL; p2 = p2->next) {
|
||||
repo_group_id = (int)(long)(p2->data);
|
||||
if (group_id == repo_group_id) {
|
||||
ret = TRUE;
|
||||
goto out;
|
||||
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 out;
|
||||
} else if (g_strcmp0(perm->permission, "r") == 0 &&
|
||||
!permission) {
|
||||
permission = perm->permission;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1920,56 +2052,58 @@ out:
|
||||
for (p1 = groups; p1 != NULL; p1 = p1->next)
|
||||
g_object_unref ((GObject *)p1->data);
|
||||
g_list_free (groups);
|
||||
g_list_free (repo_groups);
|
||||
return ret;
|
||||
for (p2 = group_perms; p2 != NULL; p2 = p2->next)
|
||||
g_free (p2->data);
|
||||
g_list_free (group_perms);
|
||||
|
||||
return g_strdup(permission);
|
||||
}
|
||||
|
||||
/*
|
||||
* Comprehensive repo access permission checker.
|
||||
*
|
||||
* Returns read/write permission.
|
||||
*/
|
||||
int
|
||||
char *
|
||||
seaf_repo_manager_check_permission (SeafRepoManager *mgr,
|
||||
const char *repo_id,
|
||||
const char *user,
|
||||
GError **error)
|
||||
{
|
||||
char *owner;
|
||||
char *owner = NULL;
|
||||
int org_id;
|
||||
char *permission = NULL;
|
||||
|
||||
owner = seaf_repo_manager_get_repo_owner (mgr, repo_id);
|
||||
if (owner != NULL) {
|
||||
/* If the user is not owner, check share permission */
|
||||
if (strcmp (owner, user) != 0 &&
|
||||
!check_repo_share_permission (mgr, repo_id, user)) {
|
||||
g_free (owner);
|
||||
return -1;
|
||||
}
|
||||
if (strcmp (owner, user) == 0)
|
||||
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);
|
||||
return -1;
|
||||
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);
|
||||
g_free (owner);
|
||||
return -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (strcmp (owner, user) != 0 &&
|
||||
!check_org_repo_share_permission (mgr, org_id, repo_id, user)) {
|
||||
g_free (owner);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
if (strcmp (owner, user) == 0)
|
||||
permission = g_strdup("rw");
|
||||
else
|
||||
permission = check_org_repo_share_permission (mgr, org_id,
|
||||
repo_id, user);
|
||||
}
|
||||
|
||||
out:
|
||||
g_free (owner);
|
||||
return 0;
|
||||
return permission;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -343,6 +343,23 @@ seaf_repo_manager_get_groups_by_repo (SeafRepoManager *mgr,
|
||||
const char *repo_id,
|
||||
GError **error);
|
||||
|
||||
typedef struct GroupPerm {
|
||||
int group_id;
|
||||
char *permission;
|
||||
} GroupPerm;
|
||||
|
||||
GList *
|
||||
seaf_repo_manager_get_group_perm_by_repo (SeafRepoManager *mgr,
|
||||
const char *repo_id,
|
||||
GError **error);
|
||||
|
||||
int
|
||||
seaf_repo_manager_set_group_repo_perm (SeafRepoManager *mgr,
|
||||
const char *repo_id,
|
||||
int group_id,
|
||||
const char *permission,
|
||||
GError **error);
|
||||
|
||||
char *
|
||||
seaf_repo_manager_get_group_repo_owner (SeafRepoManager *mgr,
|
||||
const char *repo_id,
|
||||
@ -440,6 +457,20 @@ seaf_repo_manager_get_org_groups_by_repo (SeafRepoManager *mgr,
|
||||
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,
|
||||
@ -477,7 +508,7 @@ seaf_repo_manager_list_org_inner_pub_repos (SeafRepoManager *mgr, int org_id);
|
||||
* Comprehensive repo permission checker.
|
||||
* It checks if @user have permission to access @repo_id.
|
||||
*/
|
||||
int
|
||||
char *
|
||||
seaf_repo_manager_check_permission (SeafRepoManager *mgr,
|
||||
const char *repo_id,
|
||||
const char *user,
|
||||
|
@ -279,6 +279,11 @@ static void start_rpc_service (CcnetClient *client, int cloud_mode)
|
||||
"seafile_remove_share",
|
||||
searpc_signature_int__string_string_string());
|
||||
|
||||
searpc_server_register_function ("seafserv-threaded-rpcserver",
|
||||
seafile_set_share_permission,
|
||||
"set_share_permission",
|
||||
searpc_signature_int__string_string_string_string());
|
||||
|
||||
/* share repo to group */
|
||||
searpc_server_register_function ("seafserv-threaded-rpcserver",
|
||||
seafile_group_share_repo,
|
||||
@ -309,6 +314,11 @@ static void start_rpc_service (CcnetClient *client, int cloud_mode)
|
||||
seafile_remove_repo_group,
|
||||
"seafile_remove_repo_group",
|
||||
searpc_signature_int__int_string());
|
||||
|
||||
searpc_server_register_function ("seafserv-threaded-rpcserver",
|
||||
seafile_set_group_repo_permission,
|
||||
"set_group_repo_permission",
|
||||
searpc_signature_int__int_string_string());
|
||||
|
||||
/* branch and commit */
|
||||
searpc_server_register_function ("seafserv-threaded-rpcserver",
|
||||
@ -434,7 +444,7 @@ static void start_rpc_service (CcnetClient *client, int cloud_mode)
|
||||
searpc_server_register_function ("seafserv-threaded-rpcserver",
|
||||
seafile_check_permission,
|
||||
"check_permission",
|
||||
searpc_signature_int__string_string());
|
||||
searpc_signature_string__string_string());
|
||||
|
||||
if (!cloud_mode) {
|
||||
searpc_server_register_function ("seafserv-threaded-rpcserver",
|
||||
@ -508,7 +518,11 @@ static void start_rpc_service (CcnetClient *client, int cloud_mode)
|
||||
searpc_server_register_function ("seafserv-threaded-rpcserver",
|
||||
seafile_get_org_groups_by_repo,
|
||||
"get_org_groups_by_repo",
|
||||
searpc_signature_string__int_string());
|
||||
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",
|
||||
|
@ -68,12 +68,27 @@ seaf_share_manager_add_share (SeafShareManager *mgr, const char *repo_id,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
seaf_share_manager_set_permission (SeafShareManager *mgr, const char *repo_id,
|
||||
const char *from_email, const char *to_email,
|
||||
const char *permission)
|
||||
{
|
||||
char sql[512];
|
||||
|
||||
snprintf (sql, sizeof(sql),
|
||||
"UPDATE SharedRepo SET permission='%s' WHERE "
|
||||
"repo_id='%s' AND from_email='%s' AND to_email='%s'",
|
||||
permission, repo_id, from_email, to_email);
|
||||
return seaf_db_query (mgr->seaf->db, sql);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
collect_repos (SeafDBRow *row, void *data)
|
||||
{
|
||||
GList **p_repos = data;
|
||||
const char *repo_id;
|
||||
const char *email;
|
||||
const char *permission;
|
||||
SeafRepo *repo;
|
||||
ShareRepoInfo *shareRepoInfo;
|
||||
|
||||
@ -82,11 +97,13 @@ collect_repos (SeafDBRow *row, void *data)
|
||||
if (!repo) {
|
||||
return TRUE;
|
||||
}
|
||||
email = (const char *) seaf_db_row_get_column_text (row, 1);
|
||||
email = seaf_db_row_get_column_text (row, 1);
|
||||
permission = seaf_db_row_get_column_text (row, 2);
|
||||
|
||||
shareRepoInfo = g_new0 (ShareRepoInfo, 1);
|
||||
shareRepoInfo->email = g_strdup(email);
|
||||
shareRepoInfo->repo = repo;
|
||||
shareRepoInfo->permission = g_strdup(permission);
|
||||
|
||||
*p_repos = g_list_prepend (*p_repos, shareRepoInfo);
|
||||
|
||||
@ -102,10 +119,10 @@ seaf_share_manager_list_share_repos (SeafShareManager *mgr, const char *email,
|
||||
|
||||
if (start == -1 && limit == -1) {
|
||||
if (g_strcmp0 (type, "from_email") == 0) {
|
||||
snprintf (sql, sizeof(sql), "SELECT repo_id, to_email FROM "
|
||||
snprintf (sql, sizeof(sql), "SELECT repo_id, to_email, permission FROM "
|
||||
"SharedRepo WHERE from_email='%s'", email);
|
||||
} else if (g_strcmp0 (type, "to_email") == 0) {
|
||||
snprintf (sql, sizeof(sql), "SELECT repo_id, from_email FROM "
|
||||
snprintf (sql, sizeof(sql), "SELECT repo_id, from_email, permission FROM "
|
||||
"SharedRepo WHERE to_email='%s'", email);
|
||||
} else {
|
||||
/* should never reach here */
|
||||
@ -115,11 +132,13 @@ seaf_share_manager_list_share_repos (SeafShareManager *mgr, const char *email,
|
||||
}
|
||||
else {
|
||||
if (g_strcmp0 (type, "from_email") == 0) {
|
||||
snprintf (sql, sizeof(sql), "SELECT repo_id, to_email FROM "
|
||||
snprintf (sql, sizeof(sql),
|
||||
"SELECT repo_id, to_email, permission FROM "
|
||||
"SharedRepo WHERE from_email='%s' LIMIT %d, %d",
|
||||
email, start, limit);
|
||||
} else if (g_strcmp0 (type, "to_email") == 0) {
|
||||
snprintf (sql, sizeof(sql), "SELECT repo_id, from_email FROM "
|
||||
snprintf (sql, sizeof(sql),
|
||||
"SELECT repo_id, from_email, permission FROM "
|
||||
"SharedRepo WHERE to_email='%s' LIMIT %d, %d",
|
||||
email, start, limit);
|
||||
} else {
|
||||
@ -170,7 +189,7 @@ seaf_share_manager_remove_repo (SeafShareManager *mgr, const char *repo_id)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
char *
|
||||
seaf_share_manager_check_permission (SeafShareManager *mgr,
|
||||
const char *repo_id,
|
||||
const char *email)
|
||||
@ -178,10 +197,7 @@ seaf_share_manager_check_permission (SeafShareManager *mgr,
|
||||
char sql[512];
|
||||
|
||||
snprintf (sql, sizeof(sql),
|
||||
"SELECT repo_id FROM SharedRepo WHERE repo_id='%s' AND to_email='%s'",
|
||||
"SELECT permission FROM SharedRepo WHERE repo_id='%s' AND to_email='%s'",
|
||||
repo_id, email);
|
||||
if (seaf_db_check_for_existence (mgr->seaf->db, sql))
|
||||
return 0;
|
||||
|
||||
return -1;
|
||||
return seaf_db_get_string (mgr->seaf->db, sql);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ struct _SeafShareManager {
|
||||
struct _ShareRepoInfo {
|
||||
SeafRepo *repo;
|
||||
char *email;
|
||||
char *permission;
|
||||
// char email[100];
|
||||
};
|
||||
|
||||
@ -33,6 +34,11 @@ seaf_share_manager_add_share (SeafShareManager *mgr, const char *repo_id,
|
||||
const char *from_email, const char *to_email,
|
||||
const char *permission);
|
||||
|
||||
int
|
||||
seaf_share_manager_set_permission (SeafShareManager *mgr, const char *repo_id,
|
||||
const char *from_email, const char *to_email,
|
||||
const char *permission);
|
||||
|
||||
GList*
|
||||
seaf_share_manager_list_share_repos (SeafShareManager *mgr, const char *email,
|
||||
const char *type, int start, int limit);
|
||||
@ -45,7 +51,7 @@ seaf_share_manager_remove_share (SeafShareManager *mgr, const char *repo_id,
|
||||
int
|
||||
seaf_share_manager_remove_repo (SeafShareManager *mgr, const char *repo_id);
|
||||
|
||||
int
|
||||
char *
|
||||
seaf_share_manager_check_permission (SeafShareManager *mgr,
|
||||
const char *repo_id,
|
||||
const char *email);
|
||||
|
@ -32,7 +32,7 @@ while [ $# -ge 1 ]; do
|
||||
|
||||
gnome-terminal -e "${ccnet_server} -c ${conf2} -D ${debug} -f -"
|
||||
sleep 3
|
||||
gnome-terminal -e "${seaf_server} -c ${conf2} -d ${conf2}/seafile-data -D all -f -l -"
|
||||
gnome-terminal -e "${seaf_server} -c ${conf2} -d ${conf2}/seafile-data -D all -f -l - -C"
|
||||
sleep 3
|
||||
gnome-terminal -e "${seaf_monitor} -c ${conf2} -d ${conf2}/seafile-data -f -l -"
|
||||
;;
|
||||
|
Loading…
Reference in New Issue
Block a user