From: Veronika Kabatova Date: Thu, 3 May 2018 10:55:16 +0000 (+0200) Subject: Explicitly distinguish between comments on patch and cover X-Git-Tag: v2.1.0-rc1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d6cc05082cf8fee84932e1e683382824e9b1c28;p=thirdparty%2Fpatchwork.git Explicitly distinguish between comments on patch and cover reverse() gets confused when the same view name and kwargs are passed to it, ignoring what endpoint the request originated from. Fix this by using different view names for cover letter and patch comments views. Reported-by: Daniel Axtens Signed-off-by: Veronika Kabatova Reviewed-by: Stephen Finucane --- diff --git a/patchwork/api/cover.py b/patchwork/api/cover.py index 7c80064c..99cf9e68 100644 --- a/patchwork/api/cover.py +++ b/patchwork/api/cover.py @@ -46,7 +46,7 @@ class CoverLetterListSerializer(BaseHyperlinkedModelSerializer): def get_comments(self, cover): return self.context.get('request').build_absolute_uri( - reverse('api-comment-list', kwargs={'pk': cover.id})) + reverse('api-cover-comment-list', kwargs={'pk': cover.id})) class Meta: model = CoverLetter diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py index d1931c01..028d6854 100644 --- a/patchwork/api/patch.py +++ b/patchwork/api/patch.py @@ -94,7 +94,7 @@ class PatchListSerializer(BaseHyperlinkedModelSerializer): def get_comments(self, patch): return self.context.get('request').build_absolute_uri( - reverse('api-comment-list', kwargs={'pk': patch.id})) + reverse('api-patch-comment-list', kwargs={'pk': patch.id})) def get_check(self, instance): return instance.combined_check_state diff --git a/patchwork/tests/api/test_comment.py b/patchwork/tests/api/test_comment.py index 9cad2add..f79ea469 100644 --- a/patchwork/tests/api/test_comment.py +++ b/patchwork/tests/api/test_comment.py @@ -46,7 +46,7 @@ class TestCoverComments(APITestCase): kwargs['version'] = version kwargs['pk'] = cover.id - return reverse('api-comment-list', kwargs=kwargs) + return reverse('api-cover-comment-list', kwargs=kwargs) def assertSerialized(self, comment_obj, comment_json): self.assertEqual(comment_obj.id, comment_json['id']) @@ -85,7 +85,7 @@ class TestPatchComments(APITestCase): kwargs['version'] = version kwargs['pk'] = patch.id - return reverse('api-comment-list', kwargs=kwargs) + return reverse('api-patch-comment-list', kwargs=kwargs) def assertSerialized(self, comment_obj, comment_json): self.assertEqual(comment_obj.id, comment_json['id']) diff --git a/patchwork/urls.py b/patchwork/urls.py index 1dc4ffc2..e90de6b2 100644 --- a/patchwork/urls.py +++ b/patchwork/urls.py @@ -283,10 +283,10 @@ if settings.ENABLE_REST_API: api_1_1_patterns = [ url(r'^patches/(?P[^/]+)/comments/$', api_comment_views.CommentList.as_view(), - name='api-comment-list'), + name='api-patch-comment-list'), url(r'^covers/(?P[^/]+)/comments/$', api_comment_views.CommentList.as_view(), - name='api-comment-list'), + name='api-cover-comment-list'), ] urlpatterns += [