Skip to content

Commit

Permalink
Merge branch 'master' into detect-stale-flags
Browse files Browse the repository at this point in the history
  • Loading branch information
havenbarnes authored Dec 3, 2024
2 parents 90c0f19 + d0ca214 commit c89d215
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
14 changes: 14 additions & 0 deletions posthog/api/proxy_record.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import asyncio
import hashlib
import posthoganalytics
from django.conf import settings
from rest_framework import serializers, status
from rest_framework.viewsets import ModelViewSet

from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.constants import GENERAL_PURPOSE_TASK_QUEUE
from posthog.event_usage import groups
from posthog.models import ProxyRecord
from posthog.models.organization import Organization
from posthog.permissions import OrganizationAdminWritePermissions
from posthog.temporal.common.client import sync_connect
from posthog.temporal.proxy_service import CreateManagedProxyInputs, DeleteManagedProxyInputs
Expand Down Expand Up @@ -76,6 +79,17 @@ def create(self, request, *args, **kwargs):
)

serializer = self.get_serializer(record)
organization = Organization.objects.get(id=record.organization_id)
posthoganalytics.capture(
request.user.distinct_id,
"managed reverse proxy created",
properties={
"proxy_record_id": record.id,
"domain": record.domain,
"target_cname": record.target_cname,
},
groups=groups(organization),
)
return Response(serializer.data)

def destroy(self, request, *args, pk=None, **kwargs):
Expand Down
11 changes: 10 additions & 1 deletion posthog/warehouse/api/saved_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ class Meta:

def get_columns(self, view: DataWarehouseSavedQuery) -> list[SerializedField]:
team_id = self.context["team_id"]
context = HogQLContext(team_id=team_id, database=create_hogql_database(team_id=team_id))
database = self.context.get("database", None)
if not database:
database = create_hogql_database(team_id=team_id)

context = HogQLContext(team_id=team_id, database=database)

fields = serialize_fields(view.hogql_definition().fields, context, view.name, table_type="external")
return [
Expand Down Expand Up @@ -170,6 +174,11 @@ class DataWarehouseSavedQueryViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewS
search_fields = ["name"]
ordering = "-created_at"

def get_serializer_context(self) -> dict[str, Any]:
context = super().get_serializer_context()
context["database"] = create_hogql_database(team_id=self.team_id)
return context

def safely_get_queryset(self, queryset):
return queryset.prefetch_related("created_by").exclude(deleted=True).order_by(self.ordering)

Expand Down

0 comments on commit c89d215

Please sign in to comment.