Phase 1C: Frontend unified contact UI

This commit is contained in:
Agent Zero
2026-07-23 17:17:32 +02:00
parent a8331fbc2b
commit 879106c4eb
62 changed files with 552 additions and 1276 deletions
+1 -31
View File
@@ -23,18 +23,13 @@ class EntityLinksPlugin(BasePlugin):
module="app.plugins.builtins.entity_links.routes",
router_attr="router",
),
PluginRouteDef(
path="/api/v1/companies",
module="app.plugins.builtins.entity_links.routes",
router_attr="company_router",
),
PluginRouteDef(
path="/api/v1/contacts",
module="app.plugins.builtins.entity_links.routes",
router_attr="contact_router",
),
],
events=["company.deleted", "contact.deleted"],
events=["contact.deleted"],
migrations=["0001_initial.sql"],
permissions=[
"entity_links:read",
@@ -44,31 +39,6 @@ class EntityLinksPlugin(BasePlugin):
is_core=True,
)
async def on_company_deleted(self, payload: dict[str, Any]) -> None:
"""Handle company.deleted event — remove all EntityLink rows for that company."""
from sqlalchemy import delete
from app.core.db import get_session_factory
from app.plugins.builtins.entity_links.models import EntityLink
entity_id = payload.get("entity_id") or payload.get("company_id")
tenant_id = payload.get("tenant_id")
if entity_id is None or tenant_id is None:
return
import uuid as _uuid
factory = get_session_factory()
async with factory() as session:
await session.execute(
delete(EntityLink).where(
EntityLink.tenant_id == _uuid.UUID(tenant_id),
EntityLink.entity_type == "company",
EntityLink.entity_id == _uuid.UUID(str(entity_id)),
)
)
await session.commit()
async def on_contact_deleted(self, payload: dict[str, Any]) -> None:
"""Handle contact.deleted event — remove all EntityLink rows for that contact."""
from sqlalchemy import delete
+2 -32
View File
@@ -14,10 +14,9 @@ from app.plugins.builtins.entity_links.models import EntityLink
from app.plugins.builtins.entity_links.schemas import EntityLinkRequest
router = APIRouter(prefix="/api/v1/dms", tags=["entity-links"])
company_router = APIRouter(prefix="/api/v1/companies", tags=["entity-links"])
contact_router = APIRouter(prefix="/api/v1/contacts", tags=["entity-links"])
VALID_ENTITY_TYPES = {"company", "contact"}
VALID_ENTITY_TYPES = {"contact"}
def _parse_uuid(val: str, field: str) -> uuid.UUID:
@@ -36,7 +35,7 @@ async def link_file_to_entity(
db: AsyncSession = Depends(get_db),
current_user: dict = Depends(get_current_user),
):
"""Link a file to a company or contact."""
"""Link a file to a contact."""
tenant_id = uuid.UUID(current_user["tenant_id"])
user_id = uuid.UUID(current_user["user_id"])
fid = _parse_uuid(file_id, "file_id")
@@ -140,35 +139,6 @@ async def list_file_links(
]
@company_router.get("/{company_id}/files", dependencies=[Depends(require_permission("entity_links:read"))])
async def list_company_files(
company_id: str,
db: AsyncSession = Depends(get_db),
current_user: dict = Depends(get_current_user),
):
"""List all files linked to a company (reverse link)."""
tenant_id = uuid.UUID(current_user["tenant_id"])
cid = _parse_uuid(company_id, "company_id")
result = await db.execute(
select(EntityLink).where(
EntityLink.tenant_id == tenant_id,
EntityLink.entity_type == "company",
EntityLink.entity_id == cid,
)
)
links = result.scalars().all()
return [
{
"id": str(link.id),
"file_id": str(link.file_id),
"entity_type": link.entity_type,
"entity_id": str(link.entity_id),
}
for link in links
]
@contact_router.get("/{contact_id}/files", dependencies=[Depends(require_permission("entity_links:read"))])
async def list_contact_files(
contact_id: str,
+1 -1
View File
@@ -6,7 +6,7 @@ from pydantic import BaseModel, Field
class EntityLinkRequest(BaseModel):
entity_type: str = Field(..., pattern="^(company|contact)$")
entity_type: str = Field(..., pattern="^contact$")
entity_id: str