Skip to content

Commit

Permalink
Merge pull request #974 from onaio/api-forms-handle-xlsformerror
Browse files Browse the repository at this point in the history
Handle XLSFormError exceptions on form parial_update
  • Loading branch information
ukanga authored Mar 29, 2017
2 parents b8fc914 + bda2ab0 commit f7936cf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
9 changes: 8 additions & 1 deletion onadata/apps/api/tests/viewsets/test_xform_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ def test_partial_update(self):
view = XFormViewSet.as_view({
'patch': 'partial_update'
})
title = u'مرحب'
title = u'Hello & World!'
description = 'DESCRIPTION'
data = {'public': True, 'description': description, 'title': title,
'downloadable': True}
Expand All @@ -1398,6 +1398,13 @@ def test_partial_update(self):

request = self.factory.patch('/', data=data, **self.extra)
response = view(request, pk=self.xform.id)
self.assertEqual(response.status_code, 400)

title = u'Hello and World!'
data['title'] = title
request = self.factory.patch('/', data=data, **self.extra)
response = view(request, pk=self.xform.id)
self.assertEqual(response.status_code, 200)

self.xform.reload()
self.assertTrue(self.xform.downloadable)
Expand Down
7 changes: 5 additions & 2 deletions onadata/apps/api/viewsets/xform_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,11 @@ def partial_update(self, request, *args, **kwargs):
'text_xls_form']) & set(request.data.keys()):
return _try_update_xlsform(request, self.object, owner)

return super(XFormViewSet, self).partial_update(request, *args,
**kwargs)
try:
return super(XFormViewSet, self).partial_update(request, *args,
**kwargs)
except XLSFormError as e:
raise ParseError(str(e))

@detail_route(methods=['DELETE', 'GET'])
def delete_async(self, request, *args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions onadata/libs/serializers/xform_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ def get_hash(self, obj):
if len(parts) > 2:
dataset_type = parts[0]
pk = parts[1]
xform = None
if dataset_type == 'xform':
xform = XForm.objects.filter(pk=pk)\
.only('last_submission_time').first()
Expand Down
7 changes: 4 additions & 3 deletions onadata/libs/utils/project_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def set_project_perms_to_xform(xform, project):
role_name = perm['role']
role = ROLES.get(role_name)

if user != xform.created_by:
role.add(user, xform)
else:
if user == xform.created_by:
OwnerRole.add(user, xform)
else:
if role:
role.add(user, xform)

0 comments on commit f7936cf

Please sign in to comment.