core: make user optional in token creation

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-08-25 21:17:36 +02:00
parent 8022d0801d
commit 0ccec96490
3 changed files with 9 additions and 3 deletions

View File

@ -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):

View File

@ -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

View File

@ -136,7 +136,10 @@ export class Form<T> 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;