Updated endpoints and tests for users, rbac, health, file, and auth
This commit is contained in:
1 parent
207b8eea5e
commit
d379fbd621
26 files changed
+582
-28
No files matched your search
@@ -1,21 +1,65 @@
|
||||
"""Database user model."""
|
||||
# app/platform/users/models.py
|
||||
"""User and UserAuth ORM models."""
|
||||
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Column, String
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
from sqlalchemy import Boolean, DateTime, ForeignKey, String, func
|
||||
from sqlalchemy import Enum as SAEnum
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.core.database import Base
|
||||
from app.platform.users.enums import UserStatus
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
"""Base Class for all db models."""
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class DBUser(Base):
|
||||
"""Database User Model."""
|
||||
|
||||
id = Column(
|
||||
String(36), primary_key=True, default=lambda: str(uuid.uuid4()), index=True
|
||||
id: Mapped[uuid.UUID] = mapped_column(primary_key=True, default=uuid.uuid4)
|
||||
first_name: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
last_name: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
email: Mapped[str] = mapped_column(
|
||||
String(255), unique=True, index=True, nullable=False
|
||||
)
|
||||
email = Column(String)
|
||||
|
||||
status: Mapped[UserStatus] = mapped_column(
|
||||
SAEnum(UserStatus, native_enum=False, length=32),
|
||||
default=UserStatus.ACTIVE,
|
||||
nullable=False,
|
||||
)
|
||||
is_superuser: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
||||
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
|
||||
)
|
||||
last_login_at: Mapped[datetime | None] = mapped_column(
|
||||
DateTime(timezone=True), nullable=True
|
||||
)
|
||||
|
||||
auth: Mapped["UserAuth"] = relationship(
|
||||
back_populates="user", uselist=False, cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
|
||||
class UserAuth(Base):
|
||||
__tablename__ = "user_auth"
|
||||
|
||||
# Shared primary key pattern: user_id is both the PK and the FK. This
|
||||
# makes a second UserAuth row for the same user structurally
|
||||
# impossible, rather than something you'd enforce with a separate
|
||||
# unique constraint on a regular FK column.
|
||||
user_id: Mapped[uuid.UUID] = mapped_column(
|
||||
ForeignKey("users.id", ondelete="CASCADE"), primary_key=True
|
||||
)
|
||||
hashed_password: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
must_change_password: Mapped[bool] = mapped_column(
|
||||
Boolean, default=False, nullable=False
|
||||
)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
|
||||
)
|
||||
|
||||
user: Mapped["User"] = relationship(back_populates="auth")
|
||||
Reference in new issue
Block a user