Skip to content

Commit

Permalink
Apply requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
noliveleger committed Oct 3, 2024
1 parent b1d5000 commit 41c6b73
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 13 deletions.
4 changes: 2 additions & 2 deletions kobo/apps/openrosa/apps/api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ def has_object_permission(self, request, view, obj):
except KeyError:
pass
else:
# Deleting submissions is not allowed anymore with KoboCAT API
# Deleting submissions is not allowed with KoboCAT API
if view.action == 'bulk_delete':
raise LegacyAPIException

return user.has_perms(required_perms, obj)

# Deleting submissions in not allowed anymore with KoboCAT API
# Deleting submissions is not allowed with KoboCAT API
if view.action == 'destroy':
raise LegacyAPIException

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ def publish_xls_form(
# during deployment. Thus, this method will create the XForm object directly
# without an API call except if `use_api` is True.

# In unit tests, if we need to test the result of the (KoboCAT API),
# Some unit tests still need to test the result of API `v1`
# (i.e.: KoboCAT API). For example, to ensure project creation is
# not allowed anymore.
if not data:
data = {
'owner': self.user.username,
Expand Down
9 changes: 4 additions & 5 deletions kobo/apps/openrosa/apps/api/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
default_kobocat_storage as default_storage,
)
from kpi.views.v2.paired_data import (
PairedDataViewset,
OpenRosaDynamicDataAttachmentViewset,
SubmissionXMLRenderer,
XMLExternalDataPermission,
)
Expand Down Expand Up @@ -170,11 +170,10 @@ def get_media_file_response(
args = resolver_match.args
kwargs = resolver_match.kwargs

paired_data_viewset = PairedDataViewset.as_view({'get': 'external'})
paired_data_viewset = OpenRosaDynamicDataAttachmentViewset.as_view(
{'get': 'external'}
)
django_http_request = request._request
paired_data_viewset.cls.permission_classes = [XMLExternalDataPermission]
paired_data_viewset.cls.renderer_classes = [SubmissionXMLRenderer]
paired_data_viewset.cls.filter_backends = []
return paired_data_viewset(request=django_http_request, *args, **kwargs)


Expand Down
2 changes: 1 addition & 1 deletion kobo/apps/openrosa/apps/api/viewsets/xform_list_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def _is_metadata_expired(obj: MetaData, request: Request) -> bool:

timedelta = timezone.now() - obj.date_modified
if timedelta.total_seconds() > settings.PAIRED_DATA_EXPIRATION:
# Force external xml regeneration
# Force external XML regeneration
get_media_file_response(obj, request)

# We update the modification time here to avoid requesting that KPI
Expand Down
3 changes: 0 additions & 3 deletions kobo/apps/openrosa/apps/api/viewsets/xform_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,6 @@ def create(self, request, *args, **kwargs):

return Response(survey, status=status.HTTP_400_BAD_REQUEST)

def get_queryset(self):
return super().get_queryset()

def update(self, request, pk, *args, **kwargs):
if 'xls_file' in request.FILES:
# A new XLSForm has been uploaded and will replace the existing
Expand Down
7 changes: 7 additions & 0 deletions kobo/apps/openrosa/apps/main/tests/test_past_bugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ def test_buggy_files(self):
)
assert message == str(e)

def test_erics_files(self):
for name in [
'battery_life.xls',
'Enumerator_Training_Practice_Survey.xls',
]:
self._publish_xls_file(os.path.join('fixtures', 'bug_fixes', name))


class TestSubmissionBugs(TestBase):

Expand Down
14 changes: 13 additions & 1 deletion kpi/views/v2/paired_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def external(self, request, paired_data_uid, **kwargs):
file_type=AssetFile.PAIRED_DATA,
user=self.asset.owner,
)
# When asset file is new, we consider its content as expired to
# When the asset file is new, we consider its content as expired to
# force its creation below
has_expired = True
else:
Expand Down Expand Up @@ -336,3 +336,15 @@ def get_serializer_context(self):
source__names[record['uid']] = record['name']
context_['source__names'] = source__names
return context_


class OpenRosaDynamicDataAttachmentViewset(PairedDataViewset):
"""
Only specific to OpenRosa manifest when projects are linked with DDA.
Enforce permission and renderer classes at the class level instead to be
sure they are taken into account while calling `viewset.as_view()`
"""

permission_classes = [XMLExternalDataPermission]
renderer_classes = [SubmissionXMLRenderer]
filter_backends = []

0 comments on commit 41c6b73

Please sign in to comment.