From 1373732fd35e94720e33b23ed9c75dd25d9150d9 Mon Sep 17 00:00:00 2001 From: Jennings Zhang Date: Fri, 4 Oct 2024 22:06:05 -0400 Subject: [PATCH 1/2] Fix optional fields of PluginInstanceSerializer --- chris_backend/plugininstances/serializers.py | 4 ++-- requirements/base.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/chris_backend/plugininstances/serializers.py b/chris_backend/plugininstances/serializers.py index 6a2b1cef..f7dee612 100644 --- a/chris_backend/plugininstances/serializers.py +++ b/chris_backend/plugininstances/serializers.py @@ -35,7 +35,7 @@ class PluginInstanceSerializer(serializers.HyperlinkedModelSerializer): size = serializers.ReadOnlyField() error_code = serializers.ReadOnlyField() previous = serializers.HyperlinkedRelatedField( - view_name='plugininstance-detail', read_only=True + view_name='plugininstance-detail', read_only=True, allow_null=True ) output_folder = serializers.HyperlinkedRelatedField(view_name='chrisfolder-detail', read_only=True) @@ -49,7 +49,7 @@ class PluginInstanceSerializer(serializers.HyperlinkedModelSerializer): view_name='plugin-detail', read_only=True ) workflow = serializers.HyperlinkedRelatedField( - view_name='workflow-detail', read_only=True + view_name='workflow-detail', read_only=True, allow_null=True ) feed = serializers.HyperlinkedRelatedField(view_name='feed-detail', read_only=True) compute_resource = serializers.HyperlinkedRelatedField( diff --git a/requirements/base.txt b/requirements/base.txt index 9f59e073..6fb48073 100755 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -16,4 +16,4 @@ whitenoise[brotli]==6.5.0 PyJWT===2.8.0 channels[daphne]==4.1.0 nats-py==2.9.0 -drf-spectacular==0.27.2 +git+https://github.com/tfranzel/drf-spectacular.git@refs/pull/1307/head From e04fa0fdb8c659fd4a8c2a20863876b49a648a0e Mon Sep 17 00:00:00 2001 From: Jennings Zhang Date: Fri, 4 Oct 2024 22:41:20 -0400 Subject: [PATCH 2/2] Add OpenApiAuthenticationExtension for TokenAuthSupportQueryString --- chris_backend/core/views.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/chris_backend/core/views.py b/chris_backend/core/views.py index 7b8e685d..c214dce3 100755 --- a/chris_backend/core/views.py +++ b/chris_backend/core/views.py @@ -9,6 +9,7 @@ from rest_framework.reverse import reverse from rest_framework import exceptions from rest_framework.authentication import TokenAuthentication +from drf_spectacular.extensions import OpenApiAuthenticationExtension from collectionjson import services from .models import ChrisInstance, FileDownloadToken, FileDownloadTokenFilter @@ -156,3 +157,15 @@ def authenticate_token(token: str) -> User: token_obj.delete() # one-time-use token, we could instead set revoked=true return user + + +class TokenAuthSupportQueryStringScheme(OpenApiAuthenticationExtension): + target_class = TokenAuthSupportQueryString + name = 'DownloadTokenInQueryString' + + def get_security_definition(self, auto_schema): + return { + 'type': 'apiKey', + 'in': 'header', + 'name': 'download_token' + }