2022-03-28 20:58:40 +00:00
|
|
|
"""
|
|
|
|
Python representation of `usercapability` table.
|
|
|
|
"""
|
|
|
|
|
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):
|
2022-03-28 20:58:40 +00:00
|
|
|
"""
|
|
|
|
Allowed values for capabilities
|
|
|
|
"""
|
|
|
|
|
2022-03-27 13:47:38 +00:00
|
|
|
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):
|
2022-03-28 20:58:40 +00:00
|
|
|
"""
|
|
|
|
Common to all representations of capabilities
|
|
|
|
"""
|
|
|
|
|
2022-03-27 13:47:38 +00:00
|
|
|
capability_name: str = Field(primary_key=True)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def _(self) -> Capability:
|
2022-03-28 20:58:40 +00:00
|
|
|
"""
|
|
|
|
Transform into a `Capability`.
|
|
|
|
"""
|
|
|
|
|
2022-03-27 13:47:38 +00:00
|
|
|
return Capability(self.capability_name)
|
|
|
|
|
|
|
|
def __repr__(self) -> str:
|
|
|
|
return self.capability_name
|
|
|
|
|
|
|
|
|
|
|
|
class UserCapability(UserCapabilityBase, table=True):
|
2022-03-28 20:58:40 +00:00
|
|
|
"""
|
|
|
|
Representation of usercapability table
|
|
|
|
"""
|
|
|
|
|
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
|
|
|
)
|