mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-01 15:09:14 +00:00
Fix comment author issue
This commit is contained in:
@@ -37,7 +37,7 @@ class FileCommentView(APIView):
|
|||||||
avatar_size = AVATAR_DEFAULT_SIZE
|
avatar_size = AVATAR_DEFAULT_SIZE
|
||||||
|
|
||||||
comment = o.to_dict()
|
comment = o.to_dict()
|
||||||
comment.update(user_to_dict(request.user.username, request=request,
|
comment.update(user_to_dict(o.author, request=request,
|
||||||
avatar_size=avatar_size))
|
avatar_size=avatar_size))
|
||||||
|
|
||||||
return Response(comment)
|
return Response(comment)
|
||||||
|
@@ -39,7 +39,7 @@ class FileCommentsView(APIView):
|
|||||||
comments = []
|
comments = []
|
||||||
for o in FileComment.objects.get_by_file_path(repo_id, path):
|
for o in FileComment.objects.get_by_file_path(repo_id, path):
|
||||||
comment = o.to_dict()
|
comment = o.to_dict()
|
||||||
comment.update(user_to_dict(request.user.username, request=request,
|
comment.update(user_to_dict(o.author, request=request,
|
||||||
avatar_size=avatar_size))
|
avatar_size=avatar_size))
|
||||||
comments.append(comment)
|
comments.append(comment)
|
||||||
|
|
||||||
|
@@ -7,16 +7,18 @@ from seahub.test_utils import BaseTestCase
|
|||||||
|
|
||||||
class FileCommentTest(BaseTestCase):
|
class FileCommentTest(BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.login_as(self.user)
|
self.tmp_user = self.create_user()
|
||||||
|
|
||||||
o = FileComment.objects.add_by_file_path(repo_id=self.repo.id,
|
o = FileComment.objects.add_by_file_path(repo_id=self.repo.id,
|
||||||
file_path=self.file,
|
file_path=self.file,
|
||||||
author=self.user.username,
|
author=self.tmp_user.username,
|
||||||
comment='test comment')
|
comment='test comment')
|
||||||
|
self.login_as(self.user)
|
||||||
|
|
||||||
self.endpoint = reverse('api2-file-comment', args=[self.repo.id, o.pk]) + '?p=' + self.file
|
self.endpoint = reverse('api2-file-comment', args=[self.repo.id, o.pk]) + '?p=' + self.file
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.remove_repo()
|
self.remove_repo()
|
||||||
|
self.remove_user(self.tmp_user.email)
|
||||||
|
|
||||||
def test_can_get(self):
|
def test_can_get(self):
|
||||||
resp = self.client.get(self.endpoint)
|
resp = self.client.get(self.endpoint)
|
||||||
@@ -25,6 +27,7 @@ class FileCommentTest(BaseTestCase):
|
|||||||
json_resp = json.loads(resp.content)
|
json_resp = json.loads(resp.content)
|
||||||
assert json_resp['parent_path'] == '/'
|
assert json_resp['parent_path'] == '/'
|
||||||
assert json_resp['item_name'] == 'test.txt'
|
assert json_resp['item_name'] == 'test.txt'
|
||||||
|
assert json_resp['user_email'] == self.tmp_user.email
|
||||||
assert 'avatars' in json_resp['avatar_url']
|
assert 'avatars' in json_resp['avatar_url']
|
||||||
|
|
||||||
def test_can_get_with_avatar_size(self):
|
def test_can_get_with_avatar_size(self):
|
||||||
@@ -34,6 +37,7 @@ class FileCommentTest(BaseTestCase):
|
|||||||
json_resp = json.loads(resp.content)
|
json_resp = json.loads(resp.content)
|
||||||
assert json_resp['parent_path'] == '/'
|
assert json_resp['parent_path'] == '/'
|
||||||
assert json_resp['item_name'] == 'test.txt'
|
assert json_resp['item_name'] == 'test.txt'
|
||||||
|
assert json_resp['user_email'] == self.tmp_user.email
|
||||||
assert 'avatars' in json_resp['avatar_url']
|
assert 'avatars' in json_resp['avatar_url']
|
||||||
|
|
||||||
def test_can_delete(self):
|
def test_can_delete(self):
|
||||||
|
@@ -7,16 +7,19 @@ from seahub.test_utils import BaseTestCase
|
|||||||
|
|
||||||
class FileCommentsTest(BaseTestCase):
|
class FileCommentsTest(BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
self.tmp_user = self.create_user()
|
||||||
|
|
||||||
self.login_as(self.user)
|
self.login_as(self.user)
|
||||||
self.endpoint = reverse('api2-file-comments', args=[self.repo.id]) + '?p=' + self.file
|
self.endpoint = reverse('api2-file-comments', args=[self.repo.id]) + '?p=' + self.file
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.remove_repo()
|
self.remove_repo()
|
||||||
|
self.remove_user(self.tmp_user.email)
|
||||||
|
|
||||||
def test_can_list(self):
|
def test_can_list(self):
|
||||||
o = FileComment.objects.add_by_file_path(repo_id=self.repo.id,
|
o = FileComment.objects.add_by_file_path(repo_id=self.repo.id,
|
||||||
file_path=self.file,
|
file_path=self.file,
|
||||||
author=self.user.username,
|
author=self.tmp_user.username,
|
||||||
comment='test comment')
|
comment='test comment')
|
||||||
resp = self.client.get(self.endpoint)
|
resp = self.client.get(self.endpoint)
|
||||||
self.assertEqual(200, resp.status_code)
|
self.assertEqual(200, resp.status_code)
|
||||||
@@ -24,12 +27,13 @@ class FileCommentsTest(BaseTestCase):
|
|||||||
json_resp = json.loads(resp.content)
|
json_resp = json.loads(resp.content)
|
||||||
assert len(json_resp['comments']) == 1
|
assert len(json_resp['comments']) == 1
|
||||||
assert json_resp['comments'][0]['comment'] == o.comment
|
assert json_resp['comments'][0]['comment'] == o.comment
|
||||||
|
assert json_resp['comments'][0]['user_email'] == self.tmp_user.email
|
||||||
assert 'avatars' in json_resp['comments'][0]['avatar_url']
|
assert 'avatars' in json_resp['comments'][0]['avatar_url']
|
||||||
|
|
||||||
def test_can_list_with_avatar_size(self):
|
def test_can_list_with_avatar_size(self):
|
||||||
o = FileComment.objects.add_by_file_path(repo_id=self.repo.id,
|
o = FileComment.objects.add_by_file_path(repo_id=self.repo.id,
|
||||||
file_path=self.file,
|
file_path=self.file,
|
||||||
author=self.user.username,
|
author=self.tmp_user.username,
|
||||||
comment='test comment')
|
comment='test comment')
|
||||||
resp = self.client.get(self.endpoint + '&avatar_size=20')
|
resp = self.client.get(self.endpoint + '&avatar_size=20')
|
||||||
self.assertEqual(200, resp.status_code)
|
self.assertEqual(200, resp.status_code)
|
||||||
@@ -37,6 +41,7 @@ class FileCommentsTest(BaseTestCase):
|
|||||||
json_resp = json.loads(resp.content)
|
json_resp = json.loads(resp.content)
|
||||||
assert len(json_resp['comments']) == 1
|
assert len(json_resp['comments']) == 1
|
||||||
assert json_resp['comments'][0]['comment'] == o.comment
|
assert json_resp['comments'][0]['comment'] == o.comment
|
||||||
|
assert json_resp['comments'][0]['user_email'] == self.tmp_user.email
|
||||||
assert 'avatars' in json_resp['comments'][0]['avatar_url']
|
assert 'avatars' in json_resp['comments'][0]['avatar_url']
|
||||||
|
|
||||||
def test_can_post(self):
|
def test_can_post(self):
|
||||||
|
Reference in New Issue
Block a user