32 lines
713 B
Python
32 lines
713 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"
|
|
|
|
|
|
class UserCapabilityBase(SQLModel):
|
|
user_name: str = Field(primary_key=True, foreign_key="user.name")
|
|
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: "User" = Relationship(
|
|
back_populates="capabilities"
|
|
)
|