flask_more_smorest.perms.models.abstract_role
Abstract role and domain models for Flask-More-Smorest.
Provides abstract bases for Domain and UserRole models for multi-domain role-based access control.
Classes
|
Abstract Domain model for multi-domain support. |
|
Abstract UserRole model with domain scoping for multi-domain applications. |
- class flask_more_smorest.perms.models.abstract_role.AbstractDomain(**kwargs)[source]
Abstract Domain model for multi-domain support.
This is an abstract base class - it does NOT create a database table. Subclasses must define concrete fields and table configuration.
Domains represent distinct contexts within an application (e.g., organizations, tenants, or projects) where roles can be scoped.
Subclassing example:
from flask_more_smorest.perms import AbstractDomain class CustomDomain(AbstractDomain): __tablename__ = "domain" name: Mapped[str] = mapped_column(db.String(255), nullable=False) display_name: Mapped[str] = mapped_column(db.String(255), nullable=False) active: Mapped[bool] = mapped_column(db.Boolean, default=True, nullable=False) # Optional: custom fields organization_id: Mapped[str] = mapped_column(db.String(50)) settings: Mapped[dict] = mapped_column(db.JSON, default={})
- class flask_more_smorest.perms.models.abstract_role.AbstractUserRole(domain_id=None, role=None, **kwargs)[source]
Abstract UserRole model with domain scoping for multi-domain applications.
This is an abstract base class - it does NOT create a database table. Subclasses must define concrete fields and table configuration.
Supports custom role enums by accepting any string/enum value:
from enum import Enum class CustomRole(str, Enum): SUPERADMIN = "SUPERADMIN" ADMIN = "ADMIN" MANAGER = "MANAGER" USER = "USER" class CustomUserRole(AbstractUserRole): __tablename__ = "user_role" user_id: Mapped[uuid.UUID] = mapped_column( sa.Uuid(as_uuid=True), db.ForeignKey("user.id"), nullable=False ) domain_id: Mapped[uuid.UUID | None] = mapped_column( sa.Uuid(as_uuid=True), db.ForeignKey("domain.id"), nullable=True, default=None, ) _role: Mapped[str] = mapped_column("role", sa.String(50), nullable=False) # Create roles with custom enum values role = CustomUserRole(user=user, role=CustomRole.MANAGER)
- user = <_RelationshipDeclared at 0x7a2d8811a210; no key>
- domain = <_RelationshipDeclared at 0x7a2d881187d0; no key>