mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-01 23:20:51 +00:00
[api] Fix group repos
This commit is contained in:
@@ -3119,7 +3119,7 @@ class GroupRepos(APIView):
|
|||||||
"mtime": repo.last_modified,
|
"mtime": repo.last_modified,
|
||||||
"mtime_relative": translate_seahub_time(repo.last_modified),
|
"mtime_relative": translate_seahub_time(repo.last_modified),
|
||||||
"encrypted": repo.encrypted,
|
"encrypted": repo.encrypted,
|
||||||
"permission": 'rw', # Always have read-write permission to owned repo
|
"permission": permission,
|
||||||
"owner": username,
|
"owner": username,
|
||||||
"owner_nickname": email2nickname(username),
|
"owner_nickname": email2nickname(username),
|
||||||
"share_from_me": True,
|
"share_from_me": True,
|
||||||
@@ -3136,6 +3136,7 @@ class GroupRepos(APIView):
|
|||||||
else:
|
else:
|
||||||
repos = seafile_api.get_repos_by_group(group.id)
|
repos = seafile_api.get_repos_by_group(group.id)
|
||||||
|
|
||||||
|
repos.sort(lambda x, y: cmp(y.last_modified, x.last_modified))
|
||||||
group.is_staff = is_group_staff(group, request.user)
|
group.is_staff = is_group_staff(group, request.user)
|
||||||
|
|
||||||
repos_json = []
|
repos_json = []
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
import time
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
|
||||||
from tests.api.apitestbase import ApiTestBase
|
from tests.api.apitestbase import ApiTestBase
|
||||||
@@ -15,7 +16,7 @@ class GroupRepoTest(ApiTestBase):
|
|||||||
|
|
||||||
def test_can_add(self):
|
def test_can_add(self):
|
||||||
with self.get_tmp_group() as group:
|
with self.get_tmp_group() as group:
|
||||||
resp = self.create_group_repo(group.group_id)
|
resp = self.create_group_repo(group.group_id, permission='rw')
|
||||||
|
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
resp_json = resp.json()
|
resp_json = resp.json()
|
||||||
@@ -26,6 +27,14 @@ class GroupRepoTest(ApiTestBase):
|
|||||||
assert resp_json['permission'] == 'rw'
|
assert resp_json['permission'] == 'rw'
|
||||||
assert '</time>' in resp_json['mtime_relative']
|
assert '</time>' in resp_json['mtime_relative']
|
||||||
|
|
||||||
|
def test_can_add_read_only(self):
|
||||||
|
with self.get_tmp_group() as group:
|
||||||
|
resp = self.create_group_repo(group.group_id, permission='r')
|
||||||
|
|
||||||
|
assert resp.status_code == 200
|
||||||
|
resp_json = resp.json()
|
||||||
|
assert resp_json['permission'] == 'r'
|
||||||
|
|
||||||
def test_add_with_wrong_perm(self):
|
def test_add_with_wrong_perm(self):
|
||||||
with self.get_tmp_group() as group:
|
with self.get_tmp_group() as group:
|
||||||
resp = self.create_group_repo(group.group_id, permission='rr')
|
resp = self.create_group_repo(group.group_id, permission='rr')
|
||||||
@@ -50,6 +59,23 @@ class GroupRepoTest(ApiTestBase):
|
|||||||
assert resp_repo['permission'] in ('r', 'rw')
|
assert resp_repo['permission'] in ('r', 'rw')
|
||||||
assert '</time>' in resp_repo['mtime_relative']
|
assert '</time>' in resp_repo['mtime_relative']
|
||||||
|
|
||||||
|
def test_order_by_mtime(self):
|
||||||
|
with self.get_tmp_group() as group:
|
||||||
|
self.create_group_repo(group.group_id)
|
||||||
|
time.sleep(1)
|
||||||
|
self.create_group_repo(group.group_id)
|
||||||
|
time.sleep(1)
|
||||||
|
self.create_group_repo(group.group_id)
|
||||||
|
|
||||||
|
path = apiurl(reverse("api2-grouprepos", args=[group.group_id]))
|
||||||
|
resp = self.get(path)
|
||||||
|
|
||||||
|
assert resp.status_code == 200
|
||||||
|
assert len(resp.json()) == 3
|
||||||
|
|
||||||
|
assert (resp.json()[0]['mtime'] > resp.json()[1]['mtime'] and
|
||||||
|
resp.json()[1]['mtime'] > resp.json()[2]['mtime'] )
|
||||||
|
|
||||||
def test_can_delete(self):
|
def test_can_delete(self):
|
||||||
with self.get_tmp_group() as group:
|
with self.get_tmp_group() as group:
|
||||||
resp = self.create_group_repo(group.group_id)
|
resp = self.create_group_repo(group.group_id)
|
||||||
|
Reference in New Issue
Block a user