Recalculate emissions card on the pipeline console (#3153)¶
Problem¶
780 removed the per-type "Recalculate" button, so the backoffice had no¶
UI left to trigger an emission recalculation. #3142 had to call
POST /sync/recalculate-emissions/{module} from the browser console. The
endpoints and the store actions wrapping them were still there. So was a
recalculate emit chain that nothing ever fired: UploadCard →
UploadCardData / UploadCardFactors → SubmoduleItem /
ModuleUploadsSection → triggerTypeRecalculation, injected from
ModuleConfig.
What shipped¶
- Backend gate.
can_recalculate_emissions/require_pipeline_ops_or_config_editinapp/utils/scoping.pymirrorcan_view_module_flow/require_module_or_config_view. They admitbackoffice.pipeline_operationsedit ORbackoffice.configurationedit, and any other user gets 403. Both recalculate endpoints inapp/api/v1/data_sync.pyuse it. Both keys are bare and super-admin-only (app/models/user.py), so the purehas_permissioncheck agrees with OPA. - Card.
RecalculateEmissionsCard.vuesits next toRecomputeStatsCardonPipelineOperationsConsolePage. It shows only when the user holds either edit key, checked throughauthStore.hasUserPermission. The user picks a module, an optional data entry type (options fromMODULE_SUBMODULES), and a configured year. The confirm dialog reuses thedata_management_recalculate_emissions_*overwrite warning. - With a data entry type, the card calls
initiateEmissionRecalculation. - Without one, it calls
initiateModuleEmissionRecalculation(…, false). The module path passesonly_stale=falsebecause an operator asking for a recalc wants a full one. - The card emits
triggeredand the page refetches its pipeline list. The new pipeline row then streams live, so the user can follow the job. - Deleted. The
recalculateemit, thehasRecalcButton/recalcStatus/recalcRunningprops,triggerTypeRecalculation,recalcTypeRunning, thegetRecalcStatus/recalcTypeRunning/triggerTypeRecalculationprovides, andyearConfig.getRecalcStatus. The module-levelModuleRecalculationDialogand the "recalculation needed" badge stay. - Tests.
backend/tests/unit/utils/test_recalc_emissions_gate.pycovers each edit key passing, and 403 for no permissions, view-only, and a scopedbackoffice.configuration/<cf>edit grant. Denials log the samePermission check deniedline asrequire_permission.frontend/tests/unit/recalculate-emissions-card.spec.tschecks the per-type POST and the module POST withonly_stale=false.