Skip to content

Commit

Permalink
Merge pull request #36 from galv-team/fix-upload
Browse files Browse the repository at this point in the history
fix: upload bugs
  • Loading branch information
mjaquiery authored Sep 10, 2024
2 parents d467f44 + f224df9 commit bdc6b19
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend_django/config/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Build paths inside the project like this: BASE_DIR / 'subdir'.
import os

API_VERSION = "2.4.0"
API_VERSION = "2.4.1"

try:
USER_ACTIVATION_TOKEN_EXPIRY_S = int(os.environ.get("DJANGO_USER_ACTIVATION_TOKEN_EXPIRY_S"))
Expand Down
2 changes: 1 addition & 1 deletion backend_django/galv/serializers/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,7 @@ def validate_uploader(self, value):
raise ValidationError("You may not change the uploader of a File")
if value != user and not value.is_superuser:
raise ValidationError("You may only create Files for yourself")
if len(self.context['request'].user_auth_details.team_ids) == 0:
if len(get_user_auth_details(self.context['request']).team_ids) == 0:
raise ValidationError("You must be a member of a team to create Files")
return value

Expand Down
9 changes: 9 additions & 0 deletions backend_django/galv/tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ def get_upload_data(user_id):
response = self.client.post(reverse(f'{self.stub}-list'), data=data, format='multipart')
assert_response_property(self, response, self.assertEqual, response.status_code, details['code'])

with self.subTest("JSON not allowed"):
with tempfile.TemporaryFile() as f:
f.write(b"ElapsedTime_s,Current_A,Voltage_V\n1,2,3\n2,2,3\n3,2,3\n4,2,3\n5,2,3\n6,2,3\n7,2,3\n8,2,3\n9,2,3\n10,2,3\n11,3,3\n")
f.seek(0)
self.client.force_authenticate(self.user)
data = {**get_upload_data(self.user.id), "file": f}
response = self.client.post(reverse(f'{self.stub}-list'), data=data, format='json')
assert_response_property(self, response, self.assertEqual, response.status_code, 415)

with self.subTest("Two-stage upload"):
observed_file = None
with self.subTest("Stage one - no mapping"):
Expand Down
5 changes: 5 additions & 0 deletions backend_django/galv/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,11 @@ class ObservedFileViewSet(DescribeSelfMixin, viewsets.ModelViewSet):
queryset = ObservedFile.objects.all().order_by('-last_observed_time', '-id')
http_method_names = ['get', 'post', 'patch', 'options']

def get_parsers(self):
if self.request is not None and self.action_map.get(self.request.method.lower()) == 'create':
return [MultiPartParser(), FormParser()]
return super().get_parsers()

def get_serializer_class(self):
if self.action == "create":
return ObservedFileCreateSerializer
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
project = 'Galv'
copyright = '2023, Oxford RSE'
author = 'Oxford RSE'
release = '2.4.0'
release = '2.4.1'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion docs/tags.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["v2.2.0", "v2.3.1", "v2.4.0", "main"]
["v2.2.0", "v2.3.1", "v2.4.1", "main"]

0 comments on commit bdc6b19

Please sign in to comment.