Files
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

46 lines
1.8 KiB
Python

from rest_framework import status
from rest_framework.response import Response
from products.approvals.backend.exceptions import ApprovalRequired, PolicyConflict
from products.approvals.backend.serializers import ChangeRequestSerializer
class ApprovalHandlingMixin:
"""
Mixin for ViewSets to handle approval-gate exceptions raised from decorated serializers.
Intercepts ApprovalRequired (409) and PolicyConflict (400) raised by the @approval_gate
decorator on serializer methods and converts them into the same responses the viewset path
produces (see decorators._result_to_response), so both paths share one contract.
"""
def handle_exception(self, exc: Exception) -> Response:
if isinstance(exc, ApprovalRequired):
return Response(
{
"code": exc.error_code,
"status": "approval_required",
"detail": exc.message,
"message": exc.message,
"resource_type": exc.change_request.resource_type,
"resource_id": exc.change_request.resource_id,
"change_request_id": str(exc.change_request.id),
"change_request": ChangeRequestSerializer(exc.change_request).data,
"required_approvers": exc.required_approvers,
},
status=status.HTTP_409_CONFLICT,
)
if isinstance(exc, PolicyConflict):
return Response(
{
"code": "policy_conflict",
"error": exc.message,
"conflicting_policies": exc.conflicting_policies,
"guidance": exc.guidance,
},
status=status.HTTP_400_BAD_REQUEST,
)
return super().handle_exception(exc) # type: ignore[misc]