sprint3: dashboard counts per user + import owner_id + export visibility filter
This commit is contained in:
@@ -15,6 +15,7 @@ from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.audit import log_audit
|
||||
from app.core.visibility import apply_visibility_filter
|
||||
from app.models.contact import Contact
|
||||
from app.services.contact_service import _serialize_contact as _contact_to_dict
|
||||
|
||||
@@ -86,6 +87,7 @@ async def import_companies(
|
||||
phone_1=row.get("phone", "").strip() or None,
|
||||
website=row.get("website", "").strip() or None,
|
||||
description=row.get("description", "").strip() or None,
|
||||
owner_id=user_id,
|
||||
created_by=user_id,
|
||||
updated_by=user_id,
|
||||
)
|
||||
@@ -162,6 +164,7 @@ async def import_contacts(
|
||||
email_1=row.get("email", "").strip() or None,
|
||||
phone_1=row.get("phone", "").strip() or None,
|
||||
phone_2=row.get("mobile", "").strip() or None,
|
||||
owner_id=user_id,
|
||||
created_by=user_id,
|
||||
updated_by=user_id,
|
||||
)
|
||||
@@ -215,6 +218,8 @@ async def import_csv(
|
||||
async def export_contacts_csv(
|
||||
db: AsyncSession,
|
||||
tenant_id: uuid.UUID,
|
||||
user_id: uuid.UUID | None = None,
|
||||
is_system_admin: bool = False,
|
||||
) -> str:
|
||||
"""Export contacts as CSV string using unified Contact model fields."""
|
||||
q = (
|
||||
@@ -225,6 +230,10 @@ async def export_contacts_csv(
|
||||
)
|
||||
.order_by(Contact.surname, Contact.firstname)
|
||||
)
|
||||
if user_id:
|
||||
q = await apply_visibility_filter(
|
||||
db, q, "contact", Contact, user_id, tenant_id, is_system_admin
|
||||
)
|
||||
result = await db.execute(q)
|
||||
contacts = result.scalars().all()
|
||||
|
||||
@@ -255,6 +264,8 @@ async def export_contacts_csv(
|
||||
async def export_companies_csv(
|
||||
db: AsyncSession,
|
||||
tenant_id: uuid.UUID,
|
||||
user_id: uuid.UUID | None = None,
|
||||
is_system_admin: bool = False,
|
||||
) -> str:
|
||||
"""Export companies (Contact.type == 'company') as CSV string."""
|
||||
q = (
|
||||
@@ -266,6 +277,10 @@ async def export_companies_csv(
|
||||
)
|
||||
.order_by(Contact.name)
|
||||
)
|
||||
if user_id:
|
||||
q = await apply_visibility_filter(
|
||||
db, q, "contact", Contact, user_id, tenant_id, is_system_admin
|
||||
)
|
||||
result = await db.execute(q)
|
||||
companies = result.scalars().all()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user