Skip to content

feat: add subject access request (SAR) data export for staff console#663

Open
Joe-Heffer-Shef wants to merge 2 commits into
mainfrom
feat/582-sar-user-data-export
Open

feat: add subject access request (SAR) data export for staff console#663
Joe-Heffer-Shef wants to merge 2 commits into
mainfrom
feat/582-sar-user-data-export

Conversation

@Joe-Heffer-Shef

@Joe-Heffer-Shef Joe-Heffer-Shef commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements #582 — a staff console action that generates a UK GDPR Article 15 subject access export for a given user, as JSON.

Screenshots

image image image

Changes

This wires up DataProtectionEvent.EventType.EXPORT, which was already defined in the data protection audit log but documented as "reserved" (docs/data-protection.md) pending this exact flow.

  • New UserService.export_personal_data(user) builds a dict of the user's own data: profile fields, organisation memberships (their own only), and projects they created — reusing the same queries as the existing ConsoleUserDetailView.
  • New ConsoleExportUserDataView (staff-only) follows the existing GET-confirm / POST-act console pattern used by ConsoleDeleteUserView. POST returns the export as a downloadable JSON attachment and merges in the user's data_protection_history (their own audit events, with staff identities stripped), then records a new export audit event via data_protection_service.record_event.
  • Export is blocked for already-anonymised (erased) accounts, since there's nothing meaningful left to export.
  • New "Export data (SAR)" button on the user detail page.

Scope note

The issue's suggested scope mentions survey responses and invitations, but in this schema neither SurveyResponse nor Invitation has a foreign key to User — responses are anonymous (collected via invitation token) and invitations only carry a raw email address. So there's no account-linked survey/invitation data to include; the real personal-data surface for a User account is profile fields, their own organisation memberships, projects they created, and their own data protection history. This export deliberately excludes other organisation members' data even where membership records are shared.

Test plan

  • python manage.py test home/tests/test_console_views.py --failfast — new tests cover: GET confirmation, POST JSON download + content, exclusion of other members' personal data, audit event recording, 403 for erased accounts, staff-only access, anonymous redirect.
  • python manage.py test home/tests --parallel=auto --failfast — full home suite passes (114 tests).
  • python manage.py check / makemigrations --check --dry-run — no issues, no missing migrations.
  • Manually verified end-to-end against a running dev server: logged in as staff, loaded /console/users/<pk>/, confirmed the "Export data (SAR)" button and confirmation page render, POSTed to download the JSON export with correct Content-Disposition/Content-Type and expected data, and confirmed the new export event appears in /console/data-protection/.

🤖 Generated with Claude Code

Wires up the reserved DataProtectionEvent.EventType.EXPORT flow (UK GDPR
Art. 15). Staff can generate a JSON export of a user's own profile,
organisation memberships, projects created, and data protection history
from a new console view, without including other users' personal data.

Closes #582.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Joe-Heffer-Shef

This comment was marked as resolved.

@Joe-Heffer-Shef Joe-Heffer-Shef linked an issue Jul 8, 2026 that may be closed by this pull request
5 tasks
@Joe-Heffer-Shef Joe-Heffer-Shef self-assigned this Jul 8, 2026
@Joe-Heffer-Shef Joe-Heffer-Shef added the data-protection Ethics, privacy, data sharing, and data management label Jul 8, 2026
@Joe-Heffer-Shef
Joe-Heffer-Shef requested a review from twinkarma July 8, 2026 15:04

@twinkarma twinkarma left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data-protection Ethics, privacy, data sharing, and data management

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subject Access Request (SAR): export all personal data for a user

2 participants