Skip to content

Commit

Permalink
Merge branch 'beta' into require-auth-at-project-level
Browse files Browse the repository at this point in the history
  • Loading branch information
noliveleger committed Jan 11, 2024
2 parents 276b6b3 + aa5a80c commit 114783e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
12 changes: 5 additions & 7 deletions onadata/apps/api/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
HttpResponseRedirect,
)
from django.utils.translation import gettext as t
from kobo_service_account.utils import get_real_user
from kobo_service_account.utils import get_real_user, get_request_headers
from rest_framework import exceptions
from rest_framework.authtoken.models import Token
from rest_framework.request import Request
Expand All @@ -31,8 +31,6 @@
from onadata.libs.utils.logger_tools import (
publish_form,
response_with_mimetype_and_name,
OPEN_ROSA_VERSION_HEADER,
OPEN_ROSA_VERSION,
)
from onadata.libs.utils.user_auth import (
check_and_set_form_by_id,
Expand Down Expand Up @@ -213,12 +211,12 @@ def get_media_file_response(
# an HTTP redirection. We use KoBoCAT to proxy the response from KPI
headers = {}
if not request.user.is_anonymous:
token = Token.objects.get(user=request.user)
headers['Authorization'] = f'Token {token.key}'
headers = get_request_headers(request.user.username)

# Send the request internally to avoid extra traffic on the public interface
internal_url = metadata.data_value.replace(settings.KOBOFORM_URL,
settings.KOBOFORM_INTERNAL_URL)
internal_url = metadata.data_value.replace(
settings.KOBOFORM_URL, settings.KOBOFORM_INTERNAL_URL
)
response = requests.get(internal_url, headers=headers)

return HttpResponse(
Expand Down
9 changes: 5 additions & 4 deletions onadata/apps/api/viewsets/metadata_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,11 @@ class MetaDataViewSet(viewsets.ModelViewSet):
def retrieve(self, request, *args, **kwargs):
self.object = self.get_object()

if isinstance(request.accepted_renderer, MediaFileRenderer) \
and self.object.data_file is not None:

return get_media_file_response(self.object)
if (
isinstance(request.accepted_renderer, MediaFileRenderer)
and self.object.data_file is not None
):
return get_media_file_response(self.object, request)

serializer = self.get_serializer(self.object)

Expand Down

0 comments on commit 114783e

Please sign in to comment.