: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
feat(admin): show team and organization on data deletion request detail (#123341)
Paweł Szczur7070bd1dbbd4
diff --git a/posthog/admin/admins/data_deletion_request_admin.py b/posthog/admin/admins/data_deletion_request_admin.pyindex 3c49935db504..7200fefc4bae 100644--- a/posthog/admin/admins/data_deletion_request_admin.py+++ b/posthog/admin/admins/data_deletion_request_admin.py@@ -24,6 +24,7 @@ from posthog.models.data_deletion_request import (invalidate_compiled_predicate_cache,refresh_deletion_stats,)+from posthog.models.team import TeamCRITERIA_FIELDS = {"request_type",@@ -215,6 +216,7 @@ class DataDeletionRequestAdmin(admin.ModelAdmin):list_filter = ("request_type", "status", "requires_approval", "approved", "approved_automatically")search_fields = ("team_id", "events", "properties", "person_properties", "notes")readonly_fields = (+ "team_details","status","count","part_count",@@ -334,6 +336,30 @@ class DataDeletionRequestAdmin(admin.ModelAdmin):created += 1messages.success(request, f"Duplicated {created} request(s) as new draft(s).")+ @admin.display(description="Team")+ def team_details(self, obj: DataDeletionRequest) -> str:+ team = Team.objects.select_related("organization").filter(id=obj.team_id).first()+ if team is None:+ return format_html("{} <em>(team not found)</em>", obj.team_id)+ return format_html(+ '<a href="{}">{}</a> {} · organization <a href="{}">{}</a> {}',+ reverse("admin:posthog_team_change", args=[team.pk]),+ team.pk,+ team.name,+ reverse("admin:posthog_organization_change", args=[team.organization_id]),+ team.organization_id,+ team.organization.name,+ )++ def get_fieldsets(self, request, obj=None):+ fieldsets = super().get_fieldsets(request, obj)+ if obj is None:+ return fieldsets+ return [+ (name, {**options, "fields": tuple("team_details" if f == "team_id" else f for f in options["fields"])})+ for name, options in fieldsets+ ]+@admin.display(description="Last Dagster run")def last_dagster_run(self, obj: DataDeletionRequest) -> str:"""Link to the Dagster run of the latest execution attempt, for debugging in-flight requests."""diff --git a/posthog/admin/test_data_deletion_request_admin.py b/posthog/admin/test_data_deletion_request_admin.pyindex 0571c0b5759a..cf9ac683bc4c 100644--- a/posthog/admin/test_data_deletion_request_admin.py+++ b/posthog/admin/test_data_deletion_request_admin.py@@ -10,6 +10,7 @@ from django.contrib.auth.models import Groupfrom django.contrib.messages import get_messagesfrom django.contrib.messages.storage.fallback import FallbackStoragefrom django.test import RequestFactory, SimpleTestCase, override_settings+from django.urls import reversefrom django.utils import timezonefrom bs4 import BeautifulSoup@@ -814,6 +815,39 @@ class TestDataDeletionRequestAdminChangeFormScripts(BaseTest):},)+ @parameterized.expand([("existing_team", True), ("deleted_team", False)])+ def test_change_view_shows_team_and_organization(self, _name, team_exists):+ team_id = self.team.id if team_exists else 999999+ request = DataDeletionRequest.objects.create(+ team_id=team_id,+ request_type=RequestType.EVENT_REMOVAL,+ events=["$pageview"],+ start_time=datetime.now() - timedelta(days=7),+ end_time=datetime.now(),+ )++ response = self.client.get(f"/admin/posthog/datadeletionrequest/{request.pk}/change/")++ self.assertEqual(response.status_code, 200)+ team_field = BeautifulSoup(response.content, "html.parser").select_one(".field-team_details .readonly")+ assert team_field is not None+ links = {a.get("href"): a.get_text() for a in team_field.select("a")}+ if team_exists:+ self.assertEqual(+ links,+ {+ reverse("admin:posthog_team_change", args=[self.team.id]): str(self.team.id),+ reverse("admin:posthog_organization_change", args=[self.organization.id]): str(+ self.organization.id+ ),+ },+ )+ self.assertIn(self.team.name, team_field.get_text())+ self.assertIn(self.organization.name, team_field.get_text())+ else:+ self.assertEqual(links, {})+ self.assertIn(f"{team_id} (team not found)", team_field.get_text())+@parameterized.expand([("naive", "2025-01-08 08:12:00", ("2025-01-08", "08:12:00")),