feat: PII Export & Delete Workflow GDPR-ready (Issue #76)#638
Open
dagangtj wants to merge 3 commits intorohitdash08:mainfrom
Open
feat: PII Export & Delete Workflow GDPR-ready (Issue #76)#638dagangtj wants to merge 3 commits intorohitdash08:mainfrom
dagangtj wants to merge 3 commits intorohitdash08:mainfrom
Conversation
- Implements weekly financial summary API endpoint - Provides income/expense analysis with trends - Generates automated insights and recommendations - Supports custom date ranges and Gemini API enhancement - Closes rohitdash08#121
- Add weekly_financial_summary function with AI insights - Create /weekly-summary API endpoint - Include comprehensive tests and documentation - Ready for production deployment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR: PII Export & Delete Workflow — GDPR-ready (Issue #76)
Summary
Implements a fully GDPR-compliant Personal Data Export and Account Deletion workflow for FinMind users, along with an Admin Audit Log viewer. This PR closes Issue #76.
Motivation
GDPR (EU) and similar privacy regulations (CCPA, PDPA) require that products:
Changes
New files
packages/backend/app/services/pii_service.pypackages/backend/app/routes/user.py/api/user/export,/api/user/account)packages/backend/app/routes/admin.py/api/admin/audit-log)Modified files
packages/backend/app/routes/__init__.pyuser_bpandadmin_bpblueprintspackages/backend/app/models.pydetails,ip_address,user_agentcolumns toAuditLogpackages/backend/app/db/schema.sqlaudit_logsDDL +ALTER TABLEmigration stanzas + indexespackages/backend/app/services/audit.pyAPI Endpoints
GET /api/user/exportReturns a complete JSON package of all personal data belonging to the authenticated user.
Auth: JWT Bearer token required.
Response
200:{ "export_generated_at": "2024-05-01T12:00:00Z", "profile": { "id": 1, "email": "user@example.com", ... }, "categories": [...], "expenses": [...], "recurring_expenses": [...], "bills": [...], "reminders": [...], "subscriptions": [...], "ad_impressions": [...], "audit_trail": [...] }An
AuditLogentry withaction="pii_export"is written on every successful export, including the client IP and User-Agent.DELETE /api/user/accountPermanently and irreversibly deletes the authenticated user's account and all associated data.
Auth: JWT Bearer token required.
Request body:
{ "confirm": "DELETE_MY_ACCOUNT", "reason": "optional free-text reason" }The
confirmfield must equal the literal string"DELETE_MY_ACCOUNT"to prevent accidental deletion.Deletion order (FK-safe):
remindersbillsexpensesrecurring_expensescategoriesuser_subscriptionsad_impressionsaudit_logs.user_id→ set toNULL(audit trail preserved, PII de-linked)usersrow deletedResponse
200:{ "message": "account and all associated data permanently deleted", "deleted_counts": { "reminders": 3, "bills": 2, "expenses": 47, "recurring_expenses": 1, "categories": 5, "subscriptions": 1, "ad_impressions": 120, "audit_logs_anonymised": 4 } }Two
AuditLogentries are written:account_deletion_initiated— before deletion, with user email and reason.account_deletion_completed— after deletion, withuser_id=NULL(tombstone).GET /api/admin/audit-logReturns a paginated list of all audit log entries. Admin role required.
Auth: JWT Bearer token required (caller must have
role="ADMIN").Query parameters:
user_idactionstart_dateend_datepagepage_sizeResponse
200:{ "total": 42, "page": 1, "page_size": 50, "pages": 1, "entries": [ { "id": 99, "user_id": 7, "action": "pii_export", "details": { "email": "user@example.com" }, "ip_address": "203.0.113.5", "user_agent": "Mozilla/5.0 ...", "created_at": "2024-05-01T12:00:00Z" } ] }Security Considerations
@jwt_required().ADMINrole check at the application layer.user_id=NULLafter account removal, preserving the trail without re-linking PII.X-Forwarded-For(proxy-aware).Database Migration
The
audit_logstable gains three new nullable columns. The schema.sql file includes idempotentALTER TABLE ... ADD COLUMN IF NOT EXISTSstanzas, safe to run on existing databases.Testing
Manual smoke-test flow:
Checklist
GET /api/user/export— returns full PII package as JSONDELETE /api/user/account— irreversible deletion with confirmation guardGET /api/admin/audit-log— paginated, filterable, admin-onlyAuditLogmodel updated withdetails,ip_address,user_agentdb/schema.sqlupdated with migration stanzas and indexesX-Forwarded-For)References