core: make user optional in token creation
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
8022d0801d
commit
0ccec96490
|
@ -27,6 +27,8 @@ class TokenSerializer(ManagedSerializer, ModelSerializer):
|
||||||
|
|
||||||
def validate(self, attrs: dict[Any, str]) -> dict[Any, str]:
|
def validate(self, attrs: dict[Any, str]) -> dict[Any, str]:
|
||||||
"""Ensure only API or App password tokens are created."""
|
"""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)
|
attrs.setdefault("intent", TokenIntents.INTENT_API)
|
||||||
if attrs.get("intent") not in [TokenIntents.INTENT_API, TokenIntents.INTENT_APP_PASSWORD]:
|
if attrs.get("intent") not in [TokenIntents.INTENT_API, TokenIntents.INTENT_APP_PASSWORD]:
|
||||||
raise ValidationError(f"Invalid intent {attrs.get('intent')}")
|
raise ValidationError(f"Invalid intent {attrs.get('intent')}")
|
||||||
|
@ -46,6 +48,9 @@ class TokenSerializer(ManagedSerializer, ModelSerializer):
|
||||||
"expires",
|
"expires",
|
||||||
"expiring",
|
"expiring",
|
||||||
]
|
]
|
||||||
|
extra_kwargs = {
|
||||||
|
"user": {"required": False},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class TokenViewSerializer(PassiveSerializer):
|
class TokenViewSerializer(PassiveSerializer):
|
||||||
|
|
|
@ -30070,7 +30070,6 @@ components:
|
||||||
required:
|
required:
|
||||||
- identifier
|
- identifier
|
||||||
- pk
|
- pk
|
||||||
- user
|
|
||||||
TokenRequest:
|
TokenRequest:
|
||||||
type: object
|
type: object
|
||||||
description: Token Serializer
|
description: Token Serializer
|
||||||
|
@ -30102,7 +30101,6 @@ components:
|
||||||
type: boolean
|
type: boolean
|
||||||
required:
|
required:
|
||||||
- identifier
|
- identifier
|
||||||
- user
|
|
||||||
TokenView:
|
TokenView:
|
||||||
type: object
|
type: object
|
||||||
description: Show token's current key
|
description: Show token's current key
|
||||||
|
|
|
@ -136,7 +136,10 @@ export class Form<T> extends LitElement {
|
||||||
json[element.name] = values;
|
json[element.name] = values;
|
||||||
} else if (element.tagName.toLowerCase() === "input" && element.type === "date") {
|
} else if (element.tagName.toLowerCase() === "input" && element.type === "date") {
|
||||||
json[element.name] = element.valueAsDate;
|
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);
|
json[element.name] = new Date(element.valueAsNumber);
|
||||||
} else if (element.tagName.toLowerCase() === "input" && element.type === "checkbox") {
|
} else if (element.tagName.toLowerCase() === "input" && element.type === "checkbox") {
|
||||||
json[element.name] = element.checked;
|
json[element.name] = element.checked;
|
||||||
|
|
Reference in New Issue