Download src/core/workspaces/models.py from anaselamr/yaz: direct link, hf CLI and curl.
- Browser
- Download file 3.97 kB
-
https://huggingface.co/spaces/anaselamr/yaz/resolve/main/src/core/workspaces/models.py
- Command line
-
hf download hf://spaces/anaselamr/yaz/src/core/workspaces/models.py
-
curl -L -o models.py https://huggingface.co/spaces/anaselamr/yaz/resolve/main/src/core/workspaces/models.py
3.97 kB
| """ | |
| Workspace — Operational context within a tenant. | |
| Architecture: | |
| LegalEntity → System → Tenant → **Workspace** → Cases / Users | |
| A workspace represents a bounded operational context within a tenant, | |
| such as a surgical department, ward, clinic, or project team. Users | |
| are assigned to workspaces and cases belong to workspaces. | |
| Standards: HIPAA (workspace-level access control), ISO 27001 (segregation) | |
| """ | |
| from __future__ import annotations | |
| import enum | |
| import uuid | |
| from datetime import datetime | |
| from typing import Any, Dict, List, Optional | |
| from sqlalchemy import Column, DateTime, Index, Text | |
| from sqlalchemy.dialects.postgresql import JSON, UUID | |
| from sqlmodel import Field, SQLModel | |
| from core.database.mixins import SoftDeleteMixin, TenantMixin, TimestampMixin | |
| class WorkspaceType(str, enum.Enum): | |
| DEPARTMENT = "department" | |
| TEAM = "team" | |
| PROJECT = "project" | |
| CLINIC = "clinic" | |
| WARD = "ward" | |
| OPERATING_SUITE = "operating_suite" | |
| LABORATORY = "laboratory" | |
| CUSTOM = "custom" | |
| class WorkspaceStatus(str, enum.Enum): | |
| ACTIVE = "active" | |
| ARCHIVED = "archived" | |
| SUSPENDED = "suspended" | |
| class MemberRole(str, enum.Enum): | |
| OWNER = "owner" | |
| ADMIN = "admin" | |
| MEMBER = "member" | |
| VIEWER = "viewer" | |
| class Workspace(TenantMixin, TimestampMixin, SoftDeleteMixin, SQLModel, table=True): | |
| """ | |
| Workspace — bounded operational context within a tenant. | |
| Security: tenant_id MANDATORY on every query. | |
| Performance: <200ms for list/CRUD. | |
| """ | |
| __tablename__ = "workspaces" | |
| __table_args__ = ( | |
| Index("ix_workspaces_tenant_slug", "tenant_id", "slug", unique=True), | |
| {"extend_existing": True}, | |
| ) | |
| id: uuid.UUID = Field( | |
| default_factory=uuid.uuid4, | |
| sa_column=Column(UUID(as_uuid=True), primary_key=True, nullable=False), | |
| ) | |
| tenant_id: uuid.UUID = Field( | |
| sa_column=Column(UUID(as_uuid=True), nullable=False, index=True), | |
| ) | |
| slug: str = Field(max_length=100, nullable=False, index=True) | |
| name: str = Field(max_length=200, nullable=False) | |
| description: Optional[str] = Field( | |
| default=None, | |
| sa_column=Column(Text), | |
| ) | |
| workspace_type: WorkspaceType = Field(default=WorkspaceType.DEPARTMENT) | |
| status: WorkspaceStatus = Field(default=WorkspaceStatus.ACTIVE) | |
| # Owner (user who created the workspace) | |
| owner_id: Optional[uuid.UUID] = Field( | |
| default=None, | |
| sa_column=Column(UUID(as_uuid=True)), | |
| ) | |
| # Branding / icon | |
| icon: Optional[str] = Field(default=None, max_length=10) | |
| color: Optional[str] = Field(default=None, max_length=20) | |
| # Config (enabled engines, feature flags) | |
| config: Optional[Dict[str, Any]] = Field( | |
| default=None, | |
| sa_column=Column(JSON), | |
| ) | |
| # Enabled domain engines (subset of tenant's engines) | |
| enabled_engines: Optional[List[str]] = Field( | |
| default=None, | |
| sa_column=Column(JSON), | |
| ) | |
| class WorkspaceMember(TenantMixin, TimestampMixin, SQLModel, table=True): | |
| """ | |
| Workspace membership — links users to workspaces with roles. | |
| """ | |
| __tablename__ = "workspace_members" | |
| __table_args__ = ( | |
| Index("ix_ws_members_ws_user", "workspace_id", "user_id", unique=True), | |
| {"extend_existing": True}, | |
| ) | |
| id: uuid.UUID = Field( | |
| default_factory=uuid.uuid4, | |
| sa_column=Column(UUID(as_uuid=True), primary_key=True, nullable=False), | |
| ) | |
| tenant_id: uuid.UUID = Field( | |
| sa_column=Column(UUID(as_uuid=True), nullable=False, index=True), | |
| ) | |
| workspace_id: uuid.UUID = Field( | |
| sa_column=Column(UUID(as_uuid=True), nullable=False, index=True), | |
| ) | |
| user_id: uuid.UUID = Field( | |
| sa_column=Column(UUID(as_uuid=True), nullable=False, index=True), | |
| ) | |
| role: MemberRole = Field(default=MemberRole.MEMBER) | |
| joined_at: Optional[datetime] = Field( | |
| default=None, | |
| sa_column=Column(DateTime(timezone=True)), | |
| ) | |