:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
refactor(approvals): serve the approval handling mixin from presentation (#125442)
Andersdd9bf6f3cdca
diff --git a/ee/clickhouse/views/experiment_holdouts.py b/ee/clickhouse/views/experiment_holdouts.pyindex 08db18901fd5..5192eb680eef 100644--- a/ee/clickhouse/views/experiment_holdouts.py+++ b/ee/clickhouse/views/experiment_holdouts.py@@ -14,7 +14,7 @@ from posthog.api.shared import UserBasicSerializerfrom products.access_control.backend.presentation.access_control import UserAccessControlSerializerMixinfrom products.approvals.backend.decorators import approval_gate-from products.approvals.backend.mixins import ApprovalHandlingMixin+from products.approvals.backend.presentation.mixins import ApprovalHandlingMixinfrom products.experiments.backend.models.experiment import ExperimentHoldoutfrom products.feature_flags.backend.facade.api import update_flagfrom products.feature_flags.backend.facade.filters import set_holdoutdiff --git a/products/approvals/backend/presentation/__init__.py b/products/approvals/backend/presentation/__init__.pynew file mode 100644index 000000000000..e69de29bb2d1diff --git a/products/approvals/backend/mixins.py b/products/approvals/backend/presentation/mixins.pysimilarity index 91%rename from products/approvals/backend/mixins.pyrename to products/approvals/backend/presentation/mixins.pyindex 99d8af706366..2c85c47c5954 100644--- a/products/approvals/backend/mixins.py+++ b/products/approvals/backend/presentation/mixins.py@@ -1,3 +1,9 @@+"""Approval-gate response handling that other products' viewsets mix in.++It lives in presentation, not in a facade, because a facade must not import DRF. Another+product's presentation may import this module, but not approvals internals.+"""+from rest_framework import statusfrom rest_framework.response import Responsediff --git a/products/experiments/backend/presentation/views.py b/products/experiments/backend/presentation/views.pyindex 3b67670d1d3d..7314ca7c1534 100644--- a/products/experiments/backend/presentation/views.py+++ b/products/experiments/backend/presentation/views.py@@ -78,7 +78,7 @@ from products.access_control.backend.facade.user_access_control import (access_level_satisfied_for_resource,)from products.access_control.backend.presentation.access_control import AccessControlViewSetMixin-from products.approvals.backend.mixins import ApprovalHandlingMixin+from products.approvals.backend.presentation.mixins import ApprovalHandlingMixinfrom products.experiments.backend.experiment_service import ExperimentService, ExperimentVersionConflictfrom products.experiments.backend.facade.api import (get_experiment_health,diff --git a/products/feature_flags/backend/api/feature_flag.py b/products/feature_flags/backend/api/feature_flag.pyindex a7faa7b53104..f8e01c84b4b3 100644--- a/products/feature_flags/backend/api/feature_flag.py+++ b/products/feature_flags/backend/api/feature_flag.py@@ -95,10 +95,10 @@ from products.access_control.backend.presentation.access_control import (UserAccessControlSerializerMixin,)from products.approvals.backend.decorators import approval_gate-from products.approvals.backend.mixins import ApprovalHandlingMixinfrom products.approvals.backend.models import ApprovalPolicyfrom products.approvals.backend.ownership import scope_by_owner_enabledfrom products.approvals.backend.policies import lock_approval_policies+from products.approvals.backend.presentation.mixins import ApprovalHandlingMixinfrom products.cohorts.backend.models.cohort import Cohort, CohortTypefrom products.cohorts.backend.models.util import get_all_cohort_dependenciesfrom products.dashboards.backend.api.dashboard import Dashboarddiff --git a/products/feature_flags/backend/api/scheduled_change.py b/products/feature_flags/backend/api/scheduled_change.pyindex bcc6f232c0bc..fd003030c286 100644--- a/products/feature_flags/backend/api/scheduled_change.py+++ b/products/feature_flags/backend/api/scheduled_change.py@@ -11,8 +11,8 @@ from rest_framework.exceptions import PermissionDeniedfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.shared import UserBasicSerializer-from products.approvals.backend.mixins import ApprovalHandlingMixinfrom products.approvals.backend.models import ChangeRequest, ChangeRequestState+from products.approvals.backend.presentation.mixins import ApprovalHandlingMixinfrom products.approvals.backend.scheduled_changes import gate_scheduled_changefrom products.approvals.backend.serializers import ChangeRequestSummarySerializerfrom products.feature_flags.backend.api.feature_flag import CanEditFeatureFlagdiff --git a/products/product_tours/backend/api/product_tour.py b/products/product_tours/backend/api/product_tour.pyindex fe404a2183a6..69824bcd4745 100644--- a/products/product_tours/backend/api/product_tour.py+++ b/products/product_tours/backend/api/product_tour.py@@ -40,7 +40,7 @@ from posthog.models.user import Userfrom posthog.utils_cors import cors_responsefrom products.access_control.backend.presentation.access_control import AccessControlViewSetMixin-from products.approvals.backend.mixins import ApprovalHandlingMixin+from products.approvals.backend.presentation.mixins import ApprovalHandlingMixinfrom products.feature_flags.backend.api.feature_flag import MinimalFeatureFlagSerializerfrom products.feature_flags.backend.facade.api import create_flag, set_flag_active, update_flagfrom products.feature_flags.backend.facade.config import ConfigFormatErrordiff --git a/products/surveys/backend/api/survey.py b/products/surveys/backend/api/survey.pyindex 6bdea9e2dcc2..e7053ddd0683 100644--- a/products/surveys/backend/api/survey.py+++ b/products/surveys/backend/api/survey.py@@ -72,7 +72,7 @@ from products.access_control.backend.presentation.access_control import ()from products.actions.backend.api.action import ActionSerializer, ActionStepJSONSerializerfrom products.actions.backend.models.action import Action-from products.approvals.backend.mixins import ApprovalHandlingMixin+from products.approvals.backend.presentation.mixins import ApprovalHandlingMixinfrom products.approvals.backend.transactions import gated_atomicfrom products.feature_flags.backend.api.feature_flag import (BEHAVIOURAL_COHORT_FOUND_ERROR_CODE,diff --git a/pyproject.toml b/pyproject.tomlindex deed5e7844c7..548e7125c7e6 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -618,6 +618,12 @@ ignore_imports = ["products.cdp.backend.presentation.serializers -> products.cdp.backend.validation","products.cdp.backend.presentation.hog_functions -> products.cdp.backend.flag_gated_templates","products.cdp.backend.presentation.icons -> products.cdp.backend.services.icons",+ # TODO: approvals presentation wave. The approval handling mixin that other products' viewsets+ # use still reads the gate exceptions and the change request serializer from approvals+ # internals. Delete both entries once the facade exposes the exceptions and a change request+ # contract for presentation to serialize, because ApprovalRequired carries the ChangeRequest model.+ "products.approvals.backend.presentation.mixins -> products.approvals.backend.exceptions",+ "products.approvals.backend.presentation.mixins -> products.approvals.backend.serializers",# TODO: existing violations — fix by routing through facade"products.alerts.backend.presentation.views.alert -> products.alerts.backend.evaluation.contract","products.alerts.backend.presentation.views.alert -> products.alerts.backend.evaluation.detector",@@ -722,7 +728,6 @@ ignore_imports = ["products.experiments.backend.presentation.serializers -> products.experiments.backend.setup_context","products.experiments.backend.presentation.serializers -> products.feature_flags.backend.api.feature_flag","products.experiments.backend.presentation.serializers -> products.feature_flags.backend.models.feature_flag",- "products.experiments.backend.presentation.views -> products.approvals.backend.mixins","products.experiments.backend.presentation.views -> products.experiments.backend.experiment_service","products.experiments.backend.presentation.views -> products.experiments.backend.llm_metric_templates","products.experiments.backend.presentation.views -> products.experiments.backend.models.experiment",