import httpx
import asyncio
async def delete_user_data_workflow(user_email, user_id):
"""Delete user data with GDPR compliance review."""
async with httpx.AsyncClient() as client:
# Gather all data to be deleted
data_summary = await gather_user_data_summary(user_id)
# Request human review
response = await client.post(
"https://api.humancheck.dev/reviews",
headers={
"Authorization": "Bearer your-api-key-here",
"Content-Type": "application/json"
},
json={
"task_type": "data_deletion",
"proposed_action": f"Delete all data for user: {user_email} (ID: {user_id})",
"agent_reasoning": f"GDPR deletion request. Data includes: {data_summary['summary']}",
"confidence_score": 1.0, # High confidence in request validity
"urgency": "medium",
"metadata": {
"user_id": user_id,
"user_email": user_email,
"request_type": "gdpr",
"data_summary": data_summary,
"data_points": data_summary["count"],
"estimated_deletion_time": data_summary["estimated_time"]
},
"blocking": True # Wait for verification
}
)
review = response.json()
# Get decision
decision = review.get("decision")
if not decision:
decision_response = await client.get(
f"https://api.humancheck.dev/reviews/{review['id']}/decision"
)
decision = decision_response.json()
if decision["decision_type"] == "approve":
# Delete all user data
await delete_user_data(user_id, data_summary)
return {"status": "deleted", "user_id": user_id}
else:
return {
"status": "rejected",
"reason": decision.get("notes"),
"user_id": user_id
}
async def gather_user_data_summary(user_id):
"""Gather summary of all user data."""
# Query database for user data
data_points = {
"profile": await count_user_profiles(user_id),
"orders": await count_user_orders(user_id),
"messages": await count_user_messages(user_id),
"files": await count_user_files(user_id),
"logs": await count_user_logs(user_id)
}
total_count = sum(data_points.values())
return {
"summary": f"{total_count} data points across {len([k for k, v in data_points.items() if v > 0])} categories",
"count": total_count,
"breakdown": data_points,
"estimated_time": f"{total_count * 0.1:.1f} seconds"
}
async def delete_user_data(user_id, data_summary):
"""Delete all user data."""
# Delete in order to maintain referential integrity
await delete_user_files(user_id)
await delete_user_messages(user_id)
await delete_user_orders(user_id)
await delete_user_logs(user_id)
await delete_user_profile(user_id)
# Log deletion
await log_deletion(user_id, data_summary)