9f54bc3ab1
Phase 4.1 — Role Hierarchy:
- UserRole enum: add global_admin (platform operator) + tenant_admin
(per-tenant admin); keep legacy 'admin' for backward compat
- Role sets: ADMIN_ROLES, TENANT_ADMIN_ROLES, PM_ROLES, RLS_BYPASS_ROLES
- New auth guards: require_global_admin(), require_tenant_admin_or_above(),
require_pm_or_above(), is_admin(), is_privileged()
- Legacy require_admin / require_admin_or_pm now check both old+new roles
- Migration 049: ADD VALUE global_admin + tenant_admin with AUTOCOMMIT
workaround; backfills admin → global_admin
- Seed: new admin users created with global_admin role
Phase 4.3 — RLS bypass updated for global_admin in get_db + set_tenant_context
Phase 4.4 — Tenant Feature Flags:
- Migration 050: tenant_config JSONB on tenants table
- Tenant model: tenant_config field + get_config() accessor
- Defaults: max_concurrent_renders=3, fallback_material, invoice_prefix etc.
Phase 5.1 — Fallback Material:
- blender_render.py: replace PALETTE_LINEAR/PALETTE_HEX/_assign_palette_material
with _assign_failed_material() → SCHAEFFLER_059999_FailedMaterial (magenta)
- Unmatched parts now logged explicitly before rendering
Phase 5.2 — Remove EEVEE fallback:
- render_blender.py: EEVEE→Cycles silent retry removed; hard failure on EEVEE error
Phase 5.3 — Remove Blender version check:
- render_blender.py: deleted MIN_BLENDER_VERSION = (5, 0, 1) constant
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
52 lines
2.5 KiB
Python
52 lines
2.5 KiB
Python
import uuid
|
|
from datetime import datetime
|
|
from sqlalchemy import String, Boolean, DateTime, Enum as SAEnum, ForeignKey
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from app.database import Base
|
|
import enum
|
|
|
|
|
|
class UserRole(str, enum.Enum):
|
|
# New role hierarchy (Phase 4)
|
|
global_admin = "global_admin" # platform operator — bypasses RLS, all tenants
|
|
tenant_admin = "tenant_admin" # per-tenant admin — full control within own tenant
|
|
project_manager = "project_manager" # order/render management within tenant
|
|
client = "client" # read own orders, create draft orders
|
|
|
|
# Legacy alias — kept for backward compat during migration; use global_admin for new code
|
|
admin = "admin"
|
|
|
|
|
|
# Roles that have administrative privileges (global_admin + legacy admin)
|
|
ADMIN_ROLES = {"global_admin", "admin"}
|
|
|
|
# Roles with tenant-level admin access
|
|
TENANT_ADMIN_ROLES = {"global_admin", "tenant_admin", "admin"}
|
|
|
|
# Roles with project management or above
|
|
PM_ROLES = {"global_admin", "tenant_admin", "project_manager", "admin"}
|
|
|
|
# Roles that bypass RLS (see TenantContextMiddleware + get_db)
|
|
RLS_BYPASS_ROLES = {"global_admin", "admin"}
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False, index=True)
|
|
password_hash: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
full_name: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
role: Mapped[UserRole] = mapped_column(SAEnum(UserRole), default=UserRole.client, nullable=False)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
|
tenant_id: Mapped[uuid.UUID | None] = mapped_column(
|
|
UUID(as_uuid=True), ForeignKey("tenants.id"), nullable=True, index=True
|
|
)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
|
|
|
tenant: Mapped["Tenant | None"] = relationship("Tenant", back_populates="users", lazy="noload")
|
|
orders: Mapped[list["Order"]] = relationship("Order", back_populates="created_by_user", foreign_keys="Order.created_by")
|
|
audit_logs: Mapped[list["AuditLog"]] = relationship("AuditLog", back_populates="user", foreign_keys="AuditLog.user_id")
|