: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(sharing): log activity when dashboard sharing is toggled (#58964)
danazou6a58e47a90d2
diff --git a/frontend/src/scenes/dashboard/dashboardActivityDescriber.tsx b/frontend/src/scenes/dashboard/dashboardActivityDescriber.tsxindex 9ba6636aa670..1114f86bad30 100644--- a/frontend/src/scenes/dashboard/dashboardActivityDescriber.tsx+++ b/frontend/src/scenes/dashboard/dashboardActivityDescriber.tsx@@ -226,6 +226,39 @@ export function dashboardActivityDescriber(logItem: ActivityLogItem, asNotificat}}+ if (logItem.activity === 'sharing enabled') {+ return {+ description: (+ <>+ <strong className="ph-no-capture">{userNameForLogItem(logItem)}</strong> shared{' '}+ {asNotification ? 'your' : 'the'} dashboard {nameAndLink(logItem)}+ </>+ ),+ }+ }++ if (logItem.activity === 'sharing disabled') {+ return {+ description: (+ <>+ <strong className="ph-no-capture">{userNameForLogItem(logItem)}</strong> deleted shared link for{' '}+ {asNotification ? 'your' : 'the'} dashboard {nameAndLink(logItem)}+ </>+ ),+ }+ }++ if (logItem.activity === 'access token refreshed') {+ return {+ description: (+ <>+ <strong className="ph-no-capture">{userNameForLogItem(logItem)}</strong> refreshed the shared link+ for {asNotification ? 'your' : 'the'} dashboard {nameAndLink(logItem)}+ </>+ ),+ }+ }+if (logItem.activity === 'share_login_success') {const afterData = logItem.detail.changes?.[0]?.after as anyconst clientIp = afterData?.client_ip || 'unknown IP'diff --git a/posthog/api/sharing.py b/posthog/api/sharing.pyindex 752f07b8871f..8a4594ab786e 100644--- a/posthog/api/sharing.py+++ b/posthog/api/sharing.py@@ -422,6 +422,28 @@ class SharingConfigurationViewSet(TeamAndOrgViewSetMixin, mixins.ListModelMixin,),)+ if context.get("dashboard") and "enabled" in request.data:+ log_activity(+ organization_id=None,+ team_id=self.team_id,+ user=cast(User, self.request.user),+ was_impersonated=is_impersonated_session(self.request),+ item_id=instance.dashboard.pk,+ scope="Dashboard",+ activity="sharing " + ("enabled" if serializer.data.get("enabled") else "disabled"),+ detail=Detail(+ name=instance.dashboard.name,+ changes=[+ Change(+ type="Dashboard",+ action="changed",+ field="sharing",+ after=serializer.data.get("enabled"),+ )+ ],+ ),+ )+if context.get("notebook"):log_activity(organization_id=None,@@ -482,6 +504,18 @@ class SharingConfigurationViewSet(TeamAndOrgViewSetMixin, mixins.ListModelMixin,),)+ if context.get("dashboard"):+ log_activity(+ organization_id=None,+ team_id=self.team_id,+ user=cast(User, self.request.user),+ was_impersonated=is_impersonated_session(self.request),+ item_id=new_instance.dashboard.pk,+ scope="Dashboard",+ activity="access token refreshed",+ detail=Detail(name=new_instance.dashboard.name),+ )+if context.get("notebook"):log_activity(organization_id=None,diff --git a/posthog/api/test/test_sharing.py b/posthog/api/test/test_sharing.pyindex b5d88f64f50f..84534829851b 100644--- a/posthog/api/test/test_sharing.py+++ b/posthog/api/test/test_sharing.py@@ -186,6 +186,19 @@ class TestSharing(APIBaseTest):assert response.json()["is_shared"]assert ActivityLog.objects.filter(scope="SharingConfiguration").count() == 0+ self.client.patch(+ f"/api/projects/{self.team.id}/dashboards/{self.dashboard.id}/sharing",+ {"enabled": False},+ )++ dashboard_sharing_logs = ActivityLog.objects.filter(+ scope="Dashboard", activity__in=["sharing enabled", "sharing disabled"]+ ).order_by("created_at")+ assert [(x.activity, x.user_id) for x in dashboard_sharing_logs] == [+ ("sharing enabled", self.user.id),+ ("sharing disabled", self.user.id),+ ]+@patch("posthog.api.exports.ExportedAssetSerializer._start_export_workflow")def test_can_edit_enabled_state_for_insight(self, patched_exporter_task: Mock):assert ActivityLog.objects.filter(scope="SharingConfiguration").count() == 0@@ -453,6 +466,13 @@ class TestSharing(APIBaseTest):response = self.client.get(f"/api/projects/{self.team.id}/dashboards/{self.dashboard.id}/sharing")assert response.json()["access_token"] == refreshed_data["access_token"]+ # Verify activity log was created+ activity_logs = ActivityLog.objects.filter(scope="Dashboard", activity="access token refreshed")+ assert activity_logs.count() == 1+ first = activity_logs.first()+ assert first is not None+ assert first.item_id == str(self.dashboard.id)+@patch("posthog.api.exports.ExportedAssetSerializer._start_export_workflow")def test_can_refresh_sharing_access_token_for_insight(self, patched_exporter_task: Mock):# First enable sharing