Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/dispatch/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import secrets
from datetime import datetime, timedelta
from uuid import uuid4
from typing import Optional

import bcrypt
from jose import jwt
Expand Down Expand Up @@ -166,7 +165,7 @@ def email_required(cls, v):
class UserLogin(UserBase):
"""Pydantic model for user login data."""

password: str
password: str | None = None

@field_validator("password")
@classmethod
Expand All @@ -180,7 +179,7 @@ def password_required(cls, v):
class UserRegister(UserLogin):
"""Pydantic model for user registration data."""

password: str = None
password: str | None = None

@field_validator("password", mode="before")
@classmethod
Expand Down Expand Up @@ -209,10 +208,10 @@ class UserUpdate(DispatchBase):
"""Pydantic model for updating user data."""

id: PrimaryKey
projects: Optional[list[UserProject]] = None
organizations: Optional[list[UserOrganization]]
experimental_features: Optional[bool] = None
role: Optional[str] = None
projects: list[UserProject] | None = None
organizations: list[UserOrganization] | None
experimental_features: bool | None = None
role: str | None = None


class UserPasswordUpdate(DispatchBase):
Expand Down
9 changes: 6 additions & 3 deletions src/dispatch/auth/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,14 @@ def create_or_update_organization_role(
def create(*, db_session, organization: str, user_in: (UserRegister | UserCreate)) -> DispatchUser:
"""Creates a new dispatch user."""
# pydantic forces a string password, but we really want bytes
password = bytes(user_in.password, "utf-8")

# Handle the case where password may be None (e.g., SSO users)
if user_in.password is not None:
password = bytes(user_in.password, "utf-8")
else:
password = None
# create the user
user = DispatchUser(
**user_in.dict(exclude={"password", "organizations", "projects", "role"}), password=password
**user_in.model_dump(exclude={"password", "organizations", "projects", "role"}), password=password
)

org = organization_service.get_by_slug_or_raise(
Expand Down
Loading