From facc6a4d807249c60b6a14634f6001c60902e5b9 Mon Sep 17 00:00:00 2001 From: Davis Raymond Muro Date: Fri, 17 Apr 2020 14:23:42 +0300 Subject: [PATCH] Modify Enketo submission and formList urls Modify Enketo submission and formList urls by changing the name of the "form_pk" arguement to "xform_pk" --- onadata/apps/api/tests/viewsets/test_xform_list_viewset.py | 6 +++--- onadata/apps/api/viewsets/xform_list_viewset.py | 7 ++++--- onadata/apps/main/urls.py | 4 ++-- onadata/libs/filters.py | 4 ---- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/onadata/apps/api/tests/viewsets/test_xform_list_viewset.py b/onadata/apps/api/tests/viewsets/test_xform_list_viewset.py index bf8dca52ae..3a45e41682 100644 --- a/onadata/apps/api/tests/viewsets/test_xform_list_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_xform_list_viewset.py @@ -1005,7 +1005,7 @@ def test_retrieve_form_using_pk(self): request = self.factory.get( f'/enketo/{self.xform.pk}/formList') response = self.view( - request, form_pk=self.xform.pk) + request, xform_pk=self.xform.pk) self.assertEqual(response.status_code, 401) # Set require auth to false for form owner @@ -1030,7 +1030,7 @@ def test_retrieve_form_using_pk(self): f'/enketo/{self.xform.pk}/formList') request.META.update(auth(request.META, response)) response = self.view( - request, form_pk=self.xform.pk) + request, xform_pk=self.xform.pk) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 1) self.assertEqual( @@ -1041,7 +1041,7 @@ def test_retrieve_form_using_pk(self): request = self.factory.get( f'/enketo/{self.xform.pk}/formList') response = self.view( - request, form_pk=self.xform.pk) + request, xform_pk=self.xform.pk) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 1) self.assertEqual( diff --git a/onadata/apps/api/viewsets/xform_list_viewset.py b/onadata/apps/api/viewsets/xform_list_viewset.py index 1568b3cd66..8ede9b6500 100644 --- a/onadata/apps/api/viewsets/xform_list_viewset.py +++ b/onadata/apps/api/viewsets/xform_list_viewset.py @@ -73,7 +73,7 @@ def get_renderers(self): def filter_queryset(self, queryset): username = self.kwargs.get('username') - form_pk = self.kwargs.get('form_pk') + form_pk = self.kwargs.get('xform_pk') if (not username and not form_pk) and \ self.request.user.is_anonymous: # raises a permission denied exception, forces authentication @@ -84,8 +84,9 @@ def filter_queryset(self, queryset): profile = get_object_or_404( UserProfile, user__username=username) elif form_pk: - form = get_object_or_404(XForm, pk=form_pk) - profile = form.user.profile + queryset = queryset.filter(pk=form_pk) + if queryset.first(): + profile = queryset.first().user.profile if profile: if profile.require_auth and self.request.user.is_anonymous: diff --git a/onadata/apps/main/urls.py b/onadata/apps/main/urls.py index ce104186d1..5859a22835 100644 --- a/onadata/apps/main/urls.py +++ b/onadata/apps/main/urls.py @@ -224,7 +224,7 @@ re_path(r'^(?P\w+)/formList$', XFormListViewSet.as_view({'get': 'list', 'head': 'list'}), name='form-list'), - re_path(r'^enketo/(?P\w+)/formList$', + re_path(r'^enketo/(?P\w+)/formList$', XFormListViewSet.as_view({'get': 'list', 'head': 'list'}), name='form-list'), re_path(r'^(?P\w+)/(?P\d+)/formList$', @@ -258,7 +258,7 @@ re_path(r'^(?P\w+)/submission$', XFormSubmissionViewSet.as_view({'post': 'create', 'head': 'create'}), name='submissions'), - re_path(r'^enketo/(?P\w+)/submission$', + re_path(r'^enketo/(?P\w+)/submission$', XFormSubmissionViewSet.as_view({'post': 'create', 'head': 'create'}), name='submissions'), re_path(r'^(?P\w+)/(?P\d+)/submission$', diff --git a/onadata/libs/filters.py b/onadata/libs/filters.py index cae1389db2..742946dbe2 100644 --- a/onadata/libs/filters.py +++ b/onadata/libs/filters.py @@ -25,10 +25,6 @@ def filter_queryset(self, request, queryset, view): view.lookup_field, view.kwargs.get('xform_pk')) lookup_field = view.lookup_field - if view.kwargs.get('form_pk'): - form_id = view.kwargs.get('form_pk') - lookup_field = 'pk' - queryset = queryset.filter(deleted_at=None) if request.user.is_anonymous: return queryset