kiwi-vpn/api/kiwi_vpn_api/db/capability.py

37 lines
773 B
Python
Raw Normal View History

2022-03-27 13:47:38 +00:00
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"
2022-03-28 00:48:44 +00:00
def __repr__(self) -> str:
return self.value
2022-03-27 13:47:38 +00:00
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):
2022-03-28 00:48:44 +00:00
user_name: str = Field(primary_key=True, foreign_key="user.name")
2022-03-27 13:47:38 +00:00
user: "User" = Relationship(
2022-03-28 00:48:44 +00:00
back_populates="capabilities",
2022-03-27 13:47:38 +00:00
)