29 lines
953 B
Python
29 lines
953 B
Python
|
|
"""Role model for RBAC."""
|
||
|
|
|
||
|
|
import uuid
|
||
|
|
|
||
|
|
from sqlalchemy import String, ForeignKey, JSON
|
||
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||
|
|
|
||
|
|
from app.db.base import Base
|
||
|
|
|
||
|
|
|
||
|
|
class Role(Base):
|
||
|
|
"""Represents a role with permissions within an account."""
|
||
|
|
|
||
|
|
__tablename__ = "roles"
|
||
|
|
|
||
|
|
id: Mapped[str] = mapped_column(
|
||
|
|
String(36), primary_key=True, default=lambda: str(uuid.uuid4())
|
||
|
|
)
|
||
|
|
account_id: Mapped[str] = mapped_column(
|
||
|
|
String(36), ForeignKey("accounts.id", ondelete="CASCADE"), nullable=False
|
||
|
|
)
|
||
|
|
name: Mapped[str] = mapped_column(String(100), nullable=False)
|
||
|
|
description: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||
|
|
permissions: Mapped[list] = mapped_column(JSON, nullable=False, default=list)
|
||
|
|
|
||
|
|
# Relationships
|
||
|
|
account: Mapped["Account"] = relationship("Account", back_populates="roles")
|
||
|
|
users: Mapped[list["User"]] = relationship("User", back_populates="role")
|