From d2df426489261ca0a6b38198a1b677bc0c81ed03 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 10 Feb 2021 20:30:19 +0100 Subject: [PATCH] core: fix tokens using wrong lookup --- authentik/core/api/providers.py | 5 +---- authentik/core/api/sources.py | 7 +++---- authentik/core/api/tokens.py | 6 +++--- authentik/core/api/utils.py | 6 ++++++ swagger.yaml | 6 +++--- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/authentik/core/api/providers.py b/authentik/core/api/providers.py index f4d72ff80..c34207e81 100644 --- a/authentik/core/api/providers.py +++ b/authentik/core/api/providers.py @@ -6,10 +6,7 @@ from rest_framework.decorators import action from rest_framework.fields import ReadOnlyField from rest_framework.request import Request from rest_framework.response import Response -from rest_framework.serializers import ( - ModelSerializer, - SerializerMethodField, -) +from rest_framework.serializers import ModelSerializer, SerializerMethodField from rest_framework.viewsets import ModelViewSet from authentik.core.api.utils import MetaNameSerializer, TypeCreateSerializer diff --git a/authentik/core/api/sources.py b/authentik/core/api/sources.py index e2c927434..b8f191d50 100644 --- a/authentik/core/api/sources.py +++ b/authentik/core/api/sources.py @@ -1,17 +1,16 @@ """Source API Views""" -from authentik.lib.templatetags.authentik_utils import verbose_name -from authentik.lib.utils.reflection import all_subclasses +from django.shortcuts import reverse from drf_yasg2.utils import swagger_auto_schema from rest_framework.decorators import action from rest_framework.request import Request from rest_framework.response import Response from rest_framework.serializers import ModelSerializer, SerializerMethodField from rest_framework.viewsets import ReadOnlyModelViewSet -from django.shortcuts import reverse -from django.utils.translation import gettext_lazy as _ from authentik.core.api.utils import MetaNameSerializer, TypeCreateSerializer from authentik.core.models import Source +from authentik.lib.templatetags.authentik_utils import verbose_name +from authentik.lib.utils.reflection import all_subclasses class SourceSerializer(ModelSerializer, MetaNameSerializer): diff --git a/authentik/core/api/tokens.py b/authentik/core/api/tokens.py index 25422d5d3..f30ba4f4b 100644 --- a/authentik/core/api/tokens.py +++ b/authentik/core/api/tokens.py @@ -43,12 +43,12 @@ class TokenViewSet(ModelViewSet): @swagger_auto_schema(responses={200: TokenViewSerializer(many=False)}) @action(detail=True) + # pylint: disable=unused-argument def view_key(self, request: Request, identifier: str) -> Response: """Return token key and log access""" - tokens = Token.filter_not_expired(identifier=identifier) - if not tokens.exists(): + token: Token = self.get_object() + if token.is_expired: raise Http404 - token = tokens.first() Event.new(EventAction.SECRET_VIEW, secret=token).from_http( # noqa # nosec request ) diff --git a/authentik/core/api/utils.py b/authentik/core/api/utils.py index 36907e6f4..be583bdcc 100644 --- a/authentik/core/api/utils.py +++ b/authentik/core/api/utils.py @@ -31,3 +31,9 @@ class TypeCreateSerializer(Serializer): name = CharField(read_only=True) description = CharField(read_only=True) link = CharField(read_only=True) + + def create(self, validated_data: dict) -> Model: + raise NotImplementedError + + def update(self, instance: Model, validated_data: dict) -> Model: + raise NotImplementedError diff --git a/swagger.yaml b/swagger.yaml index 9674c2a07..350410702 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -4344,7 +4344,7 @@ paths: type: integer responses: '200': - description: '' + description: Types of an object that can be created schema: description: '' type: array @@ -4936,7 +4936,7 @@ paths: type: integer responses: '200': - description: '' + description: Types of an object that can be created schema: description: '' type: array @@ -9083,7 +9083,7 @@ definitions: type: string readOnly: true TypeCreate: - description: '' + description: Types of an object that can be created type: object properties: name: