Skip to content
Closed
Show file tree
Hide file tree
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
38 changes: 7 additions & 31 deletions api/api/urls/v1.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.conf import settings
from django.urls import include, path, re_path
from drf_yasg import openapi # type: ignore[import-untyped]
from drf_yasg.views import get_schema_view # type: ignore[import-untyped]
from rest_framework import authentication, permissions, routers
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView
from rest_framework import routers

from app_analytics.views import SDKAnalyticsFlags, SelfHostedTelemetryAPIView
from environments.identities.traits.views import SDKTraits
Expand All @@ -13,25 +12,6 @@
from integrations.github.views import github_webhook
from organisations.views import chargebee_webhook

schema_view_permission_class = ( # pragma: no cover
permissions.IsAuthenticated
if settings.REQUIRE_AUTHENTICATION_FOR_API_DOCS
else permissions.AllowAny
)

schema_view = get_schema_view(
openapi.Info(
title="Flagsmith API",
default_version="v1",
description="",
license=openapi.License(name="BSD License"),
contact=openapi.Contact(email="[email protected]"),
),
public=True,
permission_classes=[schema_view_permission_class],
authentication_classes=[authentication.BasicAuthentication],
)

traits_router = routers.DefaultRouter()
traits_router.register(r"", SDKTraits, basename="sdk-traits")

Expand Down Expand Up @@ -81,15 +61,11 @@
),
re_path("", include("features.versioning.urls", namespace="versioning")),
# API documentation
re_path(
r"^swagger(?P<format>\.json|\.yaml)$",
schema_view.without_ui(cache_timeout=0),
name="schema-json",
),
re_path(
r"^docs/$",
schema_view.with_ui("swagger", cache_timeout=0),
name="schema-swagger-ui",
path("schema/", SpectacularAPIView.as_view(), name="schema"),
path(
"docs/",
SpectacularSwaggerView.as_view(url_name="api-v1:schema"),
name="swagger-ui",
),
# Test webhook url
re_path(r"^webhooks/", include("webhooks.urls", namespace="webhooks")),
Expand Down
17 changes: 16 additions & 1 deletion api/app/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
"app",
"e2etests",
"simple_history",
"drf_yasg",
"audit",
"permissions",
"projects.code_references",
Expand Down Expand Up @@ -163,6 +162,7 @@
"softdelete",
"metadata",
"app_analytics",
"drf_spectacular",
]

SILENCED_SYSTEM_CHECKS = ["axes.W002"]
Expand Down Expand Up @@ -326,6 +326,7 @@
"util.renderers.PydanticJSONRenderer",
"rest_framework.renderers.BrowsableAPIRenderer",
],
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
}
MIDDLEWARE = [
"common.core.middleware.APIResponseVersionHeaderMiddleware",
Expand Down Expand Up @@ -1465,3 +1466,17 @@
REQUIRE_AUTHENTICATION_FOR_API_DOCS = env.bool(
"REQUIRE_AUTHENTICATION_FOR_API_DOCS", default=False
)


SPECTACULAR_SETTINGS = {
"TITLE": "Flagsmith API",
"VERSION": "v1",
}

if REQUIRE_AUTHENTICATION_FOR_API_DOCS:
SPECTACULAR_SETTINGS["SERVE_PERMISSIONS"] = (
"rest_framework.permissions.IsAuthenticated"
)
SPECTACULAR_SETTINGS["SERVE_AUTHENTICATION"] = (
"rest_framework.authentication.SessionAuthentication"
)
2 changes: 1 addition & 1 deletion api/environments/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def get_subscription(self) -> Subscription | None:
).get(id=project_id)

return getattr(project.organisation, "subscription", None)
elif view.action in ("update", "partial_update"):
elif self.instance and view.action in ("update", "partial_update"):
return getattr(self.instance.project.organisation, "subscription", None) # type: ignore[union-attr]

return None
Expand Down
Loading
Loading