mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-01 23:46:53 +00:00
Update ccnet_api for multi-tier-groups and add test.
This commit is contained in:
@@ -822,6 +822,15 @@ class CcnetAPI(object):
|
||||
"""
|
||||
return ccnet_threaded_rpc.search_groups(group_patt, start, limit)
|
||||
|
||||
def get_top_groups(self):
|
||||
return ccnet_threaded_rpc.get_top_groups()
|
||||
|
||||
def get_child_groups(self, group_id):
|
||||
return ccnet_threaded_rpc.get_child_groups(group_id)
|
||||
|
||||
def get_ancestor_groups(self, group_id):
|
||||
return ccnet_threaded_rpc.get_ancestor_groups(group_id)
|
||||
|
||||
def search_ldapusers(self, keyword, start, limit):
|
||||
"""
|
||||
Search for users whose name contains @keyword directly from LDAP server.
|
||||
@@ -863,14 +872,14 @@ class CcnetAPI(object):
|
||||
return ccnet_threaded_rpc.get_superusers()
|
||||
|
||||
# group management
|
||||
def create_group(self, group_name, user_name, gtype=None):
|
||||
def create_group(self, group_name, user_name, gtype=None, parent_group_id=0):
|
||||
"""
|
||||
For CE, gtype is not used and should always be None.
|
||||
"""
|
||||
return ccnet_threaded_rpc.create_group(group_name, user_name, gtype)
|
||||
return ccnet_threaded_rpc.create_group(group_name, user_name, gtype, parent_group_id)
|
||||
|
||||
def create_org_group(self, org_id, group_name, user_name):
|
||||
return ccnet_threaded_rpc.create_org_group(org_id, group_name, user_name)
|
||||
def create_org_group(self, org_id, group_name, user_name, parent_group_id=0):
|
||||
return ccnet_threaded_rpc.create_org_group(org_id, group_name, user_name, parent_group_id)
|
||||
|
||||
def remove_group(self, group_id):
|
||||
"""
|
||||
@@ -908,12 +917,12 @@ class CcnetAPI(object):
|
||||
def quit_group(self, group_id, user_name):
|
||||
return ccnet_threaded_rpc.quit_group(group_id, user_name)
|
||||
|
||||
def get_groups(self, user_name):
|
||||
def get_groups(self, user_name, return_ancestors=False):
|
||||
"""
|
||||
Get all groups the user belongs to.
|
||||
Return: a list of Group objects (ccnet/lib/ccnetobj.vala)
|
||||
"""
|
||||
return ccnet_threaded_rpc.get_groups(user_name)
|
||||
return ccnet_threaded_rpc.get_groups(user_name, 1 if return_ancestors else 0)
|
||||
|
||||
def get_all_groups(self, start, limit, source=None):
|
||||
"""
|
||||
@@ -1009,6 +1018,9 @@ class CcnetAPI(object):
|
||||
"""
|
||||
return ccnet_threaded_rpc.get_org_groups(org_id, start, limit)
|
||||
|
||||
def get_org_top_groups(self, org_id):
|
||||
return ccnet_threaded_rpc.get_org_top_groups(org_id)
|
||||
|
||||
def org_user_exists(self, org_id, email):
|
||||
"""
|
||||
Return non-zero if True, otherwise 0.
|
||||
|
66
tests/test_groups.py
Normal file
66
tests/test_groups.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import pytest
|
||||
from seaserv import seafile_api as api
|
||||
from seaserv import ccnet_api
|
||||
|
||||
from tests.config import USER, USER2
|
||||
|
||||
def test_multi_tier_groups(repo):
|
||||
id1 = ccnet_api.create_group('group1', USER, parent_group_id=-1)
|
||||
id2 = ccnet_api.create_group('group2', USER2, parent_group_id = id1)
|
||||
id3 = ccnet_api.create_group('group3', USER, parent_group_id = id1)
|
||||
id4 = ccnet_api.create_group('group4', USER2, parent_group_id = id3)
|
||||
id5 = ccnet_api.create_group('group5', USER2, parent_group_id = 0)
|
||||
assert id1 != -1 and id2 != -1 and id3 != -1 and id4 != -1
|
||||
|
||||
group1 = ccnet_api.get_group(id1)
|
||||
group2 = ccnet_api.get_group(id2)
|
||||
group3 = ccnet_api.get_group(id3)
|
||||
group4 = ccnet_api.get_group(id4)
|
||||
assert group1.parent_group_id == -1
|
||||
assert group2.parent_group_id == id1
|
||||
assert group3.parent_group_id == id1
|
||||
assert group4.parent_group_id == id3
|
||||
|
||||
ances_order = [id5, id4, id3, id2, id1]
|
||||
user2_groups_with_ancestors = ccnet_api.get_groups (USER2, return_ancestors = True)
|
||||
assert len(user2_groups_with_ancestors) == 5
|
||||
i = 0
|
||||
for g in user2_groups_with_ancestors:
|
||||
assert g.id == ances_order[i]
|
||||
i = i + 1
|
||||
|
||||
order = [id5, id4, id2]
|
||||
i = 0
|
||||
user2_groups = ccnet_api.get_groups (USER2)
|
||||
assert len(user2_groups) == 3
|
||||
for g in user2_groups:
|
||||
assert g.id == order[i]
|
||||
i = i + 1
|
||||
|
||||
top_groups = ccnet_api.get_top_groups()
|
||||
assert len(top_groups) == 1
|
||||
for g in top_groups:
|
||||
assert g.parent_group_id == -1
|
||||
|
||||
child_order = [id2, id3]
|
||||
i = 0
|
||||
id1_children = ccnet_api.get_child_groups(id1)
|
||||
assert len(id1_children) == 2
|
||||
for g in id1_children:
|
||||
assert g.id == child_order[i]
|
||||
i = i + 1
|
||||
|
||||
group4_order = [id1, id3, id4]
|
||||
i = 0
|
||||
group4_ancestors = ccnet_api.get_ancestor_groups(id4)
|
||||
assert len(group4_ancestors) == 3
|
||||
for g in group4_ancestors:
|
||||
assert g.id == group4_order[i]
|
||||
i = i + 1
|
||||
|
||||
rm5 = ccnet_api.remove_group(id5)
|
||||
rm4 = ccnet_api.remove_group(id4)
|
||||
rm3 = ccnet_api.remove_group(id3)
|
||||
rm2 = ccnet_api.remove_group(id2)
|
||||
rm1 = ccnet_api.remove_group(id1)
|
||||
assert rm5 == 0 and rm4 == 0 and rm3 == 0 and rm2 == 0 and rm1 == 0
|
Reference in New Issue
Block a user