Skip to content

: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.

feat(admin): add ai terms and conditions admin page (#124462)

Peter Kirkhamd67780841e0a
diff --git a/posthog/admin/admins/organization_ai_terms_admin.py b/posthog/admin/admins/organization_ai_terms_admin.py
new file mode 100644
index 000000000000..f1ad808a6a98
--- /dev/null
+++ b/posthog/admin/admins/organization_ai_terms_admin.py
@@ -0,0 +1,70 @@
+from typing import cast
+
+from django import forms
+from django.contrib import admin
+from django.http import HttpRequest
+
+from posthog.admin.paginators.no_count_paginator import NoCountPaginator
+from posthog.models.organization import Organization, OrganizationAITerms
+from posthog.models.user import User
+
+
+def _desktop_beta_terms_accepted(organization: OrganizationAITerms) -> bool:
+ # Deferred: the tasks facade pulls in a heavy dependency tree kept off the web startup path.
+ from products.tasks.backend.facade import api as tasks_facade # noqa: PLC0415
+
+ return tasks_facade.get_desktop_beta_terms_acceptance(organization.id).is_desktop_beta_terms_accepted
+
+
+class OrganizationAITermsForm(forms.ModelForm):
+ revoke_desktop_beta_terms = forms.BooleanField(
+ required=False,
+ label="Revoke PostHog Desktop beta terms",
+ help_text="An org admin can accept the terms again in organization settings.",
+ )
+
+ class Meta:
+ model = OrganizationAITerms
+ fields = ["is_ai_data_processing_approved"]
+ labels = {"is_ai_data_processing_approved": "In-app AI data processing approved"}
+
+
[email protected](OrganizationAITerms)
+class OrganizationAITermsAdmin(admin.ModelAdmin):
+ form = OrganizationAITermsForm
+ show_full_result_count = False
+ paginator = NoCountPaginator
+ list_display = ("id", "name", "is_ai_data_processing_approved")
+ list_display_links = ("id", "name")
+ search_fields = ("id", "name", "=team__id")
+ readonly_fields = ("id", "name", "desktop_beta_terms_display")
+
+ def has_add_permission(self, request: HttpRequest) -> bool:
+ return False
+
+ def has_delete_permission(self, request: HttpRequest, obj: OrganizationAITerms | None = None) -> bool:
+ return False
+
+ def get_fields(self, request: HttpRequest, obj: OrganizationAITerms | None = None) -> tuple[str, ...]:
+ fields = ("id", "name", "is_ai_data_processing_approved", "desktop_beta_terms_display")
+ if obj is not None and _desktop_beta_terms_accepted(obj):
+ return (*fields, "revoke_desktop_beta_terms")
+ return fields
+
+ @admin.display(description="PostHog Desktop beta terms")
+ def desktop_beta_terms_display(self, organization: OrganizationAITerms) -> str:
+ return "Accepted" if _desktop_beta_terms_accepted(organization) else "Not accepted"
+
+ def save_model(
+ self, request: HttpRequest, obj: OrganizationAITerms, form: OrganizationAITermsForm, change: bool
+ ) -> None:
+ if "is_ai_data_processing_approved" in form.changed_data:
+ # Save through the concrete model, because the activity log and the Organization signals
+ # listen for sender=Organization and ignore a save that this proxy model sends.
+ organization = Organization.objects.get(pk=obj.pk)
+ organization.is_ai_data_processing_approved = obj.is_ai_data_processing_approved
+ organization.save(update_fields=["is_ai_data_processing_approved"])
+ if form.cleaned_data.get("revoke_desktop_beta_terms"):
+ from products.tasks.backend.facade import api as tasks_facade # noqa: PLC0415
+
+ tasks_facade.revoke_desktop_beta_terms(obj.id, cast(User, request.user))
diff --git a/posthog/migrations/1415_organizationaiterms.py b/posthog/migrations/1415_organizationaiterms.py
new file mode 100644
index 000000000000..e0f99abd93ad
--- /dev/null
+++ b/posthog/migrations/1415_organizationaiterms.py
@@ -0,0 +1,24 @@
+# Generated by Django 5.2.18 on 2026-10-27 22:17
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("posthog", "1414_remove_filesystem_rows_for_deleted_insights"),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name="OrganizationAITerms",
+ fields=[],
+ options={
+ "verbose_name": "AI terms and conditions",
+ "verbose_name_plural": "AI terms and conditions",
+ "proxy": True,
+ "indexes": [],
+ "constraints": [],
+ },
+ bases=("posthog.organization",),
+ ),
+ ]
diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txt
index 352f862057bc..8168d5266ba4 100644
--- a/posthog/migrations/max_migration.txt
+++ b/posthog/migrations/max_migration.txt
@@ -1 +1 @@
-1414_remove_filesystem_rows_for_deleted_insights
+1415_organizationaiterms
diff --git a/posthog/models/organization.py b/posthog/models/organization.py
index 014689b96114..92ca9095a052 100644
--- a/posthog/models/organization.py
+++ b/posthog/models/organization.py
@@ -786,6 +786,14 @@ def _start_billing_active_sync_workflow(organization_id: str) -> None:
logger.warning("billing_active_state_sync_dispatch_failed", organization_id=organization_id, exc_info=True)
+class OrganizationAITerms(Organization):
+ # Gives staff one admin page for the AI terms an organization accepts, across products.
+ class Meta:
+ proxy = True
+ verbose_name = "AI terms and conditions"
+ verbose_name_plural = "AI terms and conditions"
+
+
class OrganizationMembership(ModelActivityMixin, UUIDTModel):
class Level(models.IntegerChoices):
"""Keep in sync with TeamMembership.Level (only difference being projects not having an Owner)."""
diff --git a/products/tasks/backend/facade/api.py b/products/tasks/backend/facade/api.py
index a2112f9a806a..783e8e4c73de 100644
--- a/products/tasks/backend/facade/api.py
+++ b/products/tasks/backend/facade/api.py
@@ -57,6 +57,8 @@ from posthog.dataclasses import frozen
from posthog.event_usage import groups
from posthog.ingress.contracts import WebhookDelivery
from posthog.models import Team, User
+from posthog.models.activity_logging.activity_log import Change, Detail, log_activity
+from posthog.models.activity_logging.model_activity import get_was_impersonated
from posthog.models.comment.comment import CANVAS_COMMENT_SCOPES
from posthog.models.integration import Integration
from posthog.models.integration.codex import CodexAccessGrant, CodexAuthError, CodexReauthRequired, CodexUserIntegration
@@ -2599,6 +2601,38 @@ def accept_desktop_beta_terms(organization_id: UUID, user_id: int) -> contracts.
return contracts.DesktopBetaTermsAcceptanceDTO(is_desktop_beta_terms_accepted=True)
+def revoke_desktop_beta_terms(organization_id: UUID, user: User) -> contracts.DesktopBetaTermsAcceptanceDTO:
+ with transaction.atomic():
+ acceptance = DesktopBetaTermsAcceptance.objects.filter(organization_id=organization_id).first()
+ if acceptance is not None:
+ acceptance.delete()
+ # The deleted row is the only record of who accepted and when, so the audit entry keeps both.
+ log_activity(
+ organization_id=organization_id,
+ team_id=None,
+ user=user,
+ was_impersonated=get_was_impersonated(),
+ item_id=organization_id,
+ scope="Organization",
+ activity="updated",
+ detail=Detail(
+ changes=[
+ Change(
+ type="Organization",
+ action="revoked",
+ field="PostHog Desktop beta terms",
+ before={
+ "accepted_by_user_id": acceptance.accepted_by_user_id,
+ "accepted_at": acceptance.accepted_at.isoformat(),
+ },
+ after=None,
+ )
+ ]
+ ),
+ )
+ return contracts.DesktopBetaTermsAcceptanceDTO(is_desktop_beta_terms_accepted=False)
+
+
# --- Sandbox environments (presentation CRUD) ---
# Visibility: an environment is reachable by a team member if it is non-private, or it is
# theirs (``created_by``). ``list`` additionally hides ``internal`` environments.