36 lines
773 B
Python
36 lines
773 B
Python
from enum import Enum
|
|
from typing import TYPE_CHECKING
|
|
|
|
from sqlmodel import Field, Relationship, SQLModel
|
|
|
|
if TYPE_CHECKING:
|
|
from .user import User
|
|
|
|
|
|
class Capability(Enum):
|
|
admin = "admin"
|
|
login = "login"
|
|
issue = "issue"
|
|
renew = "renew"
|
|
|
|
def __repr__(self) -> str:
|
|
return self.value
|
|
|
|
|
|
class UserCapabilityBase(SQLModel):
|
|
capability_name: str = Field(primary_key=True)
|
|
|
|
@property
|
|
def _(self) -> Capability:
|
|
return Capability(self.capability_name)
|
|
|
|
def __repr__(self) -> str:
|
|
return self.capability_name
|
|
|
|
|
|
class UserCapability(UserCapabilityBase, table=True):
|
|
user_name: str = Field(primary_key=True, foreign_key="user.name")
|
|
|
|
user: "User" = Relationship(
|
|
back_populates="capabilities",
|
|
)
|