From 0ccec9649037cda23eb1b586490d606641de6e24 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 25 Aug 2021 21:17:36 +0200 Subject: [PATCH] core: make user optional in token creation Signed-off-by: Jens Langhammer --- authentik/core/api/tokens.py | 5 +++++ schema.yml | 2 -- web/src/elements/forms/Form.ts | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/authentik/core/api/tokens.py b/authentik/core/api/tokens.py index d2b5905e49..b128e5bc82 100644 --- a/authentik/core/api/tokens.py +++ b/authentik/core/api/tokens.py @@ -27,6 +27,8 @@ class TokenSerializer(ManagedSerializer, ModelSerializer): def validate(self, attrs: dict[Any, str]) -> dict[Any, str]: """Ensure only API or App password tokens are created.""" + request: Request = self.context["request"] + attrs.setdefault("user", request.user) attrs.setdefault("intent", TokenIntents.INTENT_API) if attrs.get("intent") not in [TokenIntents.INTENT_API, TokenIntents.INTENT_APP_PASSWORD]: raise ValidationError(f"Invalid intent {attrs.get('intent')}") @@ -46,6 +48,9 @@ class TokenSerializer(ManagedSerializer, ModelSerializer): "expires", "expiring", ] + extra_kwargs = { + "user": {"required": False}, + } class TokenViewSerializer(PassiveSerializer): diff --git a/schema.yml b/schema.yml index 7c87d9766f..d9af69eb01 100644 --- a/schema.yml +++ b/schema.yml @@ -30070,7 +30070,6 @@ components: required: - identifier - pk - - user TokenRequest: type: object description: Token Serializer @@ -30102,7 +30101,6 @@ components: type: boolean required: - identifier - - user TokenView: type: object description: Show token's current key diff --git a/web/src/elements/forms/Form.ts b/web/src/elements/forms/Form.ts index 731e61e6d9..16b8a46cf4 100644 --- a/web/src/elements/forms/Form.ts +++ b/web/src/elements/forms/Form.ts @@ -136,7 +136,10 @@ export class Form extends LitElement { json[element.name] = values; } else if (element.tagName.toLowerCase() === "input" && element.type === "date") { json[element.name] = element.valueAsDate; - } else if (element.tagName.toLowerCase() === "input" && element.type === "datetime-local") { + } else if ( + element.tagName.toLowerCase() === "input" && + element.type === "datetime-local" + ) { json[element.name] = new Date(element.valueAsNumber); } else if (element.tagName.toLowerCase() === "input" && element.type === "checkbox") { json[element.name] = element.checked;