You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import Boolean, DateTime, Enum as SAEnum, Integer, String
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from admin_app.db.models.base import AdminTimestampedModel
|
|
from shared.contracts import StaffRole
|
|
|
|
# Modelo da conta administrativa
|
|
# Ele representa o usuário interno do painel
|
|
|
|
def _staff_role_values(enum_cls) -> list[str]:
|
|
return [role.value for role in enum_cls]
|
|
|
|
|
|
class StaffAccount(AdminTimestampedModel):
|
|
__tablename__ = "staff_accounts"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
email: Mapped[str] = mapped_column(String(255), unique=True, index=True, nullable=False)
|
|
display_name: Mapped[str] = mapped_column(String(150), nullable=False)
|
|
password_hash: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
role: Mapped[StaffRole] = mapped_column(
|
|
SAEnum(
|
|
StaffRole,
|
|
native_enum=False,
|
|
values_callable=_staff_role_values,
|
|
length=32,
|
|
),
|
|
nullable=False,
|
|
default=StaffRole.VIEWER,
|
|
)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
|
|
last_login_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|