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.

chore(signals): expose SignalTeamConfig in Django admin (#69895)

Vojta Bartoša998e6297f0c
diff --git a/products/signals/backend/admin.py b/products/signals/backend/admin.py
index a96519cbbfa3..b681d8f6e632 100644
--- a/products/signals/backend/admin.py
+++ b/products/signals/backend/admin.py
@@ -1,8 +1,18 @@
+import re
+
+from django import forms
from django.contrib import admin
from django.urls import reverse
from django.utils.html import format_html
-from .models import SignalReport, SignalReportArtefact, SignalScoutConfig, SignalScoutRun, SignalScratchpad
+from .models import (
+ SignalReport,
+ SignalReportArtefact,
+ SignalScoutConfig,
+ SignalScoutRun,
+ SignalScratchpad,
+ SignalTeamConfig,
+)
class SignalReportArtefactInline(admin.TabularInline):
@@ -152,3 +162,56 @@ class SignalScratchpadAdmin(admin.ModelAdmin):
reverse("admin:posthog_team_change", args=[scratchpad.team.pk]),
scratchpad.team.name,
)
+
+
+# Slack channel ids are uppercase alphanumerics starting with C/G/D (public/private/DM). The notifier
+# keys off the id (the part before "|"), so a display name or "#name" saved here silently drops every
+# team-default notification — reject those shapes before they reach the DB.
+_SLACK_CHANNEL_ID_RE = re.compile(r"^[CGD][A-Z0-9]{6,}$")
+
+
+class SignalTeamConfigAdminForm(forms.ModelForm):
+ class Meta:
+ model = SignalTeamConfig
+ fields = "__all__"
+
+ def clean_default_slack_notification_channel(self) -> str | None:
+ value = (self.cleaned_data.get("default_slack_notification_channel") or "").strip()
+ if not value:
+ return None
+ # Only the channel id is required; an optional "|#name" suffix is allowed for readability.
+ channel_id = value.split("|", 1)[0].strip()
+ if not _SLACK_CHANNEL_ID_RE.match(channel_id):
+ raise forms.ValidationError(
+ "Use 'CHANNELID|#name' form, or just the channel id. The id looks like 'C0123ABCD' "
+ "(copy it from the channel's details in Slack) — a '#name' won't work."
+ )
+ return value
+
+
[email protected](SignalTeamConfig)
+class SignalTeamConfigAdmin(admin.ModelAdmin):
+ form = SignalTeamConfigAdminForm
+ list_display = (
+ "id",
+ "team_link",
+ "default_autostart_priority",
+ "default_slack_notification_channel",
+ "updated_at",
+ )
+ list_display_links = ("id",)
+ search_fields = ("id", "team__name", "team__organization__name", "default_slack_notification_channel")
+ raw_id_fields = ("team",)
+ # autostart_base_branches is free-form JSON with no form-level shape check; a non-dict value would
+ # crash the autostart worker (it calls .get() on it). It's owned by the API, so keep it read-only here.
+ readonly_fields = ("id", "autostart_base_branches", "created_at", "updated_at")
+ list_select_related = ("team", "team__organization")
+ show_full_result_count = False
+
+ @admin.display(description="Team")
+ def team_link(self, config: SignalTeamConfig):
+ return format_html(
+ '<a href="{}">{}</a>',
+ reverse("admin:posthog_team_change", args=[config.team.pk]),
+ config.team.name,
+ )