Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deleted_by serializer field for Dataviews #2721

Merged
merged 7 commits into from
Oct 23, 2024
40 changes: 40 additions & 0 deletions onadata/apps/api/tests/viewsets/test_dataview_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,16 @@ def test_list_dataview(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 2)

# delete DataView and check that we don't get it in response
dataview = DataView.objects.get(name="My DataView2")
deleted_dataview_id = dataview.id
dataview.soft_delete(user=self.user)
response = view(request)

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 1)
self.assertNotEqual(response.data[0]["dataviewid"], deleted_dataview_id)

anon_request = request = self.factory.get("/")
anon_response = view(anon_request)
self.assertEqual(anon_response.status_code, 401)
Expand All @@ -477,6 +487,36 @@ def test_get_dataview_no_perms(self):

self.assertEqual(response.status_code, 200)

def test_can_not_get_deleted_dataview(self):
data = {
"name": "Agriculture Dataview",
"xform": f"http://testserver/api/v1/forms/{self.xform.pk}",
"project": f"http://testserver/api/v1/projects/{self.project.pk}",
"columns": '["name", "age", "gender"]',
"query": '[{"column":"age","filter":">","value":"20"},'
'{"column":"age","filter":"<","value":"50"}]',
}

self._create_dataview(data=data)

view = DataViewViewSet.as_view(
{
"get": "retrieve",
}
)

request = self.factory.get("/", **self.extra)
response = view(request, pk=self.data_view.pk)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["dataviewid"], self.data_view.pk)

dataview = DataView.objects.get(id=response.data["dataviewid"])
dataview.soft_delete(user=self.user)

request = self.factory.get("/", **self.extra)
response = view(request, pk=self.data_view.pk)
self.assertEqual(response.status_code, 404)

# pylint: disable=invalid-name
def test_dataview_data_filter_integer(self):
data = {
Expand Down
2 changes: 1 addition & 1 deletion onadata/apps/api/viewsets/dataview_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class DataViewViewSet(
A simple ViewSet for viewing and editing DataViews.
"""

queryset = DataView.objects.select_related()
queryset = DataView.objects.filter(deleted_at__isnull=True).select_related()
serializer_class = DataViewSerializer
permission_classes = [DataViewViewsetPermissions]
lookup_field = "pk"
Expand Down
2 changes: 0 additions & 2 deletions onadata/libs/serializers/dataview_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ class Meta:
"has_hxl_support",
"url",
"date_created",
"deleted_at",
"deleted_by",
)
validators = [
serializers.UniqueTogetherValidator(
Expand Down