From 8d7d21ccb7be11da4d5c820aee5db38076e706ef Mon Sep 17 00:00:00 2001 From: Ben White Date: Thu, 5 Sep 2024 10:37:42 +0200 Subject: [PATCH 1/2] Setup public templates --- posthog/api/__init__.py | 4 +--- posthog/api/hog_function_template.py | 15 ++++----------- posthog/urls.py | 5 +++++ 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/posthog/api/__init__.py b/posthog/api/__init__.py index c6fd6851da9c7..9037698ea6dac 100644 --- a/posthog/api/__init__.py +++ b/posthog/api/__init__.py @@ -326,10 +326,8 @@ def api_not_found(request): router.register(r"async_migrations", async_migration.AsyncMigrationsViewset, "async_migrations") router.register(r"instance_settings", instance_settings.InstanceSettingsViewset, "instance_settings") router.register(r"kafka_inspector", kafka_inspector.KafkaInspectorViewSet, "kafka_inspector") - router.register("debug_ch_queries/", debug_ch_queries.DebugCHQueries, "debug_ch_queries") - from posthog.api.action import ActionViewSet # noqa: E402 from posthog.api.cohort import CohortViewSet, LegacyCohortViewSet # noqa: E402 from posthog.api.element import ElementViewSet, LegacyElementViewSet # noqa: E402 @@ -449,7 +447,7 @@ def api_not_found(request): projects_router.register( r"hog_function_templates", - hog_function_template.HogFunctionTemplateViewSet, + hog_function_template.PublicHogFunctionTemplateViewSet, "project_hog_function_templates", ["project_id"], ) diff --git a/posthog/api/hog_function_template.py b/posthog/api/hog_function_template.py index c2becf5ab4afe..29f85331c5078 100644 --- a/posthog/api/hog_function_template.py +++ b/posthog/api/hog_function_template.py @@ -1,15 +1,12 @@ import structlog from django_filters.rest_framework import DjangoFilterBackend -from rest_framework import viewsets +from rest_framework import viewsets, permissions from rest_framework.request import Request from rest_framework.response import Response from rest_framework.exceptions import NotFound -from posthog.api.routing import TeamAndOrgViewSetMixin from posthog.cdp.templates import HOG_FUNCTION_TEMPLATES from posthog.cdp.templates.hog_function_template import HogFunctionTemplate, HogFunctionSubTemplate -from posthog.models.hog_functions.hog_function import HogFunction -from posthog.permissions import PostHogFeatureFlagPermission from rest_framework_dataclasses.serializers import DataclassSerializer @@ -28,15 +25,11 @@ class Meta: dataclass = HogFunctionTemplate -class HogFunctionTemplateViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet): - scope_object = "INTERNAL" # Keep internal until we are happy to release this GA - queryset = HogFunction.objects.none() +# NOTE: There is nothing currently private about these values +class PublicHogFunctionTemplateViewSet(viewsets.GenericViewSet): filter_backends = [DjangoFilterBackend] filterset_fields = ["id", "team", "created_by", "enabled"] - - permission_classes = [PostHogFeatureFlagPermission] - posthog_feature_flag = {"hog-functions": ["create", "partial_update", "update"]} - + permission_classes = [permissions.AllowAny] serializer_class = HogFunctionTemplateSerializer def _get_templates(self): diff --git a/posthog/urls.py b/posthog/urls.py index c34956e8131b3..6794a4faecac9 100644 --- a/posthog/urls.py +++ b/posthog/urls.py @@ -28,6 +28,7 @@ authentication, capture, decide, + hog_function_template, organizations_router, project_dashboards_router, project_feature_flags_router, @@ -236,6 +237,10 @@ def opt_slash_path(route: str, view: Callable, name: Optional[str] = None) -> UR path("year_in_posthog/2022//", year_in_posthog.render_2022), path("year_in_posthog/2023/", year_in_posthog.render_2023), path("year_in_posthog/2023//", year_in_posthog.render_2023), + opt_slash_path( + "api/public_hog_function_templates", + hog_function_template.PublicHogFunctionTemplateViewSet.as_view({"get": "list"}), + ), ] if settings.DEBUG: From 46091635409ccc443582ed85e02fcfb07ab363e3 Mon Sep 17 00:00:00 2001 From: Ben White Date: Thu, 5 Sep 2024 11:05:43 +0200 Subject: [PATCH 2/2] Fixes --- posthog/api/hog_function_template.py | 1 - 1 file changed, 1 deletion(-) diff --git a/posthog/api/hog_function_template.py b/posthog/api/hog_function_template.py index 29f85331c5078..c6dbd0a649add 100644 --- a/posthog/api/hog_function_template.py +++ b/posthog/api/hog_function_template.py @@ -33,7 +33,6 @@ class PublicHogFunctionTemplateViewSet(viewsets.GenericViewSet): serializer_class = HogFunctionTemplateSerializer def _get_templates(self): - # TODO: Filtering for status? data = HOG_FUNCTION_TEMPLATES return data