diff --git a/posthog/api/__init__.py b/posthog/api/__init__.py index 786a6f0810e9b..97f79f8545e03 100644 --- a/posthog/api/__init__.py +++ b/posthog/api/__init__.py @@ -369,10 +369,8 @@ def register_grandfathered_environment_nested_viewset( 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.web_experiment import WebExperimentViewSet # noqa: E402 @@ -502,7 +500,7 @@ def register_grandfathered_environment_nested_viewset( 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..c6dbd0a649add 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,19 +25,14 @@ 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): - # TODO: Filtering for status? data = HOG_FUNCTION_TEMPLATES return data diff --git a/posthog/urls.py b/posthog/urls.py index 1790c3f059fa0..feb127cfcaf2e 100644 --- a/posthog/urls.py +++ b/posthog/urls.py @@ -28,6 +28,7 @@ authentication, capture, decide, + hog_function_template, router, sharing, signup, @@ -228,6 +229,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: