2176 — (planner) Error 403 on usage update¶
Problem¶
Since #951 (PR #2106, provenance-keyed data-entry field permissions), moving
the "% of reference year" slider in any prefilled Project Planner module
(Equipment, Local/rooms, …) returned 403 FIELD_NOT_EDITABLE on every
change, and the global 403 hook then hard-redirected the user to
/unauthorized.
Root cause¶
Two independent defects stacked:
- Backend. The slider sends the generic data-entry
PATCH …/modules/{module}/{submodule}/{item_id}with{percentage_of_reference_year}. Planner-prefilled rows reuse calculator data-entry types (< 80), sois_policy_exempt()does not exempt them; the #951 review fix only mapped theirPLANNER_SNAPSHOTsource to the USER provenance branch. The USER whitelists come verbatim from the #951 issue matrix, which never mentionspercentage_of_reference_year— the field is planner-only and not a DTO field on any module (it rides throughDataEntryUpdate.unflatten_payloadintodata). Every actual slider change therefore diffed as a locked field. Planner headcount kept working becauseplanner_headcount(≥ 80) is type-exempt. - Frontend.
http.ts's 403 hook assumeddetailis a string;FIELD_NOT_EDITABLEsends{code, fields}, so.matchthrew, was swallowed, and the hook redirected to/unauthorized— evicting the user from the planner for a row-level denial.
Fix¶
backend/app/core/data_entry_permissions.py: newPLANNER_SNAPSHOT_WRITABLE_FIELDS = {"percentage_of_reference_year"}andwritable_fields_for_row(module_type, data_entry_type, source), which unions the provenance whitelist,ALWAYS_WRITABLE_FIELDS, and — forPLANNER_SNAPSHOT-sourced rows only — the planner scaling field. The field stays out of thePERMISSIONSmatrix on purpose:_validate_registry()checks matrix fields against each module's update DTO, where it does not exist. Snapshot rows otherwise keep exactly the USER-branch field caps (narrow fix, confirmed over full row exemption).backend/app/workflows/carbon_report_module.py: the update guard resolvesallowedviawritable_fields_for_row(...)instead of the inlineeditable_fields(...) | ALWAYS_WRITABLE_FIELDS.frontend/src/api/http.ts: when the parsed 403detailis an object (row-level business denial:FIELD_NOT_EDITABLE,ROW_NOT_DELETABLE), the hook returns without notifying/redirecting so ky throwsHTTPErrorand the caller's catch surfaces its own save-error toast. String details keep the existing/unauthorizedredirect.
The slider only renders when row.reference_kg_co2eq != null
(ModuleTable.vue), i.e. only on PLANNER_SNAPSHOT rows — keying the grant
on that source covers every slider row, including rows a user adds manually
in the planner (no reference entry → no slider).
Regression test¶
backend/tests/unit/workflows/test_carbon_report_module_permissions.py::
test_update_planner_snapshot_row_percentage_succeeds — a
PLANNER_SNAPSHOT equipment row PATCHed with
{"percentage_of_reference_year": 50} must reach
DataEntryService.update; 403s without the fix.
Related¶
- 951-edit-rights-per-dataset-permissions.md — the permission layer this amends.