|
| 1 | +# anonymous-data-admin Specification |
| 2 | + |
| 3 | +## Purpose |
| 4 | + |
| 5 | +Provides Django admin interface integration for AnonymousValues, allowing administrators and dataset owners to inspect, filter, search, view, edit, and navigate to anonymous records. |
| 6 | + |
| 7 | +## Requirements |
| 8 | + |
| 9 | +### Requirement: AnonymousValues model admin registration and changelist display |
| 10 | +The system SHALL register `AnonymousValues` in the Django admin site via `AnonymousValuesAdmin`. The changelist view SHALL display the following columns: |
| 11 | +- `id`: UUID of the record |
| 12 | +- `owner`: username of the dataset's owner |
| 13 | +- `dataset`: slug of the associated dataset |
| 14 | +- `set_name`: logical submission set name (e.g. `"places"`, `"comments"`) |
| 15 | +- `data`: formatted JSON content of the anonymous data blob |
| 16 | + |
| 17 | +#### Scenario: Admin changelist shows anonymous record columns |
| 18 | +- **WHEN** an admin navigates to the `AnonymousValues` changelist in Django admin |
| 19 | +- **THEN** each row SHALL display the record's UUID, the dataset owner's username, the dataset slug, the set name, and the data blob |
| 20 | + |
| 21 | +### Requirement: Changelist filtering and search |
| 22 | +The `AnonymousValuesAdmin` SHALL support filtering and full-text searching: |
| 23 | +- Filtering by dataset slug via `DataSetFilter` |
| 24 | +- Filtering by `set_name` |
| 25 | +- Searching by `set_name` and `data` content |
| 26 | + |
| 27 | +#### Scenario: Filter anonymous values by dataset slug |
| 28 | +- **WHEN** an admin filters by a dataset slug in the `AnonymousValues` changelist |
| 29 | +- **THEN** only `AnonymousValues` belonging to that dataset SHALL be displayed |
| 30 | + |
| 31 | +#### Scenario: Filter anonymous values by set_name |
| 32 | +- **WHEN** an admin filters by a `set_name` (e.g. `"comments"`) in the `AnonymousValues` changelist |
| 33 | +- **THEN** only `AnonymousValues` with that `set_name` SHALL be displayed |
| 34 | + |
| 35 | +#### Scenario: Search anonymous values by data content |
| 36 | +- **WHEN** an admin searches for a keyword that appears in `data` (e.g. `"Asian"` or `"25-34"`) |
| 37 | +- **THEN** matching `AnonymousValues` records SHALL be returned in search results |
| 38 | + |
| 39 | +### Requirement: Owner-scoped access for non-superusers |
| 40 | +For users who are not superusers, `AnonymousValuesAdmin` SHALL restrict the queryset to records where `dataset__owner=request.user`. |
| 41 | + |
| 42 | +#### Scenario: Superuser sees all anonymous records |
| 43 | +- **WHEN** a superuser accesses the `AnonymousValues` admin changelist |
| 44 | +- **THEN** all `AnonymousValues` across all datasets SHALL be visible |
| 45 | + |
| 46 | +#### Scenario: Non-superuser sees only owned dataset anonymous records |
| 47 | +- **WHEN** an authenticated non-superuser accesses the `AnonymousValues` admin changelist |
| 48 | +- **THEN** only `AnonymousValues` belonging to datasets owned by that user SHALL be visible |
| 49 | + |
| 50 | +### Requirement: Change form with JSON editing |
| 51 | +The `AnonymousValuesAdmin` change and add form SHALL allow viewing and editing `AnonymousValues` fields: |
| 52 | +- `id` SHALL be a read-only field |
| 53 | +- `dataset` SHALL use a raw ID lookup field (`raw_id_fields`) |
| 54 | +- `data` SHALL use a JSON editing widget (`PrettyAceWidget`) with JSON syntax validation on save |
| 55 | + |
| 56 | +#### Scenario: Editing anonymous values in admin form |
| 57 | +- **WHEN** an admin edits an `AnonymousValues` record with valid JSON in the `data` field |
| 58 | +- **THEN** the changes SHALL be validated and saved to the database |
| 59 | + |
| 60 | +#### Scenario: Invalid JSON in data field is rejected |
| 61 | +- **WHEN** an admin submits invalid JSON in the `data` field |
| 62 | +- **THEN** form validation SHALL raise an error and prevent saving |
| 63 | + |
| 64 | +### Requirement: Dataset admin navigation link |
| 65 | +`DataSetAdmin` SHALL include an `anonymous_values` read-only field that renders an HTML link pointing to the `AnonymousValues` changelist filtered by that dataset's slug (`/admin/sa_api_v2/anonymousvalues/?dataset={slug}`). |
| 66 | + |
| 67 | +#### Scenario: Dataset change form renders anonymous values link |
| 68 | +- **WHEN** an admin views a `DataSet` change form in Django admin |
| 69 | +- **THEN** the `anonymous_values` read-only field SHALL render a link to `/admin/sa_api_v2/anonymousvalues/?dataset={slug}` |
0 commit comments