Features: 1) Add request schema using UserSerializer for user creation endpoint; 2) Implement validation for attributes in user serializer, ensuring it's a dictionary and requiring business_identificator for business accounts;
Fixes: None; Extra: None;
This commit is contained in:
parent
99288ebbc8
commit
acd1e3b407
2 changed files with 6 additions and 0 deletions
|
|
@ -14,6 +14,7 @@ from vibes_auth.serializers import (
|
||||||
USER_SCHEMA = {
|
USER_SCHEMA = {
|
||||||
"create": extend_schema(
|
"create": extend_schema(
|
||||||
summary=_("create a new user"),
|
summary=_("create a new user"),
|
||||||
|
request=UserSerializer,
|
||||||
responses={status.HTTP_201_CREATED: UserSerializer, **BASE_ERRORS},
|
responses={status.HTTP_201_CREATED: UserSerializer, **BASE_ERRORS},
|
||||||
),
|
),
|
||||||
"retrieve": extend_schema(
|
"retrieve": extend_schema(
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,11 @@ class UserSerializer(ModelSerializer):
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
|
if "attributes" in attrs:
|
||||||
|
if not isinstance(attrs["attributes"], dict):
|
||||||
|
raise ValidationError(_("attributes must be a dictionary"))
|
||||||
|
if attrs["attributes"].get("is_business") and not attrs["attributes"].get("business_identificator"):
|
||||||
|
raise ValidationError(_("business identificator is required when registering as a business"))
|
||||||
if "password" in attrs:
|
if "password" in attrs:
|
||||||
validate_password(attrs["password"])
|
validate_password(attrs["password"])
|
||||||
if not compare_digest(attrs["password"], attrs["confirm_password"]):
|
if not compare_digest(attrs["password"], attrs["confirm_password"]):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue