1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-03 16:10:26 +00:00

[api2] Fix group repos

This commit is contained in:
zhengxie
2015-04-24 13:35:45 +08:00
parent 527e3274b4
commit e5c5719ea7
3 changed files with 26 additions and 9 deletions

View File

@@ -3110,15 +3110,14 @@ class GroupRepos(APIView):
repo = seafile_api.get_repo(repo_id)
seafile_api.set_group_repo(repo.id, group.id, username, permission)
calculate_repos_last_modify([repo])
group_repo = {
"id": repo.id,
"name": repo.name,
"desc": repo.desc,
"size": repo.size,
"size_formatted": filesizeformat(repo.size),
"mtime": repo.latest_modify,
"mtime_relative": translate_seahub_time(repo.latest_modify),
"mtime": repo.last_modified,
"mtime_relative": translate_seahub_time(repo.last_modified),
"encrypted": repo.encrypted,
"permission": 'rw', # Always have read-write permission to owned repo
"owner": username,
@@ -3147,17 +3146,21 @@ class GroupRepos(APIView):
"desc": r.desc,
"size": r.size,
"size_formatted": filesizeformat(r.size),
"mtime": r.latest_modify,
"mtime_relative": translate_seahub_time(r.latest_modify),
"mtime": r.last_modified,
"mtime_relative": translate_seahub_time(r.last_modified),
"encrypted": r.encrypted,
"permission": check_permission(r.id, username),
"permission": r.permission,
"owner": r.user,
"owner_nickname": email2nickname(r.user),
"share_from_me": True if username == r.user else False,
}
repos_json.append(repo)
return Response({"is_staff": group.is_staff, "repos": repos_json})
req_from = request.GET.get('from', "")
if req_from == 'web':
return Response({"is_staff": group.is_staff, "repos": repos_json})
else:
return Response(repos_json)
class GroupRepo(APIView):
authentication_classes = (TokenAuthentication, SessionAuthentication)

View File

@@ -11,7 +11,7 @@ define([
comparator: -'mtime',
url: function() {
return Common.getUrl({name: 'group_repos', group_id: this.group_id});
return Common.getUrl({name: 'group_repos', group_id: this.group_id})+'?from=web';
},
parse: function(data) {

View File

@@ -18,7 +18,13 @@ class GroupRepoTest(ApiTestBase):
resp = self.create_group_repo(group.group_id)
assert resp.status_code == 200
assert len(resp.json()) == 9
resp_json = resp.json()
assert len(resp_json['id']) == 36
assert resp_json['name'] == 'grepo-test'
assert resp_json['size'] >= 0
assert resp_json['mtime'] > 0
assert resp_json['permission'] == 'rw'
assert '</time>' in resp_json['mtime_relative']
def test_add_with_wrong_perm(self):
with self.get_tmp_group() as group:
@@ -36,6 +42,14 @@ class GroupRepoTest(ApiTestBase):
assert resp.status_code == 200
assert len(resp.json()) == 1
resp_repo = resp.json()[0]
assert len(resp_repo['id']) == 36
assert resp_repo['name'] == 'grepo-test'
assert resp_repo['size'] >= 0
assert resp_repo['mtime'] > 0
assert resp_repo['permission'] in ('r', 'rw')
assert '</time>' in resp_repo['mtime_relative']
def test_can_delete(self):
with self.get_tmp_group() as group:
resp = self.create_group_repo(group.group_id)