Skip to content

Commit

Permalink
Merge pull request #2515 from onaio/filter-out-deleted-xforms-project…
Browse files Browse the repository at this point in the history
…-viewset

Filter out soft-deleted xforms from project forms endpoint
  • Loading branch information
KipSigei authored Nov 23, 2023
2 parents 8639763 + 702791b commit 8cdb3b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions onadata/apps/api/tests/viewsets/test_project_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,25 @@ def test_project_get_deleted_form(self):
self.assertEqual(len(response.data.get("forms")), 0)
self.assertEqual(response.status_code, 200)

def test_xform_delete_project_forms_endpoint(self):
self._publish_xls_form_to_project()

view = ProjectViewSet.as_view({"get": "forms"})
request = self.factory.get("/", **self.extra)
response = view(request, pk=self.project.pk)

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 1)

# soft delete form
self.xform.soft_delete(user=self.user)

request = self.factory.get("/", **self.extra)
response = view(request, pk=self.project.pk)

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 0)

# pylint: disable=invalid-name
def test_none_empty_forms_and_dataview_properties_in_returned_json(self):
self._publish_xls_form_to_project()
Expand Down
2 changes: 1 addition & 1 deletion onadata/apps/api/viewsets/project_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def forms(self, request, **kwargs):

return Response(survey, status=status.HTTP_400_BAD_REQUEST)

xforms = XForm.objects.filter(project=project)
xforms = XForm.objects.filter(project=project, deleted_at__isnull=True)
serializer = XFormSerializer(xforms, context={"request": request}, many=True)

return Response(serializer.data)
Expand Down

0 comments on commit 8cdb3b3

Please sign in to comment.