""" Python representation of `user_capabilities` table. """ from enum import Enum from typing import TYPE_CHECKING from sqlmodel import Field, Relationship, SQLModel if TYPE_CHECKING: from .user import User class UserCapabilityType(Enum): """ Allowed values for capabilities """ admin = "admin" login = "login" issue = "issue" renew = "renew" def __repr__(self) -> str: return self.value class UserCapabilityBase(SQLModel): """ Common to all representations of capabilities """ capability_name: str = Field(primary_key=True) @property def _(self) -> UserCapabilityType: """ Transform into a `Capability`. """ return UserCapabilityType(self.capability_name) def __repr__(self) -> str: return self.capability_name class UserCapability(UserCapabilityBase, table=True): """ Representation of `user_capabilities` table """ __tablename__ = "user_capabilities" user_name: str = Field(primary_key=True, foreign_key="users.name") user: "User" = Relationship( back_populates="capabilities", )