Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [1/2] access control capture (without test) #27031

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion posthog/api/team.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
import posthoganalytics

from datetime import UTC, datetime, timedelta
from functools import cached_property
from typing import Any, Optional, cast
Expand All @@ -14,7 +16,7 @@
from posthog.api.utils import action
from posthog.auth import PersonalAPIKeyAuthentication
from posthog.constants import AvailableFeature
from posthog.event_usage import report_user_action
from posthog.event_usage import report_user_action, groups
from posthog.geoip import get_geoip_properties
from posthog.jwt import PosthogJwtAudience, encode_jwt
from posthog.models import ProductIntent, Team, User
Expand Down Expand Up @@ -373,6 +375,22 @@ def create(self, validated_data: dict[str, Any], **kwargs) -> Team:
def update(self, instance: Team, validated_data: dict[str, Any]) -> Team:
before_update = instance.__dict__.copy()

if "access_control" in validated_data and validated_data["access_control"] != instance.access_control:
user = cast(User, self.context["request"].user)
posthoganalytics.capture(
str(user.distinct_id),
"project access control toggled",
properties={
"enabled": validated_data["access_control"],
"project_id": str(instance.id),
"project_name": instance.name,
"organization_id": str(instance.organization_id),
"organization_name": instance.organization.name,
"user_role": user.organization_memberships.get(organization=instance.organization).level,
},
groups=groups(instance.organization),
)

if "survey_config" in validated_data:
if instance.survey_config is not None and validated_data.get("survey_config") is not None:
validated_data["survey_config"] = {
Expand Down
Loading